키보드 탐색, 필터링, 단일/다중 선택을 가진 스타일 없는 셀렉트 드롭다운 컴포넌트예요.
출처: 문서
본문
Features (기능)
- 하위 컴포넌트(
Root, Trigger, Value, Indicator, Clear, Portal, Positioner, Popup, List, Option, OptionIndicator, Filter, Arrow, Header, Footer, Empty)를 갖춘 컴파운드 API예요.
- 키보드 포커스 순환을 가진 단일/다중 선택이에요.
- 검색 가능한 드롭다운을 위한 내장 필터 입력 통합이에요.
- 그룹 헤더 렌더링이 있는 옵션 그룹화예요.
Usage (사용법)
import { Select } from 'primereact/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>
Behavior (동작)
모션 애니메이션 (Motion Animation)
<Select.Popup motionProps={{ name: 'p-select' }}>...</Select.Popup>
애니메이션 단계, CSS 변수, 숨김 전략에 대한 자세한 내용은 Motion을 참조하세요.
다형성 렌더링 (Polymorphic Rendering)
어떤 하위 컴포넌트든 as를 써서 렌더링되는 HTML 요소를 바꿀 수 있어요.
<Select.Root as="section">
<Select.Trigger as="div">...</Select.Trigger>
</Select.Root>
렌더 함수 children (Render Function Children)
Select.List는 children으로 렌더 함수를 받아 커스텀 옵션 렌더링을 위한 컴포넌트 인스턴스에 접근할 수 있게 해줘요.
<Select.List>
{(instance) =>
instance.options?.map((option, index) => (
<Select.Option key={index} index={index}>
{instance.listbox?.getOptionLabel(option)}
</Select.Option>
))
}
</Select.List>
API
SelectRoot
| Attribute |
Value |
data-scope |
"select" |
data-part |
"root" |
| Label |
Type |
Description |
| root |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| trigger |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the trigger's DOM element. |
| value |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the value's DOM element. |
| clearIcon |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the clear icon's DOM element. |
| icon |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the icon's DOM element. |
| positioner |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the positioner's DOM element. |
| panel |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the panel's DOM element. |
| filter |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the filter's DOM element. |
| list |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the list's DOM element. |
| options |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the options' DOM element. |
| option |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the option's DOM element. |
| selection |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the selection's DOM element. |
| header |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the header's DOM element. |
| footer |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the footer's DOM element. |
| empty |
SelectRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the empty's DOM element. |
SelectTrigger
| Attribute |
Value |
data-scope |
"select" |
data-part |
"trigger" |
data-positioner-open |
Present when popup is open |
| Label |
Type |
Description |
| root |
SelectTriggerPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectValue
| Label |
Type |
Description |
| root |
SelectValuePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectIndicator
| Attribute |
Value |
data-scope |
"select" |
data-part |
"indicator" |
data-open |
Present when popup is open |
data-closed |
Present when popup is closed |
| Label |
Type |
Description |
| root |
SelectIndicatorPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectClear
| Attribute |
Value |
data-scope |
"select" |
data-part |
"clear" |
| Label |
Type |
Description |
| root |
SelectClearPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectPortal
| Label |
Type |
Description |
| root |
SelectPortalPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectPositioner
| Attribute |
Value |
data-side |
"top" | "bottom" | "left" | "right", placement |
data-align |
"start" | "center" | "end", alignment |
CSS 커스텀 프로퍼티
positioner 요소는 레이아웃과 변환 제어를 위한 CSS 커스텀 프로퍼티를 노출해요.
| CSS Variable |
Description |
--available-height |
Available vertical space in pixels |
--available-width |
Available horizontal space in pixels |
--transform-origin |
Computed transform origin for animations |
--positioner-anchor-width |
Width of the anchor/trigger element |
| Label |
Type |
Description |
| root |
SelectPositionerPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"select" |
data-part |
"popup" |
data-open |
Present when popup is open |
| Label |
Type |
Description |
| root |
SelectPopupPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectFilter
| Attribute |
Value |
data-scope |
"select" |
data-part |
"filter" |
| Label |
Type |
Description |
| root |
SelectFilterPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| input |
SelectFilterPassThroughType<HTMLAttributes> |
Used to pass attributes to the input's DOM element. |
SelectList
| Attribute |
Value |
data-scope |
"select" |
data-part |
"list" |
| Label |
Type |
Description |
| root |
SelectListPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectOption
| Attribute |
Value |
data-selected |
Present when selected |
data-unselected |
Present when unselected |
data-focused |
Present when focused |
data-disabled |
Present when disabled |
| Label |
Type |
Description |
| root |
SelectOptionPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectOptionIndicator
| Attribute |
Value |
data-selected |
Present when selected |
data-unselected |
Present when unselected |
| Label |
Type |
Description |
| root |
SelectOptionIndicatorPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
SelectHeaderPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
SelectFooterPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectEmpty
| Label |
Type |
Description |
| root |
SelectEmptyPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
SelectArrow
| Attribute |
Value |
data-side |
"top" | "bottom" | "left" | "right", placement |
data-align |
"start" | "center" | "end", alignment |
CSS 커스텀 프로퍼티
arrow 요소는 동적 위치 지정을 위한 CSS 커스텀 프로퍼티를 노출해요:
| CSS Variable |
Description |
--placer-arrow-x |
Horizontal offset of arrow |
--placer-arrow-y |
Vertical offset of arrow |
--placer-arrow-left |
Left position of arrow element |
--placer-arrow-top |
Top position of arrow element |
| Label |
Type |
Description |
| root |
SelectArrowPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
Accessibility (접근성)
스크린 리더 (Screen Reader)
Select.Root는 combobox 패턴을 사용해요. trigger는 role="combobox"를 가지며 팝업 가시성을 반영하는 aria-expanded와 listbox를 가리키는 aria-controls를 가져요. aria-activedescendant 속성은 키보드 탐색 중 스크린 리더가 어떤 옵션을 읽을지 알려줘요. 옵션은 role="option"이며 현재 선택을 나타내는 aria-selected를 가져요. clear 버튼은 스크린 리더 접근성을 위한 aria-label을 가져요. 표시기 같은 장식 요소는 aria-hidden으로 스크린 리더에서 숨겨져요. 접근 가능한 이름은 aria-label, aria-labelledby, 또는 연결된 label 요소로 제공하세요.
키보드 지원 (Keyboard Support)
| Key |
Function |
tab |
Moves focus to the select trigger. |
enter |
Opens the popup when focused, selects the focused option when open. |
space |
Opens the popup when focused, selects the focused option when open. |
escape |
Closes the popup. |
arrow down |
Opens the popup or moves focus to the next option. |
arrow up |
Opens the popup or moves focus to the previous option. |
home |
Moves focus to the first option. |
end |
Moves focus to the last option. |
더 알아보기 (Learn more)