You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the MultiSelect component with options that have identical labels, such as "New York", the component uses the label as the key. This leads to warnings and unexpected behavior.
Implement the MultiSelect component with this list.
Select the first "New York" option.
Notice the warning in the console:
Warning: Encountered two children with the same key, New York. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Attempt to delete the duplicate "New York" option.
Expected Behavior
The component should handle duplicate labels without warnings or errors, allowing users to select and delete items correctly.
Actual Behavior
A warning appears in the console about duplicate keys.
When attempting to delete the duplicate, new values are incorrectly added to the list.
Possible Solution
Allow the use of a unique key other than the label for the MultiSelect component. This could be achieved by using the value field or an additional unique identifier for each option.
Additional Context
This issue can occur in scenarios where items have the same name, such as a list of people with identical first and last names.
melloware
added
Type: Bug
Issue contains a defect related to a specific component.
and removed
Status: Needs Triage
Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
labels
May 22, 2024
Describe the bug
When using the MultiSelect component with options that have identical labels, such as "New York", the component uses the label as the key. This leads to warnings and unexpected behavior.
Steps to Reproduce
Implement the MultiSelect component with this list.
Select the first "New York" option.
Notice the warning in the console:
Warning: Encountered two children with the same key, New York. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Expected Behavior
The component should handle duplicate labels without warnings or errors, allowing users to select and delete items correctly.
Actual Behavior
A warning appears in the console about duplicate keys.
When attempting to delete the duplicate, new values are incorrectly added to the list.
Possible Solution
Allow the use of a unique key other than the label for the MultiSelect component. This could be achieved by using the
value
field or an additional unique identifier for each option.Additional Context
This issue can occur in scenarios where items have the same name, such as a list of people with identical first and last names.
Reproducer
https://stackblitz.com/edit/vitejs-vite-1u4ahw?file=src%2FApp.tsx
PrimeReact version
10.6.5
React version
18.x
Language
TypeScript
Build / Runtime
Vite
The text was updated successfully, but these errors were encountered: