-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(combobox): controlled combobox onchange #17858
fix(combobox): controlled combobox onchange #17858
Conversation
* updated useEffect hook for controlled combobox so onChange doesn't fire twice when selection is made and selectedItem prop changes * updated onSelectedItemChange to not fire onChange if selectedItem is unchanged * unit tests
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #17858 +/- ##
=======================================
Coverage 81.59% 81.60%
=======================================
Files 406 406
Lines 14047 14049 +2
Branches 4355 4377 +22
=======================================
+ Hits 11462 11464 +2
+ Misses 2422 2421 -1
- Partials 163 164 +1 ☔ View full report in Codecov by Sentry. |
✅ Deploy Preview for v11-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
This looks awesome, thanks for the super fast turnaround! Tests look great too. Just one minor piece of feedback from me
* updated comparison of new selectedItem to use react-fast-compare isEqual
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.
Awesome! Thanks for having this fix up! 🚀
57fce93
Hey there! v11.70.0 was just released that references this issue/PR. |
Closes #17847
In cases where a selection is made to a fully controlled combobox component, and the selectedItem prop updates on this selection, such as in cases where this state is managed externally (probably just about all cases where
selectedItem
is being used), the onChange was firing twice. This PR adds a check to see if the selectedItem prop was changed externally before calling the onChange in the useEffect pertaining to controlled comboboxes. It also ensures that onChange is not fired for controlled comboboxes when a selection is made that is the same as the current selection.Testing / Reviewing