Skip to main content
Select (Alpha)
@coinbase/cds-web@8.34.1
A flexible select component for both single and multi-selection, built for web applications with comprehensive accessibility support.
Alpha componentAlpha components are stable and safe to use. They allow us to provide new and powerful features quickly, without forcing breaking changes. Components will exit the alpha status when their deprecated counterpart is removed in the next major version.
Import
import { Select } from '@coinbase/cds-web/alpha/select'
SourceView source codeStorybookView Storybook
View as Markdown
Duplicate Values

Avoid using options with duplicate values. Each option's value should be unique within the options array to ensure proper selection behavior.

Single Select

Basic single selection with predefined options.

Loading...

Multi-Select

Multi-selection mode allows users to select multiple options from the list.

Disabled Options and Select All

Disabled options and options inside disabled groups will be skipped when "Select all" is pressed. Only enabled options will be selected.

Loading...

Single Select with Groups

Organize options into logical groups for better organization.

Loading...

Multi-Select with Groups

Use groups in multi-select mode to organize selections.

Loading...

Accessibility Props

The Select component supports comprehensive accessibility features including custom labels and roles.

Loading...

Variant Props

The Select component supports different visual variants for various states and contexts.

Loading...

With Disabled Option Group

Disable entire groups to prevent selection of those options.

Loading...

Compact Mode

The Select component can be rendered in a compact size for denser UIs.

Loading...

You can also use multi-selection mode while in a compact size.

Loading...

Disabled States

Components can be disabled entirely or have individual options disabled.

Loading...

Options with Descriptions

Options can include descriptions for additional context.

Loading...

Start Node

Add an icon or element at the start of the select control.

Loading...

End Node

Add an icon or element at the end of the select control.

Loading...

Custom Icons

Add custom icons as accessories or media to options.

Loading...

Empty State

Handle empty option lists with custom messages or components.

Loading...

Controlled Open State

Control the open/closed state of the dropdown programmatically.

Loading...

Multi-Select with Max Display

Limit the number of selected items shown when using multi-select.

Loading...

Custom Select All labels

Customize the select all functionality in multi-select mode.

Loading...

Label Variants

Different label positioning options for the Select component.

Loading...

Very Long Labels

Handle extremely long option labels that may need special treatment.

Loading...

Custom Long Placeholder

Use extended placeholder text for more descriptive empty states.

Loading...

Mixed Options

Options with and without descriptions in the same select.

Loading...

Options with Only Accessory

Add accessories without media for cleaner layouts.

Loading...

Options with Only Media

Add media icons without accessories for visual identification.

Loading...

Variants with Additional Props

Combine variants with other properties for complex states.

Loading...

Long Helper Text

Extended helper text for detailed instructions.

Loading...

No Label

Select without a visible label (accessibility label still required).

Loading...

Complex Nested Options

Options with special characters, emojis, and complex content.

Loading...

Stress Test

Many options with various configurations for performance testing.

Loading...

Value Display

Show the selected value in another component.

Loading...

Options with Only Description

Options that only have descriptions without labels.

Loading...

Custom styles

You can use custom styles on the various subcomponents in Select.

Loading...

Custom class names

You can use custom class names on the various subcomponents in Select.

function CustomClassNamesExamples() {
const exampleOptions = [
{ value: null, label: 'Remove selection' },
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2' },
{ value: '3', label: 'Option 3' },
{ value: '4', label: 'Option 4' },
];
const [value, setValue] = useState('1');

return (
<Select
classNames={{
control: customControlStyles,
option: customOptionStyles,
}}
label="Single select - class names"
onChange={setValue}
options={exampleOptions}
placeholder="Empty value"
value={value}
/>
);
}

Custom Label

If you need to render a custom label (e.g. a label with a tooltip), you can pass a React Node to the label prop.

Loading...

Custom components

Select is highly customizable. Use the Component props to customize the various subcomponents in Select.

Customizable subcomponents

  • SelectControlComponent: Trigger component used to open and close the Select.
  • SelectDropdownComponent: Component which renders the dropdown menu and SelectOptionComponents.
  • SelectOptionComponent: Component which renders the content of an option in the select.
  • SelectAllOptionComponent: Component which renders the Select All option in a multi-select select menu.
  • SelectEmptyDropdownContentsComponent: Component which renders as the select menu's content when no options are passed in.

Below is a diagram to help visualize the Select anatomy.

Select
├── SelectControlComponent (trigger to open/close)
└── SelectDropdownComponent (dropdown menu)
├── SelectAllOptionComponent
├── SelectOptionComponent (option 1)
├── SelectOptionComponent (option 2)
├── SelectOptionComponent (option 3)
└── SelectOptionComponent (option N...)

Example

function CustomComponentExamples() {
const exampleOptions = [
{ value: null, label: 'Remove selection' },
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2' },
{ value: '3', label: 'Option 3' },
{ value: '4', label: 'Option 4' },
];
const [value, setValue] = useState('1');

const CustomControlComponent = ({ value, setOpen }) => {
return <Button onClick={() => setOpen(true)}>{value ?? 'Empty value'}</Button>;
};

const CustomOptionComponent = ({ value, onClick }) => {
return (
<HStack justifyContent="center">
<Spinner size={4} />
<Button transparent onClick={() => onClick?.(value)} width="80%">
{value ?? 'Empty value'}
</Button>
<Spinner size={4} />
</HStack>
);
};

return (
<Select
SelectControlComponent={CustomControlComponent}
SelectOptionComponent={CustomOptionComponent}
label="Single select - custom components"
onChange={setValue}
options={exampleOptions}
placeholder="Empty value"
value={value}
/>
);
}

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.