-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Controls: Allow resetting the Select control #33289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 1179
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 47
🏁 Script executed:
# Let's look at the beginning of the story file to understand the setup head -n 80 code/addons/docs/src/blocks/controls/options/SelectOptions.stories.tsxRepository: storybookjs/storybook
Length of output: 1652
🏁 Script executed:
# Find and examine the OptionsControl component cat code/addons/docs/src/blocks/controls/options/Options.tsxRepository: storybookjs/storybook
Length of output: 1782
🏁 Script executed:
# Find SelectControl implementation cat code/addons/docs/src/blocks/controls/options/Select.tsxRepository: storybookjs/storybook
Length of output: 4658
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 135
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 284
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 92
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 883
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 234
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 98
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 218
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 323
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 126
🏁 Script executed:
# Read the ESLint rule documentation to understand play function context cat code/lib/eslint-plugin/docs/rules/context-in-play-function.mdRepository: storybookjs/storybook
Length of output: 2068
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 156
The play function tests user interactions but has a logical flaw in the controlled component pattern.
The test verifies that
onChangeis called correctly (line 84, 90), but the assumptions about component state updates are incorrect. TheSelectControlcomponent is fully controlled—it receivesvalueas a prop and does not maintain internal state. After callingonChange, theargs.valueis never updated, so the component won't re-render with the new selected value. The assertions on lines 85 and 91 (expect(select).toHaveValue(...)) may pass due to DOM state changes fromuserEvent.selectOptions(), but they don't reflect the actual rendered state of the controlled component. To properly test a controlled component in a story, either:args.valuein the play function after callingonChange, oronChangecallbacks back to args (if Storybook provides such a mechanism).Verify the actual behavior by running this story's play function to confirm whether the select element visually updates or if the test passes due to DOM-level state diverging from the React component's rendered value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way to put it is that the transient states before re-rendering are correct, so there is no flash of incorrect state :p Do you buy that, @ghengeveld? :P
Ultimately the test is testing some irrelevant things that only matter in edge cases, but it is also testing the relevant things so I don't mind leaving it the way it is.