Skip to content

Combo box API

Cimpress UI exports three combo box-related components:

  • ComboBox: main component that allows users to select one item from a collapsible list with search functionality.
  • ComboBoxItem: component that renders a single selectable item within a combo box.
  • ComboBoxSection: component that groups related combo box items together under a section title.
import { ComboBox, ComboBoxItem, ComboBoxSection } from '@cimpress-ui/react';

This component can be used in a controlled or uncontrolled way.

In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.

In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.

This component exposes an imperative API through the apiRef prop. This API allows triggering behaviors that can’t be expressed by props.

Combo box follows the ARIA combobox pattern. See the linked page for a list of available keyboard interactions.

Collapsible combo box list follows the ARIA listbox pattern. See the linked page for a list of available keyboard interactions.

ComboBox requires a textual label to remain accessible to assistive technologies. See our accessibility guide for more details.

Combo box is a collection component. See our collection components guide to learn how to work with collections.

Combo box can integrate with native HTML forms. See our forms guide to learn how to work with forms.

Allows users to filter a collapsible list and select one item from it.

See combo box usage guidelines

Ref<HTMLDivElement>

The ref type for this component.

ComboBoxProps<T extends CollectionItem = CollectionItem>
boolean

Whether the list of options should be virtualized. Use this as a performance optimization for large lists.

Defaults to false .
UIEventHandler<HTMLDivElement>

Handler that is called when the list of items is scrolled.

string

The element's unique identifier. See MDN.

boolean

Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.

string

Sets the CSS className for the element. Only use as a last resort. Use style props instead.

See styling guide.

CSSProperties

Sets the CSS style for the element. Only use as a last resort. Use style props instead.

See styling guide.

string

The content to display as the label.

string

Defines a string value that labels the current element.

string

Identifies the element (or elements) that labels the current element.

string

Identifies the element (or elements) that describes the object.

string

Identifies the element (or elements) that provide a detailed, extended description for the object.

string

The <form> element to associate the input with. The value of this attribute must be the id of a <form> in the same document. See MDN.

string

The name of the input element, used when submitting an HTML form. See MDN.

string

A description for the field. Provides a hint such as specific requirements for what to choose.

FieldError

An error message for the field.

(value: ComboBoxValidationValue) => string | true | string[] | undefined

A function that returns an error message (or true) if a given value is invalid. Validation errors are displayed to the user when the form is submitted. For real-time validation, use the error prop instead.

string

The placeholder text displayed in the input field.

ReactNode | ((item: T) => ReactNode)

The contents of the collection.

Iterable<T, any, any>

The items to display in the collection.

boolean

Whether items are currently being loaded.

() => void

A callback function that is called when more items should be loaded.

RefObject<ComboBoxApi | null>

A React ref that allows access to the imperative API of this component.

(isOpen: boolean, menuTrigger?: MenuTriggerAction) => void

Method that is called when the open state of the menu changes. Returns the new open state and the action that caused the opening of the menu.

(key: Key | null) => void

Handler that is called when the selection changes.

string

The value of the ComboBox input (controlled).

string

The default value of the ComboBox input (uncontrolled).

(value: string) => void

Handler that is called when the ComboBox input value changes.

(e: FocusEvent<HTMLInputElement>) => void

Handler that is called when the element receives focus.

(e: FocusEvent<HTMLInputElement>) => void

Handler that is called when the element loses focus.

boolean

Whether the element should receive focus on render.

boolean

Whether user input is required on the input before form submission.

boolean

Whether the input value is invalid.

boolean

Whether the input is disabled.

boolean

Whether the input can be selected but not changed by the user.

Key | null

The currently selected key in the collection (controlled).

Key

The initial selected key in the collection (uncontrolled).

StyleProps
Responsive<Spacing | "auto">

The amount of margin applied to all edges of this component.

Responsive<Spacing | "auto">

The amount of margin applied to the left and right edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top and bottom edges of this component. Takes priority over margin.

Responsive<Spacing | "auto">

The amount of margin applied to the top edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the right edge of this component. Takes priority over marginX and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the bottom edge of this component. Takes priority over marginY and margin.

Responsive<Spacing | "auto">

The amount of margin applied to the left edge of this component. Takes priority over marginX and margin.

Renders a single list item within ComboBox.

ComboBoxItemProps<T extends CollectionItem>
StringLikeChildren

The content to display as the label.

Key

The ID of the item. Has to be unique across all sections and items.

(e: HoverEvent) => void

Handler that is called when a hover interaction starts.

(e: HoverEvent) => void

Handler that is called when a hover interaction ends.

boolean

Whether the item is disabled.

Groups list items within ComboBox into a section.

ComboBoxSectionProps<T extends CollectionItem>
string

The content to display as the section title.

Key

The ID of the section. Has to be unique across all sections and items.

ReactNode | ((item: T) => ReactNode)

The contents of the collection.

Iterable<T, any, any>

The items to display in the collection.