Select

A dropdown list of options.

A select displays a collapsible list of options and allows a user to choose one.

Fruit
<Select name="fruit" label="Fruit" placeholder="Select a fruit">
  <SelectItem id="apple">Apple</SelectItem>
  <SelectItem id="banana">Banana</SelectItem>
  <SelectItem id="orange">Orange</SelectItem>
</Select>

SelectItem

Each option in the select is rendered with a SelectItem component. The id prop is used as the value submitted with the form.

<Select name="fruit" label="Fruit">
  <SelectItem id="apple">Apple</SelectItem>
  <SelectItem id="banana">Banana</SelectItem>
  <SelectItem id="orange">Orange</SelectItem>
</Select>

SelectSection

Options can be grouped into sections using the SelectSection component. Each section accepts a title prop for a visual group header.

Food
<Select name="food" label="Food">
  <SelectSection title="Fruit">
    <SelectItem id="apple">Apple</SelectItem>
    <SelectItem id="banana">Banana</SelectItem>
    <SelectItem id="orange">Orange</SelectItem>
  </SelectSection>
  <SelectSection title="Vegetable">
    <SelectItem id="carrot">Carrot</SelectItem>
    <SelectItem id="broccoli">Broccoli</SelectItem>
    <SelectItem id="spinach">Spinach</SelectItem>
  </SelectSection>
</Select>

Validation

Select supports the same validation functions as the other form elements. See the validation documentation for more details.

<Select
  name="country"
  label="Country"
  validate={(value) => {
    if (!value) {
      return 'Please select a country';
    }
  }}
  isRequired
>
  <SelectItem id="us">United States</SelectItem>
  <SelectItem id="gb">United Kingdom</SelectItem>
  <SelectItem id="ca">Canada</SelectItem>
  <SelectItem id="au">Australia</SelectItem>
</Select>
Country (Required)

Other props

description

A description can be added to the select to provide additional information to the user.

TimezoneSelect the timezone for your account
<Select
  name="timezone"
  label="Timezone"
  description="Select the timezone for your account"
>
  <SelectItem id="utc">UTC</SelectItem>
  <SelectItem id="est">Eastern Time</SelectItem>
  <SelectItem id="pst">Pacific Time</SelectItem>
</Select>

icon

You can set an icon

Favourite Wizard
<Select
  name="favourite-wizard"
  label="Favourite Wizard"
  icon={<RiMagicLine size={18} />}
>
  <SelectItem id="harry-potter">Harry Potter</SelectItem>
  <SelectItem id="gandalf">Gandalf</SelectItem>
  <SelectItem id="merlin">Merlin</SelectItem>
</Select>

defaultSelectedKey

You can set the default selected option with the defaultSelectedKey prop.

Fruit
<Select name="fruit" label="Fruit" defaultSelectedKey="banana">
  <SelectItem id="apple">Apple</SelectItem>
  <SelectItem id="banana">Banana</SelectItem>
  <SelectItem id="orange">Orange</SelectItem>
</Select>

isRequired

A select can be marked as required by setting the isRequired prop to true.

Country (Required)Please select your country
<Select
  name="country"
  label="Country"
  description="Please select your country"
  isRequired
>
  <SelectItem id="us">United States</SelectItem>
  <SelectItem id="gb">United Kingdom</SelectItem>
  <SelectItem id="ca">Canada</SelectItem>
</Select>

isInvalid

When rendered inside a form, the select will automatically enter an invalid state and display the field error message defined by the validation function. However, it is also possible to manually set the invalid state by setting the isInvalid prop to true and passing an errorMessage prop.

Country (Required)Please select a country
<Select
  name="country"
  label="Country"
  errorMessage="Please select a country"
  isInvalid
  isRequired
>
  <SelectItem id="us">United States</SelectItem>
  <SelectItem id="gb">United Kingdom</SelectItem>
  <SelectItem id="ca">Canada</SelectItem>
</Select>

isDisabled

A select can be disabled by setting the isDisabled prop to true.

Fruit
<Select name="fruit" label="Fruit" defaultSelectedKey="apple" isDisabled>
  <SelectItem id="apple">Apple</SelectItem>
  <SelectItem id="banana">Banana</SelectItem>
  <SelectItem id="orange">Orange</SelectItem>
</Select>

Props

Select

PropTypeDescription
labelReactNodeThe label of the select.
descriptionReactNodeThe description of the select.
errorMessagestringThe error message to display when the select is invalid.
placeholderstringThe text to display when no option is selected.
isRequiredbooleanWhether the select is required.
isInvalidbooleanWhether the select is invalid.
isDisabledbooleanWhether the select is disabled.
validate(value: Key) => string | undefinedThe validation function to use for the select.
defaultSelectedKeystringThe id of the item selected by default.
selectedKeystringThe id of the currently selected item (controlled).
onSelectionChange(key: Key) => voidHandler called when the selected item changes.
namestringThe name of the select submitted with form data.
itemsIterable<T>Item objects to render dynamically using a render function.
childrenReactNode | ((item: T) => ReactNode)The select items, or a render function for dynamic items.

SelectItem

PropTypeDescription
idstringThe value submitted with the form for this option.
childrenReactNodeThe display label for this option.
textValuestringA plain text label used for typeahead search.

SelectSection

PropTypeDescription
titlestringThe heading label for the section.
itemsIterable<T>Items to render dynamically.
childrenReactNodeThe SelectItem elements to group.