Sajari UI

Combobox

Combobox is a component that allows for interactive and flexible ways to capture user input.

Import

Usage

Here's a basic usage of the Combobox.

Editable Example

Placeholder

You can pass in a fixed string or a function that receives the selected items and return a string, if no placeholder prop is passed, it will default to "Select..." when there are no values and show the name of the value if it's in single mode or "{num} items selected" if in multiple mode.

Editable Example

Clear value

By default, the combobox will clear the search value once it no longer receives any focus, to disable this, simple pass clearValueOnBlur={false} prop.

Editable Example

Sizes

Editable Example

Single mode

Editable Example

Tag mode

Editable Example

Grouping options

Editable Example

Loading state

Editable Example

Disable clear

Editable Example

Keep the dropdown after selecting

Editable Example

Disabled

Editable Example

Readonly

Editable Example

With an associated label

Editable Example

Props

The Combobox component composes PseudoBox so you can pass all PseudoBox props, and React.InputHTMLAttributes.

NameTypeDefaultDescription
aria-labelstringAccessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers.
aria-describedbystringAccessibility label to use, in scenarios where the input has no visible label. A11y: It's usefult for screen readers.
labelIdstringid of the label element labelling this input, in scenarios where the input has a visible label. A11y: It's usefult for screen readers.
disabledbooleanfalseIf true, the input will be disabled. This sets aria-disabled=true and you can style this state by passing _disabled prop.
invalidbooleanfalseIf true, the input will indicate an error. This sets aria-invalid=true and you can style this state by passing _invalid prop.
requiredbooleanfalseIf true, the input element will be required.
readOnlybooleanfalseIf true, prevents the value of the input from being edited.
size"sm" | "md""md"
mode"single" | "multiple" | "tag""multiple"To switch between single or multiple selected items.
itemsItem[] | string[]List of option items.
selectedItemsItem[] | string[][]List of selected option items.
onChange(selectedItems: Item[] | string[]) => void
placementPopperJS.Placement"bottom"The placement of the suggestion dropdown.
placeholderstring | (selectedItems: Item[] | string[]) => stringTo set the placeholder or displayed value in multiple mode.
loadingbooleanfalseIf true, a spinner icon will show to display a loading state.
allowClearbooleantrueIf true, a close icon will show to clear all the selected items.
closeOnSelectbooleanBy default, the dropdown will be closed after selecting in single mode and vice versa in other modes.
validateSelectedItemsbooleantrueIf true, selected items will be filtered to match the items prop.