Core: Infer select/radio controls for TypeScript literal union types#34892
Core: Infer select/radio controls for TypeScript literal union types#34892wbobbynmworley wants to merge 1 commit into
Conversation
When a component prop is typed as a union of string literals (e.g. size: 'S' | 'M' | 'L'), Storybook's control inference now correctly generates a radio (<=5 options) or select (>5) control. Previously, only the 'enum' type name was handled, but TypeScript literal unions appear as 'union' with 'literal' children in docgen output. Fixes storybookjs#33779
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR extends Storybook's argument control inference to handle union types containing string literals, inferring ChangesUnion Type Control Inference
🎯 2 (Simple) | ⏱️ ~12 minutes Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi maintainers, the Danger JS check is failing because this PR is missing required labels. Could someone please add: |
|
Superseded by #34887 |
Problem
Fixes #33779
When a component prop is typed as a union of string literals (e.g.
size: 'S' | 'M' | 'L'), Storybook 10 no longer automatically generates select/radio controls for those props.Root Cause
inferControls()only handledtype.name === 'enum'for generating select/radio controls. However, TypeScript literal union types appear in docgen output as:Since 'union' wasn't handled, it fell through to the
defaultcase returning an 'object' control.Fix
Added a
case 'union'ininferControl()that:name === 'literal' && typeof value === 'string')string | numberunionsManual testing
sizeprop should show as radio buttons with 'S', 'M', 'L' optionsTest Plan
Added 4 new tests in
inferControls.test.ts:All 6 tests pass.