Combobox

Comboboxes are a type of select field that allow users to choose from a list of options.

import {
Combobox,
ComboItemGroup,
ComboItemWithIndicator,
ComboItemText
} from '@cerberus/react'

Usage

The Combobox component is an abstraction component that provides a fully functional combobox. It is built on top of the Select component and allows additional functionality such as filtering.

With Start Icon

To add an icon to the start position of the input, use the startIcon prop to pass in your ReactNode.

Grouped Items

To group items, use the ComboItemGroup component (not ComboboxItemGroup).

With Field

Wrap the Combobox component with the Field component to add additional functionality such as error and helper text when using it in a form.

This is saved to your profile

Primitives

You can utilize the primitive components to customize the select.

ComponentDescription
ComboboxRootThe context provider for the combobox family
ComboboxLabelThe label that appears above the combobox input
ComboboxControlThe wrapper to the combobox trigger that opens the dropdown
ComboboxInputThe input field of the combobox
ComboboxTriggerhe trigger that opens the dropdown
ComboboxClearTriggerThe trigger that clears the selected value
ComboboxPositionerThe wrapper that positions the dropdown
ComboboxContentThe content of the dropdown (i.e. the container itself)
ComboboxItemGroupThe group of options in the dropdown
ComboboxItemGroupLabelThe label for the group of options
ComboboxItemThe option in the dropdown
ComboboxItemTextThe text label of the option
ComboboxItemIndicatorThe indicator shown when the option is selected

API

Combobox

The Combobox component is an abstraction of our primitives and accepts the following props:

NameDefaultDescription
size'md'The size of the combobox.
startIconThe icon to display at the start of the input.

The Combobox component also accepts all the props of the ComboboxRoot primitive props

ItemWithIndicator

The ItemWithIndicator component is an abstraction of our primitives and accepts all the props of the ComboboxItem primitive props

ComboItemGroup

The ComboItemGroup component is an abstraction of our primitives and accepts the following props:

NameDefaultDescription
labelThe label of the group.

The ComboItemGroup component is an abstraction of our primitives and accepts all the props of the ComboboxItemGroup primitive props

useStatefulCollection

The useStatefulCollection function is a utility hook that creates a collection of options and filters the list based on the user input.

function useStatefulCollection(
initialItems: SelectCollectionItem[] = [],
): StatefulCollectionReturn

Returns

NameDescription
collectionThe collection of options.
filterCharsThe filter value split into an Array of chars.
handleInputChangeThe function to pass to onInputValueChange.

Parts

The ComboboxParts API is an Object containing the full family of components.

NameDescription
RootThe ComboboxRoot component which is the Provider for the family.
LabelThe ComboboxLabel component which displays the label.
ControlThe ComboboxControl component which is the container for the visual field.
InputThe ComboboxInput component which is the visual field.
TriggerThe ComboboxTrigger component which is the trigger for the dropdown.
ClearTriggerThe ComboboxClearTrigger component which is the trigger to clear the value.
PositionerThe ComboboxPositioner component which is controls the positioning for the dropdown.
ContentThe ComboboxContent component which is the dropdown itself.
ItemGroupThe ComboboxItemGroup component which is the group of options in the dropdown.
ItemGroupLabelThe ComboboxItemGroupLabel component which is the label for the group of options.
ItemThe ComboboxItem component which is the option in the dropdown.
ItemTextThe ComboboxItemText component which is the text label of the option.
ItemIndicatorThe ComboboxItemIndicator component which displays based on the checked state.