Skip to content
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

Merged
merged 4 commits into from
Nov 5, 2024

Conversation

Neues
Copy link
Contributor

@Neues Neues commented Oct 23, 2024

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.

  • 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

Testing / Reviewing

* 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
@Neues Neues requested a review from a team as a code owner October 23, 2024 17:18
Copy link

netlify bot commented Oct 23, 2024

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit fe4cbc9
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-web-components/deploys/672a242c89595900089a5a52
😎 Deploy Preview https://deploy-preview-17858--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Oct 23, 2024

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit fe4cbc9
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/672a242cf568f40009a0d86b
😎 Deploy Preview https://deploy-preview-17858--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.60%. Comparing base (4ab57c9) to head (fe4cbc9).
Report is 5 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

Copy link

netlify bot commented Oct 23, 2024

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit fe4cbc9
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/672a242ca84e260008f75442
😎 Deploy Preview https://deploy-preview-17858--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@tay1orjones tay1orjones left a 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

packages/react/src/components/ComboBox/ComboBox.tsx Outdated Show resolved Hide resolved
* updated comparison of new selectedItem to use react-fast-compare isEqual
Copy link
Contributor

@guidari guidari left a 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! 🚀

@guidari guidari added this pull request to the merge queue Nov 5, 2024
Merged via the queue into carbon-design-system:main with commit 57fce93 Nov 5, 2024
40 checks passed
@carbon-automation
Copy link
Contributor

Hey there! v11.70.0 was just released that references this issue/PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: onChange fires twice when selecting item on ComboBox
4 participants