# Select
URL: /react/components/select
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/select.mdx
A component that selects a value from a list that opens when a trigger is pressed.
사용 가능 버전: @seed-design/react@2.1.0, @seed-design/css@2.3.0
## Preview
```tsx
import { Box } from "@seed-design/react";
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "seed-design/ui/select";
export default function SelectPreview() {
return (
);
}
```
## Installation
- npm: npx @seed-design/cli@latest add ui:select
- pnpm: pnpm dlx @seed-design/cli@latest add ui:select
- yarn: yarn dlx @seed-design/cli@latest add ui:select
- bun: bun x @seed-design/cli@latest add ui:select
## Usage
```tsx
import {
SelectRoot,
SelectTrigger,
SelectContent,
SelectGroup,
SelectItem,
} from "seed-design/ui/select";
```
```tsx
```
- `SelectRoot`: Manages the selected value (`value`) and open state.
- `SelectTrigger`: Displays the selected value or placeholder, and opens the list when clicked.
- `SelectContent`: Floating container that wraps the option list.
- `SelectGroup`: Groups related options together. All `SelectItem` must be inside a `SelectGroup`. The group title can be displayed with `label`.
- `SelectItem`: Individual option. Requires `value`, and shows a checkmark when selected.
## Props
### `SelectRoot`
### `SelectTrigger`
### `SelectContent`
### `SelectGroup`
### `SelectItem`
## Examples
### Size
The size of the trigger and list is set by `size`. (default: `large`)
When using `responsive`, the size automatically switches based on screen width.
```tsx
import { VStack } from "@seed-design/react";
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "seed-design/ui/select";
export default function SelectSize() {
return (
);
}
```
### Groups
Group options with `SelectGroup` and display the group title with `label`. Regardless of the number of `SelectGroup`, all `SelectItem` must be inside a `SelectGroup`.
If there are two or more groups, a divider is automatically drawn between the groups.
```tsx
import { Box } from "@seed-design/react";
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "seed-design/ui/select";
export default function SelectGroups() {
return (
);
}
```
### Multiple Selection
Specifying `multiple` on `SelectRoot` allows selecting multiple options. The list does not close when an option is selected, and pressing an already selected option again deselects it.
The trigger displays the `textValue` of the selected options joined by `", "`. This text can be changed with [Custom Value Format](#custom-value-format).
```tsx
import { Box } from "@seed-design/react";
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "seed-design/ui/select";
export default function SelectMultiple() {
return (
);
}
```
### With Description
Add supplementary descriptions to options with `SelectItem`'s `description` prop.
```tsx
import { Box } from "@seed-design/react";
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "seed-design/ui/select";
export default function SelectWithDescription() {
return (
);
}
```
### With Prefix Icon
Display icons on options with `SelectItem`'s `prefixIcon` prop.
When one option is selected, that option's icon is displayed as the trigger's prefix icon. When no option is selected, the selected option has no icon, or multiple options are selected, the trigger displays the `prefixIcon` specified on `SelectTrigger`.
```tsx
import {
IconGlobeLine,
IconLockLine,
IconPerson2Line,
IconPersonLine,
} from "@karrotmarket/react-monochrome-icon";
import { Box } from "@seed-design/react";
import {
SelectContent,
SelectGroup,
SelectItem,
SelectRoot,
SelectTrigger,
} from "seed-design/ui/select";
export default function SelectWithPrefixIcon() {
return (
}
/>
} />
} />
} />
);
}
```
### Custom Item Label
You can pass a ReactNode to `SelectItem`'s `label`. This node is rendered only on the options in the list.
When specifying a ReactNode instead of a string as `SelectItem`'s `label`, the trigger displays `SelectItem`'s `textValue`. `textValue` is `label` if `label` is a string, otherwise `value`.
Therefore, when `label` is not a string, it is recommended to also specify `textValue`. `textValue` is used as the text displayed on the trigger, the string matched when finding options by typing on the keyboard (typeahead), and the text of the native `