shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/radix/select.jsonnpx shadcn@latest add https://kit.dev/r/radix/select.jsonpnpm dlx shadcn@latest add https://kit.dev/r/radix/select.jsonyarn shadcn@latest add https://kit.dev/r/radix/select.jsonInstall the following dependencies:
bun add radix-ui lucide-reactnpm install radix-ui lucide-reactpnpm add radix-ui lucide-reactyarn add radix-ui lucide-reactCopy and paste the following code into your project.
"use client";
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
import { Select as SelectPrimitive } from "radix-ui";
import type React from "react";
import { cn } from "@/lib/utils";
export const Select = (
props: React.ComponentProps<typeof SelectPrimitive.Root>
) => <SelectPrimitive.Root data-slot="select" {...props} />;
export const SelectGroup = (
props: React.ComponentProps<typeof SelectPrimitive.Group>
) => {
const { className, ...rest } = props;
return (
<SelectPrimitive.GroupUpdate 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
SelectLabel
label
PropType
AttributeType
SelectTrigger
button
PropType
AttributeType
SelectItem
div
PropType
valuestringdisabled?booleantextValue?stringAttributeType
SelectItemText
span
AttributeType
SelectItemIndicator
div
AttributeType
SelectContent
div
PropType
AttributeType
data-align-trigger?stringCSS variableType
--radix-select-content-available-heightstring--radix-select-content-transform-originstring--radix-select-trigger-heightstring--radix-select-trigger-widthstringSelect
div
PropType
AttributeType
SelectGroup
PropType
AttributeType
SelectValue
PropType
placeholder?React.ReactNodeAttributeType
SelectSeparator
PropType
AttributeType
SelectScrollUpButton
PropType
AttributeType
SelectScrollDownButton
PropType
AttributeType