shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/select.jsonnpx shadcn@latest add https://kit.dev/r/aria/select.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/select.jsonyarn shadcn@latest add https://kit.dev/r/aria/select.jsonThis component depends on Input Group. Install it first if you haven't already.
Install the following dependencies:
bun add react-aria-components lucide-reactnpm install react-aria-components lucide-reactpnpm add react-aria-components lucide-reactyarn add react-aria-components lucide-reactCopy and paste the following code into your project.
"use client";
import { CheckIcon, ChevronDownIcon, SearchIcon } from "lucide-react";
import type React from "react";
import {
Button as ButtonPrimitive,
composeRenderProps,
Header as HeaderPrimitive,
ListBoxItem as ListBoxItemPrimitive,
ListBox as ListBoxPrimitive,
ListBoxSection as ListBoxSectionPrimitive,
Popover as PopoverPrimitive,
SearchField,
Select as SelectPrimitive,
SelectValue as SelectValuePrimitive,
Separator as SeparatorPrimitive,
type ListBoxProps,
type ListBoxSectionProps as SelectGroupProps,Update the import paths to match your project setup.
Anatomy
SelectRoot
├── SelectLabel
├── SelectClearTrigger
├── SelectItem
│ ├── SelectItemText
│ ├── SelectItemIndicator
│ └── SelectGroup
│ └── SelectGroupLabel
├── SelectList
├── SelectContent
│ └── SelectPositioner
├── SelectTrigger
│ └── SelectIndicator
└── SelectValueUsage
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
| Key | Description |
|---|---|
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
SelectGroup
PropType
AttributeType
SelectValue
PropType
AttributeType
SelectTrigger
PropType
AttributeType
SelectContent
PropType
AttributeType
SelectPopover
PropType
AttributeType
CSS variableType
--trigger-anchor-pointstring--trigger-widthstringSelectList
PropType
AttributeType
SelectInput
PropType
AttributeType
SelectLabel
PropType
AttributeType
SelectItem
PropType
AttributeType
SelectSeparator
PropType
AttributeType
SelectEmpty
PropType
AttributeType