Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Select for React and Tailwind

Displays a list of options.

Installation

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

Anatomy

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

Usage

import { createListCollection } from "@ark-ui/react/collection";
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select";
const SelectDemo = () => (
  <Select collection={collection}>
    <SelectTrigger className="w-48">
      <SelectValue placeholder="Select a fruit" />
    </SelectTrigger>

    <SelectContent>
      <SelectGroup heading="Fruits">
        {collection.items.map((item) => (
          <SelectItem item={item} key={item}>
            {item}
          </SelectItem>
        ))}
      </SelectGroup>
    </SelectContent>
  </Select>
);

const collection = createListCollection({
  items: ["Banana", "Apple", "Orange", "Pineapple"],
});

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

Controlled

Disabled

Empty

Grouping

Invalid

Max Selection

Multiple

Size Lg

Size Md

Size Sm

With Field

With Scroll

API Reference

SelectPositioner

div

PropType
CSS variableType

SelectTrigger

button

PropType
AttributeType

SelectIndicator

div

PropType

SelectClearTrigger

button

PropType
AttributeType

SelectItem

div

PropType
AttributeType

SelectItemText

span

PropType

SelectItemIndicator

div

PropType

SelectGroup

div

PropType
AttributeType

SelectGroupLabel

div

PropType
AttributeType

SelectContent

div

PropType
AttributeType
CSS variableType

SelectTrigger

div

PropType
AttributeType

SelectValue

span

PropType
AttributeType

SelectSeparator

PropType
AttributeType

SelectEmpty

div

PropType
AttributeType

useSelect

PropType

SelectContext

PropType