Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Select for React

Displays a list of options.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/base/select.json

Anatomy

SelectRoot
├── SelectLabel
├── SelectClearTrigger
├── SelectItem
│   ├── SelectItemText
│   ├── SelectItemIndicator
│   └── SelectGroup
│       └── SelectGroupLabel
├── SelectList
├── SelectContent
│   └── SelectPositioner
├── SelectTrigger
│   └── SelectIndicator
└── SelectValue

Usage

import { createListCollection } from "@ark-ui/react/collection";
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";
const items = [
  { label: "Apple", value: "apple" },
  { label: "Banana", value: "banana" },
  { label: "Blueberry", value: "blueberry" },
];

const collection = createListCollection({ items });

const SelectDemo = () => (
  <Select collection={collection}>
    <SelectTrigger className="w-48">
      <SelectValue placeholder="Select a fruit" />
    </SelectTrigger>
    <SelectContent>
      <SelectGroup>
        {collection.items.map((item) => (
          <SelectItem item={item} key={item.value}>
            {item.label}
          </SelectItem>
        ))}
      </SelectGroup>
    </SelectContent>
  </Select>
);

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.
ArrowUp
Move up.
ArrowDown
Move down.
ArrowLeft
Move left.
ArrowRight
Move right.
Home
Go to the start.
End
Go to the end.

Demos

Align Item

Use data-align-trigger on SelectContent to mirror Base UI alignItemWithTrigger (selected item over the trigger vs edge-aligned).

Groups

Use SelectGroup, group headings, and SelectSeparator to organize items.

Scrollable

A select with many items that scrolls.

Disabled

A disabled select.

Invalid

Add data-invalid on Field and aria-invalid on SelectTrigger for the error state.

Rtl

Right-to-left select. See the RTL configuration guide for document direction.

API Reference

Select

PropType
AttributeType

SelectPositioner

div

PropType
AttributeType
CSS variableType
--anchor-widthstring
--available-heightstring
--transform-originstring

SelectTrigger

button

PropType
children?React.ReactNode
AttributeType

SelectItem

div

PropType
children?React.ReactNode
AttributeType

SelectItemText

div

AttributeType

SelectItemIndicator

span

PropType
children?React.ReactNode
AttributeType

SelectList

div

AttributeType
CSS variableType
--anchor-widthstring
--available-heightstring
--transform-originstring

SelectGroup

div

PropType
AttributeType

SelectValue

span

PropType
AttributeType

SelectContent

div

PropType
children?React.ReactNode
AttributeType
CSS variableType
--anchor-widthstring
--available-heightstring
--transform-originstring

SelectLabel

div

PropType
AttributeType

SelectSeparator

div

PropType
AttributeType

SelectScrollUpButton

div

PropType
AttributeType

SelectScrollDownButton

div

PropType
AttributeType