-
-
Notifications
You must be signed in to change notification settings - Fork 369
Closed
Labels
component: selectChanges related to the select component.Changes related to the select component.type: bugIt doesn't behave as expected.It doesn't behave as expected.
Description
Bug report
Currently, Select.Value does not return correct labels when used with <Select.Root items={[]} />:
const items = [
{
value: "apple",
label: "Apple",
},
{
value: "banana",
label: "Banana",
},
{
value: "cherry",
label: "Cherry",
},
{
value: "orange",
label: "Orange",
},
];
<Select.Root items={items} multiple>
<Select.Trigger>
<Select.Value />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup>
<Select.List>
{items.map((item) => (
<Select.Item value={item.value}>{item.label}</Select.Item>
)}
</Select.List>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>Select.Value would show "apple, banana, cherry, orange" instead of "Apple, Banana, Cherry, Orange"
However, this works:
const items = [
{
value: "apple",
label: "Apple",
},
{
value: "banana",
label: "Banana",
},
{
value: "cherry",
label: "Cherry",
},
{
value: "orange",
label: "Orange",
},
];
<Select.Root multiple>
<Select.Trigger>
<Select.Value />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup>
<Select.List>
{items.map((item) => (
<Select.Item value={item}>{item.label}</Select.Item>
)}
</Select.List>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>Select.Value correctly shows "Apple, Banana, Cherry, Orange"
Current behavior
As above
Expected behavior
Select.Value should consistently show correct label and respect items.
Reproducible example
N/A
Base UI version
1.0.0-beta.5 (#3210)
Which browser are you using?
Edge
Which OS are you using?
MacOS
Which assistive tech are you using (if applicable)?
N/A
Additional context
The function resolveMultipleLabels would need to accept items as one of the arguments to make this work:
base-ui/packages/react/src/utils/resolveValueLabel.tsx
Lines 114 to 122 in 49cfd5e
| export function resolveMultipleLabels( | |
| values: any[] | undefined, | |
| itemToStringLabel?: (item: any) => string, | |
| ): string { | |
| if (!Array.isArray(values) || values.length === 0) { | |
| return ''; | |
| } | |
| return values.map((v) => stringifyAsLabel(v, itemToStringLabel)).join(', '); | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
component: selectChanges related to the select component.Changes related to the select component.type: bugIt doesn't behave as expected.It doesn't behave as expected.