Skip to content

Select API

Cimpress UI exports three select-related components:

  • Select: main component that allows users to select one item from a collapsible list.
  • SelectItem: component that renders a single selectable item within a select.
  • SelectSection: component that groups related select items together under a section title.
import { Select, SelectItem, SelectSection } 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.

Collapsible select list can be opened by focusing on the select trigger and pressing Enter, Space, Up Arrow, or Down Arrow.

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

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

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

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

Allows users to select one item from a collapsible list.

See select usage guidelines.

Ref<HTMLDivElement>

The ref type for this component.

SelectProps<T extends CollectionItem = CollectionItem>
Key | null

The currently selected key in the collection (controlled).

Key

The initial selected key in the collection (uncontrolled).

(key: Key | null) => void

Handler that is called when the selection changes.

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: Key) => 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.

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<SelectApi | null>

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

(isOpen: boolean) => void

Method that is called when the open state of the menu changes.

string

Describes the type of autocomplete functionality the input should provide if any. See MDN.

(e: FocusEvent<Element>) => void

Handler that is called when the element receives focus.

(e: FocusEvent<Element>) => 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.

string

Temporary text that occupies the select when it is empty.

Defaults to 'Select an item' (localized) .
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 Select.

SelectItemProps
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 Select into a section.

SelectSectionProps<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.