-
Notifications
You must be signed in to change notification settings - Fork 83
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
Add select options on the fly keeping/updating id's #6378
Comments
FE-6250 |
@ritxi, can you give some context about why these options need to be dynamically populated and can't be shown on initial render? |
Hi @ritxi 👋🏼 Would you be able to provide some more context regarding your use case? |
Message sent in Slack to @ritxi requesting more context about their requirements. |
Hi @ritxi there is a simple workaround until we fix the ID persistence issue
Adding the IDs to each option during your render will ensure they always have the correct ID. I've added a ticket below for us to make this work without any further code. Also as a side note, would you not just want the All option to always be there? |
Thanks @nicktitchmarsh, but showing all option after some option is selected was part of the definition. |
… changes Currently Select assigns a random guid as ID to each of its option children if no ids are provided explicitly, and regenerates this list of ids whenever the number of children changes. This results in unexpected behaviour when a new option is dynamically added to the start of the list on selection, as then the ids are regenerated and a critical axe error results from the aria-activedescendant property no longer referencing a valid child ID. To fix this, guids are now generated in Option itself (rather than SelectList as before) when the prop is not provided, and it is up to consumer to set keys on the list of option children to ensure individual child components maintain their identity correctly across renders even as children are added or removed. fix #6378
… changes Currently Select assigns a random guid as ID to each of its option children if no ids are provided explicitly, and regenerates this list of ids whenever the number of children changes. This results in unexpected behaviour when a new option is dynamically added to the start of the list on selection, as then the ids are regenerated and a critical axe error results from the aria-activedescendant property no longer referencing a valid child ID. To fix this, guids are now generated in Option itself (rather than SelectList as before) when the prop is not provided, and it is up to consumer to set keys on the list of option children to ensure individual child components maintain their identity correctly across renders even as children are added or removed. fix #6378
… changes Currently Select assigns a random guid as ID to each of its option children if no ids are provided explicitly, and regenerates this list of ids whenever the number of children changes. This results in unexpected behaviour when a new option is dynamically added to the start of the list on selection, as then the ids are regenerated and a critical axe error results from the aria-activedescendant property no longer referencing a valid child ID. To fix this, guids are now generated in Option itself (rather than SelectList as before) when the prop is not provided, and it is up to consumer to set keys on the list of option children to ensure individual child components maintain their identity correctly across renders even as children are added or removed. fix #6378
### [125.11.1](v125.11.0...v125.11.1) (2024-02-07) ### Bug Fixes * **select:** maintain option ids according to key when children count changes ([144583b](144583b)), closes [#6378](#6378)
🎉 This issue has been resolved in version 125.11.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Current behaviour
When an option is selected, if the list options changes, that refreshes the internally used list items changing their ids.
Expected behaviour
When adding options to a select I expect to keep previous options with same internal id or updating to the new id
CodeSandbox or Storybook URL
https://codesandbox.io/s/select-with-on-the-fly-all-option-rw4vl9?file=/src/index.js
JIRA Ticket (Sage Only)
SKPU-10261
Suggested Solution
When a select list of options change if the selected value is still on the list that should be updating the internal id reference to keep accessibility compliance.
Carbon Version
121.0.2
Design Tokens Version
4.25.0
What browsers are you seeing the problem on?
Chrome
What Operating System are you seeing the problem on?
MacOS
Anything else we should know?
No response
Confidentiality
The text was updated successfully, but these errors were encountered: