mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-28 23:24:13 +00:00
* feat(form): add form component * feat(www): update site styles * feat: add form examples * docs(www): add docs for forms * docs(www): hide tabs for docs demo
84 lines
1.8 KiB
Plaintext
84 lines
1.8 KiB
Plaintext
---
|
|
title: Select
|
|
description: Displays a list of options for the user to pick from—triggered by a button.
|
|
component: true
|
|
featured: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/select
|
|
api: https://www.radix-ui.com/docs/primitives/components/select#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/select/demo.tsx">
|
|
<SelectDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npx shadcn-ui add select
|
|
```
|
|
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="manual-installation">
|
|
<AccordionTrigger>Manual Installation</AccordionTrigger>
|
|
<AccordionContent>
|
|
|
|
1. Install the `@radix-ui/react-select` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-select
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/select.tsx" />
|
|
|
|
<Callout>
|
|
|
|
This is the `<Select />` primitive. You can place it in a file at `components/ui/select.tsx`.
|
|
|
|
</Callout>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
</Accordion>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select"
|
|
```
|
|
|
|
```tsx
|
|
<Select>
|
|
<SelectTrigger className="w-[180px]">
|
|
<SelectValue placeholder="Theme" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="light">Light</SelectItem>
|
|
<SelectItem value="dark">Dark</SelectItem>
|
|
<SelectItem value="system">System</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
```
|
|
|
|
## React Hook Form
|
|
|
|
<Alert className="mt-4">
|
|
<AlertDescription>
|
|
**Note**: Learn more about using React Hook Form on the
|
|
[docs](/docs/forms/react-hook-form) page.
|
|
</AlertDescription>
|
|
</Alert>
|
|
|
|
<ComponentExample src="/components/examples/select/react-hook-form.tsx">
|
|
<SelectReactHookForm />
|
|
</ComponentExample>
|