shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/base/select.jsonnpx shadcn@latest add https://kit.dev/r/base/select.jsonpnpm dlx shadcn@latest add https://kit.dev/r/base/select.jsonyarn shadcn@latest add https://kit.dev/r/base/select.jsonInstall the following dependencies:
bun add @base-ui/react lucide-reactnpm install @base-ui/react lucide-reactpnpm add @base-ui/react lucide-reactyarn add @base-ui/react lucide-reactCopy and paste the following code into your project.
"use client";
import { Select as SelectPrimitive } from "@base-ui/react/select";
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
import type React from "react";
import { cn } from "@/lib/utils";
export const Select = SelectPrimitive.Root;
export const SelectGroup = (props: SelectPrimitive.Group.Props) => {
const { className, ...rest } = props;
return (
<SelectPrimitive.Group
className={cn("cn-select-group", className)}
data-slot="select-group"
{...rest}
/>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
SelectPositioner
div
PropType
AttributeType
CSS variableType
--anchor-widthstring--available-heightstring--transform-originstringSelectTrigger
button
PropType
children?React.ReactNodeAttributeType
SelectItem
div
PropType
children?React.ReactNodeAttributeType
SelectItemText
div
AttributeType
SelectItemIndicator
span
PropType
children?React.ReactNodeAttributeType
SelectList
div
AttributeType
CSS variableType
--anchor-widthstring--available-heightstring--transform-originstringSelectGroup
div
PropType
AttributeType
SelectValue
span
PropType
AttributeType
SelectContent
div
PropType
children?React.ReactNodeAttributeType
CSS variableType
--anchor-widthstring--available-heightstring--transform-originstringSelectLabel
div
PropType
AttributeType
SelectSeparator
div
PropType
AttributeType
SelectScrollUpButton
div
PropType
AttributeType
SelectScrollDownButton
div
PropType
AttributeType