Files
shadcn-ui/apps/www/content/docs/components/select.mdx
2023-04-17 19:19:40 +04:00

71 lines
1.4 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>
```