Controls: Fix select controls for optional Flow unions and nested options#34895
Controls: Fix select controls for optional Flow unions and nested options#34895Pulkit7070 wants to merge 1 commit into
Conversation
…d options
Two bugs caused the select control to break:
1. Flow optional union types (?'sm' | 'md' | 'lg') include void and null
elements. The isLiteral check failed causing fallback to object control.
Fix: filter void/null before the every(isLiteral) check.
2. Users commonly write { control: { type: 'select', options: [...] } }
instead of the documented top-level options pattern. The nested options
were silently ignored. Fix: hoist options from inside control to the
top level in normalizeInputType when not already present.
Fixes storybookjs#12641
|
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 (4)
📝 WalkthroughWalkthroughThis PR updates argTypes conversion and normalization in two complementary ways. Flow union conversion now filters nullable markers before determining enum eligibility, improving union-to-enum detection. Input type normalization hoists ChangesArgTypes conversion and normalization
Possibly related PRs
🎯 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 |
|
Thanks for your contribution. The PR addresses a fixed bug, therefore it will be closed. I have verified that the bugfix works according to the bug report author's instructions, and it does. Please reopen an issue with a minimal reproduction example before opening a new PR for this bug. |
What
Fixes two separate bugs that caused select controls to silently break (issue #12641):
Bug 1 — Flow optional union types fall back to
objectcontrolRoot cause: Flow represents optional types (
?'sm' | 'md' | 'lg') as a union containingvoidandnullelements. Theevery(isLiteral)check failed on these non-literal elements, so the converter fell back to a genericunion/objectcontrol instead of aselect.Fix: Filter out
voidandnullelements before theisLiteralcheck inconvert/flow/convert.ts, matching the approach already applied to the TypeScript converter.File:
code/core/src/docs-tools/argTypes/convert/flow/convert.tsBug 2 — Options nested inside
controlobject are silently ignoredRoot cause: Users commonly write:
instead of the documented top-level form:
The nested
optionswere passed through as part of thecontrolobject but never surfaced to the controls addon, resulting in an empty select dropdown.Fix: In
normalizeInputType, whencontrolis an object with anoptionsproperty and no top-leveloptionsis present, hoistoptionsto the top level and strip it from thecontrolobject.File:
code/core/src/preview-api/modules/store/csf/normalizeInputTypes.tsTests
convert/flow/convert.test.tswith 4 cases covering the void/null filteringnormalizeInputTypes.test.tscovering options hoisting and precedenceManual testing
Create a story with a Flow-typed optional union prop:
?('sm' | 'md' | 'lg')objectinputselectdropdown with sm/md/lg optionsDefine argTypes with options nested inside control:
Checklist
optionsis absent)Fixes #12641