Installation
Add Component
Copy the code snippet below into you components folder.
Integrate Recipe
Integrate this recipe in to your Panda config.
Usage
To setup combobox, you might need to import the following hooks:
- useListCollection: Used to manage the list of items in the combobox, providing helpful methods for filtering and mutating the list.
- useFilter: Used to provide the filtering logic for the combobox based on- Intl.CollatorAPIs.
Examples
Sizes
Use the size prop to adjust the size of the combobox.
Variants
Use the variant prop to adjust the visual style of the combobox.
Props
Root
| Prop | Default | Type | 
|---|---|---|
| collection* | ListCollection<T>The collection of items | |
| variant | 'outline' | 'outline' | 'surface' | 'subtle' | 
| size | 'md' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 
| composite | true | booleanWhether the combobox is a composed with other composite widgets like tabs | 
| defaultInputValue | \\ | stringThe initial value of the combobox's input when rendered. Use when you don't need to control the value of the combobox's input. | 
| defaultValue | [] | string[]The initial value of the combobox's selected items when rendered. Use when you don't need to control the value of the combobox's selected items. | 
| inputBehavior | \none\ | 'none' | 'autohighlight' | 'autocomplete'Defines the auto-completion behavior of the combobox. - `autohighlight`: The first focused item is highlighted as the user types - `autocomplete`: Navigating the listbox with the arrow keys selects the item and the input is updated | 
| lazyMount | false | booleanWhether to enable lazy mounting | 
| loopFocus | true | booleanWhether to loop the keyboard navigation through the items | 
| openOnChange | true | boolean | ((details: InputValueChangeDetails) => boolean)Whether to show the combobox when the input value changes | 
| openOnClick | false | booleanWhether to open the combobox popup on initial click on the input | 
| openOnKeyPress | true | booleanWhether to open the combobox on arrow key press | 
| positioning | { placement: \bottom-start\ } | PositioningOptionsThe positioning options to dynamically position the menu | 
| selectionBehavior | \replace\ | 'replace' | 'clear' | 'preserve'The behavior of the combobox input when an item is selected - `replace`: The selected item string is set as the input value - `clear`: The input value is cleared - `preserve`: The input value is preserved | 
| skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. | 
| unmountOnExit | false | booleanWhether to unmount on exit. | 
| allowCustomValue | booleanWhether to allow typing custom values in the input | |
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. | |
| autoFocus | booleanWhether to autofocus the input on mount | |
| closeOnSelect | booleanWhether to close the combobox when an item is selected. | |
| defaultHighlightedValue | stringThe initial highlighted value of the combobox when rendered. Use when you don't need to control the highlighted value of the combobox. | |
| defaultOpen | booleanThe initial open state of the combobox when rendered. Use when you don't need to control the open state of the combobox. | |
| disabled | booleanWhether the combobox is disabled | |
| disableLayer | booleanWhether to disable registering this a dismissable layer | |
| form | stringThe associate form of the combobox. | |
| highlightedValue | stringThe controlled highlighted value of the combobox | |
| id | stringThe unique identifier of the machine. | |
| ids | Partial<{
  root: string
  label: string
  control: string
  input: string
  content: string
  trigger: string
  clearTrigger: string
  item: (id: string, index?: number | undefined) => string
  positioner: string
  itemGroup: (id: string | number) => string
  itemGroupLabel: (id: string | number) => string
}>The ids of the elements in the combobox. Useful for composition. | |
| immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
| inputValue | stringThe controlled value of the combobox's input | |
| invalid | booleanWhether the combobox is invalid | |
| multiple | booleanWhether to allow multiple selection. **Good to know:** When `multiple` is `true`, the `selectionBehavior` is automatically set to `clear`. It is recommended to render the selected items in a separate container. | |
| name | stringThe `name` attribute of the combobox's input. Useful for form submission | |
| navigate | (details: NavigateDetails) => voidFunction to navigate to the selected item | |
| onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
| onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
| onHighlightChange | (details: HighlightChangeDetails<T>) => voidFunction called when an item is highlighted using the pointer or keyboard navigation. | |
| onInputValueChange | (details: InputValueChangeDetails) => voidFunction called when the input's value changes | |
| onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
| onOpenChange | (details: OpenChangeDetails) => voidFunction called when the popup is opened | |
| onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
| onSelect | (details: SelectionDetails) => voidFunction called when an item is selected | |
| onValueChange | (details: ValueChangeDetails<T>) => voidFunction called when a new item is selected | |
| open | booleanThe controlled open state of the combobox | |
| placeholder | stringThe placeholder text of the combobox's input | |
| present | booleanWhether the node is present (controlled by the user) | |
| readOnly | booleanWhether the combobox is readonly. This puts the combobox in a "non-editable" mode but the user can still interact with it | |
| required | booleanWhether the combobox is required | |
| scrollToIndexFn | (details: ScrollToIndexDetails) => voidFunction to scroll to a specific index | |
| translations | IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states | |
| value | string[]The controlled value of the combobox's selected items | 
Item
| Prop | Default | Type | 
|---|---|---|
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. | |
| item | anyThe item to render | |
| persistFocus | booleanWhether hovering outside should clear the highlighted state | 
Trigger
| Prop | Default | Type | 
|---|---|---|
| asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. | |
| focusable | booleanWhether the trigger is focusable |