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(multiselect): add useEffect to selection hook to update externally #16139

Merged

Conversation

ychavoya
Copy link
Contributor

@ychavoya ychavoya commented Apr 5, 2024

Closes #16124

Update MultiSelect's useSelection hook to include a useEffect that updates the selected items when they are updated externally (controlled component), since the recently added useState is only executed on initial render.

Changelog

Changed

  • Ability to update a controlled MultiSelect's selected items externally

Testing / Reviewing

Added a Storybook to test controlled MultiSelect components. The MultiSelect in this storybook should update its selected values when the included buttons are pressed, and a storybook action should be triggered.

Also added a unit test that tests this behavior.

@ychavoya ychavoya requested a review from a team as a code owner April 5, 2024 19:06
Copy link
Contributor

github-actions bot commented Apr 5, 2024

DCO Assistant Lite bot All contributors have signed the DCO.

@ychavoya
Copy link
Contributor Author

ychavoya commented Apr 5, 2024

I have read the DCO document and I hereby sign the DCO.

@ychavoya
Copy link
Contributor Author

ychavoya commented Apr 5, 2024

recheck

Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit b58bc40
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/6639100d3882e8000818f75d
😎 Deploy Preview https://deploy-preview-16139--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

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 ✅

tw15egan and others added 2 commits April 12, 2024 06:58
the setter function of a useState hook returns undefined, this was mistakenly
used as the value to be set instead of sending the value directly
@ychavoya
Copy link
Contributor Author

Hi, I noticed that an error in a different part of the useSelection hook was conflicting with the changes and therefore was causing a test to run indefinitely. I sent a commit to fix that

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.

Thanks for this!

@tay1orjones
Copy link
Member

@guidari @preetibansalui This is something to look out for in #16147

@tay1orjones tay1orjones enabled auto-merge May 6, 2024 17:18
@tay1orjones tay1orjones added this pull request to the merge queue May 6, 2024
Merged via the queue into carbon-design-system:main with commit 0bc9c78 May 6, 2024
20 checks passed
@ychavoya ychavoya deleted the controllable-multiselect branch May 6, 2024 18:09
@preetibansalui
Copy link
Contributor

preetibansalui commented May 7, 2024

@guidari @preetibansalui This is something to look out for in #16147

Thanks @tay1orjones, We will look into this. I have one doubt. For this PR, I know it is to provide controlled state only, but aren't we giving a wrong example here in storybook by selecting all items (including disabled item).

image

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]: Multiselect is no longer programmatically controllable
4 participants