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
Render functions still receive full objects, while selection state and callbacks use the primitive key. When rendering items from `<Combobox.List>` or `<Combobox.Collection>`, omit `<Combobox.Item value>`. For manually rendered virtualized items, provide `index`.
87
87
88
-
Labels are inferred automatically for primitive keys. If `itemToValue` returns an object, provide `itemToStringLabel` to display its label in the input.
88
+
When `itemToValue` returns a primitive, a source item's text or numeric `label` is used automatically. Otherwise, provide `itemToStringLabel`, which receives the mapped value. If `itemToValue` returns an object, also keep its references stable or provide `isItemEqualToValue` when equivalent objects may be recreated.
89
89
90
90
## Examples
91
91
@@ -97,8 +97,8 @@ The following example shows a typed wrapper around the Combobox component with c
Copy file name to clipboardExpand all lines: docs/src/app/(docs)/react/components/combobox/types.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ Doesn't render its own HTML element.
35
35
| isItemEqualToValue |`((itemValue: Value, value: Value) => boolean)`| - | Custom comparison logic used to determine if a combobox item value matches the current selected value. Useful when item values are objects without matching referentially.
Defaults to `Object.is` comparison. |
36
36
| itemToStringLabel |`((itemValue: Value) => string)`| - | When the item values are objects (`<Combobox.Item value={object}>`), this function converts the object value to a string representation for display in the input.
If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop. |
37
37
| itemToStringValue |`((itemValue: Value) => string)`| - | When the item values are objects (`<Combobox.Item value={object}>`), this function converts the object value to a string representation for form submission.
If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop. |
38
-
| itemToValue |`((item: Item) => Value)`| - | Maps an entry from the `items` array to the value emitted for its item. Use it to select a
projection of the source item (for example `item.value`) while keeping filtering, grouping,
and rendering on the source item. When omitted, the source item is the value.|
38
+
| itemToValue |`((item: Item) => Value)`| - | Maps an entry from the `items` array to the value emitted for its item. Use it to select a
field from the source item (for example `item.value`) while keeping filtering, grouping,
and rendering on the source item. When omitted, the source item is the value.
The returned value must not be `undefined`. Use `null` for an empty item value.|
39
39
| items |`Item[] \| Group<Item>[]`| - | The items to be displayed in the list.
Can be either a flat array of items or an array of groups with items. |
40
40
| limit |`number`|`-1`| The maximum number of items to display in the list. |
41
41
| locale |`Intl.LocalesArgument`| - | The locale to use for string comparison.
Defaults to the user's runtime locale. |
| value |`any`|`null`| A unique value that identifies this item.|
649
-
| onClick |`((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)`| - | An optional click handler for the item when selected.
It fires when clicking the item with the pointer, as well as when pressing `Enter` with the keyboard if the item is highlighted when the `Input` or `List` element has focus. |
650
-
| index |`number`| - | The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM. |
651
-
| nativeButton |`boolean`|`false`| Whether the component renders a native `<button>` element when replacing it
via the `render` prop.
Set to `true` if the rendered element is a native button. |
652
-
| disabled |`boolean`|`false`| Whether the component should ignore user interaction. |
653
-
| children |`React.ReactNode`| - | - |
654
-
| className |`string \| ((state: Combobox.Item.State) => string \| undefined)`| - | CSS class applied to the element, or a function that
returns a class based on the component's state. |
655
-
| style |`React.CSSProperties \| ((state: Combobox.Item.State) => React.CSSProperties \| undefined)`| - | Style applied to the element, or a function that
returns a style object based on the component's state. |
656
-
| render |`ReactElement \| ((props: HTMLProps, state: Combobox.Item.State) => ReactElement)`| - | Allows you to replace the component's HTML element
with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| value |`any`|`null`| A unique value that identifies this item.
When the root derives a value with `itemToValue`, that derived value takes precedence. Omit
this prop for items rendered from a collection, or pass the mapped value.|
649
+
| onClick |`((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)`| - | An optional click handler for the item when selected.
It fires when clicking the item with the pointer, as well as when pressing `Enter` with the keyboard if the item is highlighted when the `Input` or `List` element has focus. |
650
+
| index |`number`| - | The index of the item in the list. Required to derive the mapped value for manually
rendered virtualized items when `itemToValue` is set. Otherwise, providing it improves
performance by avoiding the need to calculate the index automatically from the DOM.|
651
+
| nativeButton |`boolean`|`false`| Whether the component renders a native `<button>` element when replacing it
via the `render` prop.
Set to `true` if the rendered element is a native button. |
652
+
| disabled |`boolean`|`false`| Whether the component should ignore user interaction. |
653
+
| children |`React.ReactNode`| - | - |
654
+
| className |`string \| ((state: Combobox.Item.State) => string \| undefined)`| - | CSS class applied to the element, or a function that
returns a class based on the component's state. |
655
+
| style |`React.CSSProperties \| ((state: Combobox.Item.State) => React.CSSProperties \| undefined)`| - | Style applied to the element, or a function that
returns a style object based on the component's state. |
656
+
| render |`ReactElement \| ((props: HTMLProps, state: Combobox.Item.State) => ReactElement)`| - | Allows you to replace the component's HTML element
with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
0 commit comments