Select — 옵션 모음에서 항목을 고르는 드롭다운
Select는 옵션 컬렉션에서 항목 하나를 고르는 데 쓰는 컴포넌트예요. 단일/다중 선택, 체크 표시, 체크박스, 필터, 그룹, 칩 등 폭넓은 선택 UI를 구성할 수 있어요.
출처: 문서
본문
Select는 옵션 컬렉션에서 항목을 고르는 데 사용해요.
사용법 (Usage)
import { Select } from '@primereact/ui/select';
<Select.Root>
<Select.Trigger>
<Select.Value />
<Select.Clear />
<Select.Indicator />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup>
<Select.Arrow />
<Select.Header>
<Select.Filter />
</Select.Header>
<Select.List>
<Select.Option>
<Select.OptionIndicator />
</Select.Option>
</Select.List>
<Select.Empty />
<Select.Footer />
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
예시
기본 (Basic)
옵션 드롭다운 리스트에서 단일 값을 선택해요.
다중 선택 (Multiple)
multiple prop을 사용하면 여러 항목을 선택할 수 있어요. 각 옵션 안에 체크 아이콘이 있는 Select.OptionIndicator를 배치해 선택 상태를 표시해요.
체크 표시 (Checkmark)
Select.Option 안에서 Select.OptionIndicator를 사용하면 선택된 옵션 옆에 시각적 체크 표시를 보여 줘요. data-unselected:invisible을 적용하면 옵션이 선택되지 않았을 때 인디케이터를 숨겨요.
체크박스 선택 (Checkbox Selection)
옵션 안에 Checkbox 컴포넌트를 통합해, 전체 선택 지원을 포함한 체크박스 기반 다중 선택 경험을 만들 수 있어요.
칩 (Chips)
Select.Value 안에 Chip 컴포넌트를 조합해, 선택된 항목을 제거 가능한 칩으로 표시해요.
지우기 (Clear)
트리거 안에 Select.Clear를 넣으면 선택을 초기화하는 지우기 버튼을 표시할 수 있어요.
필터 (Filter)
Select.Filter가 있는 Select.Header를 팝업 안에 추가해 검색 필드로 옵션을 필터링할 수 있어요. Select.Empty 컴포넌트는 일치하는 결과가 없을 때 메시지를 제공해요.
커스텀 옵션 (Custom Option)
Select.Option 안의 렌더 함수로 옵션 콘텐츠를 커스터마이즈할 수 있어요. 이 함수는 selected 상태를 포함한 옵션 인스턴스를 받아요.
그룹 (Group)
단순 (Simple)
optionGroupLabel과 optionGroupChildren 속성으로 옵션을 그룹화할 수 있어요.
커스텀 (Custom)
Select.List 안에서 리스트 인스턴스에 접근해 그룹 헤더를 커스텀 렌더링으로 꾸밀 수 있어요.
체크박스와 필터 (Checkbox and Filter)
그룹화된 옵션, 체크박스 선택, 필터를 조합해 선택 개수를 표시하는 컴팩트한 트리거와 함께 풍부한 다중 선택 경험을 만들 수 있어요.
화살표 (Arrow)
팝업 안에 Select.Arrow를 사용하면 트리거 요소를 가리키는 시각적 화살표를 표시할 수 있어요.
플로트 라벨 (Float Label)
FloatLabel과 연동해 over, in, on 세 가지 변형의 애니메이션 라벨 동작을 쓸 수 있어요.
Ifta 라벨 (Ifta Label)
IftaLabel을 사용하면 필드 위쪽에 정렬되는 인필드(infield) 라벨 패턴을 쓸 수 있어요.
유동 (Fluid)
fluid 속성으로 select가 컨테이너의 전체 너비를 차지하게 만들 수 있어요.
크기 (Sizes)
size 속성으로 select의 크기를 바꿀 수 있어요.
채움 (Filled)
variant="filled" 속성을 지정하면 기본 outlined 스타일보다 시각적 강조가 높은 컴포넌트로 표시돼요.
비활성화 (Disabled)
disabled 속성으로 select를 비활성화할 수 있어요.
유효하지 않음 (Invalid)
invalid 속성을 지정하면 검증 오류를 나타내는 빨간 테두리로 컴포넌트를 표시해요.
포커스 동작 (Focus Behavior)
autoOptionFocus, selectOnFocus, focusOnHover prop으로 키보드·마우스 포커스 동작을 커스터마이즈할 수 있어요.
계단식 (Cascade)
Select.Popup 안에 중첩된 Menu.Submenu 분기를 감싸 다단계 옵션을 드릴다운할 수 있어요. 각 리프는 Select.Option으로 렌더링되어 활성 값이 표준 선택 강조를 받아요.
트리 (Tree)
Select.Popup 안에 Tree를 넣으면 계층적 옵션을 노출할 수 있어요. 노드를 선택하면 그 값이 Select.Value에 반영되고, 열 때 현재 선택까지 경로가 펼쳐져요.
관련 자료
하위 컴포넌트 (Sub-Components)
SelectRoot, SelectTrigger, SelectList, SelectOption 등 컴포넌트 문서는 Primitive API에서 확인할 수 있어요.
훅 (Hooks)
useSelect 훅 문서는 Headless API에서 확인할 수 있어요.
접근성 (Accessibility)
WAI-ARIA 준수 사항과 키보드 지원에 대한 자세한 내용은 Select Primitive에서 볼 수 있어요.
테마 (Theming)
CSS 클래스 (CSS Classes)
styled 모드에서 사용하는 클래스 이름 목록이에요.
| ClassName | Description |
|---|---|
| p-select | Class name of the root element. |
| p-select-trigger | Class name of the trigger element. |
| p-select-label | Class name of the label element. |
| p-select-dropdown | Class name of the icon element. |
| p-select-clear-icon | Class name of the clear icon element. |
| p-select-positioner | Class name of the positioner element. |
| p-select-panel | Class name of the panel element. |
| p-select-filter | Class name of the filter element. |
| p-select-list | Class name of the list element. |
| p-select-options | Class name of the options element. |
| p-select-option | Class name of the option element. |
| p-select-selection | Class name of the selection element. |
| p-select-empty-message | Class name of the empty message element. |
디자인 토큰 (Design Tokens)
디자인 토큰 목록이에요.
| Token | CSS Variable | Description |
|---|---|---|
| select.background | --p-select-background | Background of root |
| select.disabled.background | --p-select-disabled-background | Disabled background of root |
| select.filled.background | --p-select-filled-background | Filled background of root |
| select.filled.hover.background | --p-select-filled-hover-background | Filled hover background of root |
| select.filled.focus.background | --p-select-filled-focus-background | Filled focus background of root |
| select.border.color | --p-select-border-color | Border color of root |
| select.hover.border.color | --p-select-hover-border-color | Hover border color of root |
| select.focus.border.color | --p-select-focus-border-color | Focus border color of root |
| select.invalid.border.color | --p-select-invalid-border-color | Invalid border color of root |
| select.color | --p-select-color | Color of root |
| select.disabled.color | --p-select-disabled-color | Disabled color of root |
| select.placeholder.color | --p-select-placeholder-color | Placeholder color of root |
| select.invalid.placeholder.color | --p-select-invalid-placeholder-color | Invalid placeholder color of root |
| select.shadow | --p-select-shadow | Shadow of root |
| select.padding.x | --p-select-padding-x | Padding x of root |
| select.padding.y | --p-select-padding-y | Padding y of root |
| select.border.radius | --p-select-border-radius | Border radius of root |
| select.focus.ring.width | --p-select-focus-ring-width | Focus ring width of root |
| select.focus.ring.style | --p-select-focus-ring-style | Focus ring style of root |
| select.focus.ring.color | --p-select-focus-ring-color | Focus ring color of root |
| select.focus.ring.offset | --p-select-focus-ring-offset | Focus ring offset of root |
| select.focus.ring.shadow | --p-select-focus-ring-shadow | Focus ring shadow of root |
| select.transition.duration | --p-select-transition-duration | Transition duration of root |
| select.sm.font.size | --p-select-sm-font-size | Sm font size of root |
| select.sm.padding.x | --p-select-sm-padding-x | Sm padding x of root |
| select.sm.padding.y | --p-select-sm-padding-y | Sm padding y of root |
| select.lg.font.size | --p-select-lg-font-size | Lg font size of root |
| select.lg.padding.x | --p-select-lg-padding-x | Lg padding x of root |
| select.lg.padding.y | --p-select-lg-padding-y | Lg padding y of root |
| select.font.weight | --p-select-font-weight | Font weight of root |
| select.font.size | --p-select-font-size | Font size of root |
| select.dropdown.width | --p-select-dropdown-width | Width of dropdown |
| select.dropdown.color | --p-select-dropdown-color | Color of dropdown |
| select.overlay.background | --p-select-overlay-background | Background of overlay |
| select.overlay.border.color | --p-select-overlay-border-color | Border color of overlay |
| select.overlay.border.radius | --p-select-overlay-border-radius | Border radius of overlay |
| select.overlay.color | --p-select-overlay-color | Color of overlay |
| select.overlay.shadow | --p-select-overlay-shadow | Shadow of overlay |
| select.list.padding | --p-select-list-padding | Padding of list |
| select.list.gap | --p-select-list-gap | Gap of list |
| select.list.header.padding | --p-select-list-header-padding | Header padding of list |
| select.option.focus.background | --p-select-option-focus-background | Focus background of option |
| select.option.selected.background | --p-select-option-selected-background | Selected background of option |
| select.option.selected.focus.background | --p-select-option-selected-focus-background | Selected focus background of option |
| select.option.color | --p-select-option-color | Color of option |
| select.option.focus.color | --p-select-option-focus-color | Focus color of option |
| select.option.selected.color | --p-select-option-selected-color | Selected color of option |
| select.option.selected.focus.color | --p-select-option-selected-focus-color | Selected focus color of option |
| select.option.selected.font.weight | --p-select-option-selected-font-weight | Font weight of a selected option |
| select.option.padding | --p-select-option-padding | Padding of option |
| select.option.border.radius | --p-select-option-border-radius | Border radius of option |
| select.option.font.weight | --p-select-option-font-weight | Font weight of option |
| select.option.font.size | --p-select-option-font-size | Font size of option |
| select.option.group.background | --p-select-option-group-background | Background of option group |
| select.option.group.color | --p-select-option-group-color | Color of option group |
| select.option.group.font.weight | --p-select-option-group-font-weight | Font weight of option group |
| select.option.group.font.size | --p-select-option-group-font-size | Font size of option group |
| select.option.group.padding | --p-select-option-group-padding | Padding of option group |
| select.clear.icon.color | --p-select-clear-icon-color | Color of clear icon |
| select.checkmark.color | --p-select-checkmark-color | Color of checkmark |
| select.checkmark.gutter.start | --p-select-checkmark-gutter-start | Gutter start of checkmark |
| select.checkmark.gutter.end | --p-select-checkmark-gutter-end | Gutter end of checkmark |
| select.empty.message.padding | --p-select-empty-message-padding | Padding of empty message |