본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

셀렉트(Select)

원문 보기 위키 갱신

버튼으로 트리거되는, 사용자가 고를 수 있는 옵션 목록을 표시하는 컴포넌트예요.

출처: 문서

본문

Import

import { Select } from "@kobalte/core/select";
// or
import { Root, Label, ... } from "@kobalte/core/select";
// or (deprecated)
import { Select } from "@kobalte/core";

Features

  • WAI ARIA Listbox 디자인 패턴을 사용해 리스트박스 팝업이 있는 버튼으로 보조 기술에 노출돼요.
  • 단일 및 다중 선택을 지원해요.
  • 비활성화된 옵션을 지원해요.
  • 접근성을 위한 라벨링을 지원해요.
  • ARIA를 통해 버튼에 연결된 설명 및 오류 메시지 도움말 텍스트를 지원해요.
  • 탭 정지(tab stop) 포커스 관리를 제공해요.
  • 화살표 키로 리스트박스를 여는 키보드 지원을 제공하며, 이에 맞춰 첫 번째 또는 마지막 항목을 자동으로 포커스해요.
  • 리스트박스를 열지 않아도 텍스트를 입력해 옵션을 선택할 수 있는 타입어헤드(typeahead) 기능을 제공해요.
  • 숨겨진 네이티브 <select> 요소를 통한 브라우저 자동 완성(autofill) 통합을 지원해요.
  • 항목 및 항목 그룹을 지원해요.
  • 커스텀 플레이스홀더를 지원해요.
  • 제어(controlled) 또는 비제어(uncontrolled) 방식으로 사용할 수 있어요.

Anatomy

셀렉트는 다음 요소들로 구성돼요:

  • Select: 셀렉트 컴포넌트의 루트 컨테이너예요.
  • Select.Label: 셀렉트에 대한 정보를 사용자에게 주는 라벨이에요.
  • Select.Description: 셀렉트에 대한 더 많은 정보를 사용자에게 주는 설명이에요.
  • Select.ErrorMessage: 셀렉트의 유효성 검사 오류를 해결하는 방법을 사용자에게 알려주는 오류 메시지예요.
  • Select.Trigger: 셀렉트를 여는 버튼이에요.
  • Select.Value: 선택된 값을 반영하는 부분이에요.
  • Select.Icon: 열 수 있다는 사실을 시각적으로 보여주기 위해 값 옆에 자주 표시되는 작은 아이콘이에요.
  • Select.Portal: 셀렉트가 열려 있을 때 자식 요소를 body로 포털해요.
  • Select.Content: 셀렉트가 열려 있을 때 렌더링할 콘텐츠를 담아요.
  • Select.Arrow: 셀렉트 콘텐츠 옆에 렌더링되는 선택적 화살표 요소예요.
  • Select.Listbox: 항목 목록을 담고 있으며 사용자가 그중 하나 이상을 선택할 수 있게 해줘요.
  • Select.Section: 옵션 그룹의 라벨을 렌더링하는 데 사용돼요. 화살표 키로 포커스할 수 없어요.
  • Select.Item: 셀렉트의 항목이에요.
  • Select.ItemLabel: 항목에 대해 발표되는 접근 가능한 라벨이에요.
  • Select.ItemDescription: 항목에 대해 발표되는 선택적 접근 가능한 설명이에요.
  • Select.ItemIndicator: 항목이 선택되었을 때 렌더링되는 시각적 인디케이터예요.
<Select>
	<Select.Label />
	<Select.Trigger>
		<Select.Value />
		<Select.Icon />
	</Select.Trigger>
	<Select.Description />
	<Select.ErrorMessage />

	<Select.Portal>
		<Select.Content>
			<Select.Arrow />
			<Select.Listbox />
		</Select.Content>
	</Select.Portal>
</Select>

Example

Usage

Default value

options에 대응하는 값을 받는 defaultValue prop으로 초기 비제어(uncontrolled) 값을 제공할 수 있어요.

<Select
	defaultValue="Blueberry"
	options={["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]}
	placeholder="Select a fruit…"
	itemComponent={props => (
		<Select.Item item={props.item}>
			<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
			<Select.ItemIndicator>
				<CheckIcon />
			</Select.ItemIndicator>
		</Select.Item>
	)}
>
	<Select.Trigger aria-label="Fruit">
		<Select.Value<string>>{state => state.selectedOption()}</Select.Value>
		<Select.Icon>
			<CaretSortIcon />
		</Select.Icon>
	</Select.Trigger>
	<Select.Portal>
		<Select.Content>
			<Select.Listbox />
		</Select.Content>
	</Select.Portal>
</Select>

Controlled value

options prop에 대응하는 값을 받는 value prop을 사용해 값을 제어(controlled) 방식으로 만들 수 있어요. 사용자가 옵션을 선택하면 onChange 이벤트가 발생하며 선택된 옵션을 받아요.

import { createSignal } from "solid-js";

export function ControlledExample() {
	const [value, setValue] = createSignal("Blueberry");

	return (
		<>
			<Select
				value={value()}
				onChange={setValue}
				options={["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]}
				placeholder="Select a fruit…"
				itemComponent={props => (
					<Select.Item item={props.item}>
						<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
						<Select.ItemIndicator>
							<CheckIcon />
						</Select.ItemIndicator>
					</Select.Item>
				)}
			>
				<Select.Trigger aria-label="Fruit">
					<Select.Value<string>>{state => state.selectedOption()}</Select.Value>
					<Select.Icon>
						<CaretSortIcon />
					</Select.Icon>
				</Select.Trigger>
				<Select.Portal>
					<Select.Content>
						<Select.Listbox />
					</Select.Content>
				</Select.Portal>
			</Select>
			<p>Your favorite fruit is: {value()}.</p>
		</>
	);
}

Description

Select.Description 컴포넌트를 사용해 셀렉트에 추가 도움말 텍스트를 연결할 수 있어요.

<Select
	options={["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]}
	placeholder="Select a fruit…"
	itemComponent={props => (
		<Select.Item item={props.item}>
			<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
			<Select.ItemIndicator>
				<CheckIcon />
			</Select.ItemIndicator>
		</Select.Item>
	)}
>
	<Select.Trigger aria-label="Fruit">
		<Select.Value<string>>{state => state.selectedOption()}</Select.Value>
		<Select.Icon>
			<CaretSortIcon />
		</Select.Icon>
	</Select.Trigger>
	<Select.Description>Choose the fruit you like the most.</Select.Description>
	<Select.Portal>
		<Select.Content>
			<Select.Listbox />
		</Select.Content>
	</Select.Portal>
</Select>

Error message

Select.ErrorMessage 컴포넌트를 사용해 사용자가 유효성 검사 오류를 해결하도록 도울 수 있어요. 보조 기술에 셀렉트를 의미적으로 유효하지 않음으로 표시하기 위해 validationState prop과 함께 사용해야 해요.

기본적으로 validationState prop이 invalid로 설정된 경우에만 렌더링돼요. 오류 메시지를 항상 렌더링하려면 forceMount prop을 사용해요(ex: 애니메이션 라이브러리와 함께 사용할 때).

import { createSignal } from "solid-js";

export function ErrorMessageExample() {
	const [value, setValue] = createSignal("Grapes");

	return (
		<Select
			value={value()}
			onChange={setValue}
			validationState={value() !== "Apple" ? "invalid" : "valid"}
			options={["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]}
			placeholder="Select a fruit…"
			itemComponent={props => (
				<Select.Item item={props.item}>
					<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
					<Select.ItemIndicator>
						<CheckIcon />
					</Select.ItemIndicator>
				</Select.Item>
			)}
		>
			<Select.Trigger aria-label="Fruit">
				<Select.Value<string>>{state => state.selectedOption()}</Select.Value>
				<Select.Icon>
					<CaretSortIcon />
				</Select.Icon>
			</Select.Trigger>
			<Select.ErrorMessage>Hmm, I prefer apples.</Select.ErrorMessage>
			<Select.Portal>
				<Select.Content>
					<Select.Listbox />
				</Select.Content>
			</Select.Portal>
		</Select>
	);
}

HTML forms

셀렉트의 name prop을 Select.HiddenSelect 컴포넌트와 함께 사용해 HTML 폼과 통합할 수 있어요.

function HTMLFormExample() {
	const onSubmit = (e: SubmitEvent) => {
		// handle form submission.
	};

	return (
		<form onSubmit={onSubmit}>
			<Select
				name="fruit"
				options={["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]}
				placeholder="Select a fruit…"
				itemComponent={props => (
					<Select.Item item={props.item}>
						<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
						<Select.ItemIndicator>
							<CheckIcon />
						</Select.ItemIndicator>
					</Select.Item>
				)}
			>
				<Select.HiddenSelect />
				<Select.Trigger aria-label="Fruit">
					<Select.Value<string>>{state => state.selectedOption()}</Select.Value>
					<Select.Icon>
						<CaretSortIcon />
					</Select.Icon>
				</Select.Trigger>
				<Select.Portal>
					<Select.Content>
						<Select.Listbox />
					</Select.Content>
				</Select.Portal>
			</Select>
			<div>
				<button type="reset">Reset</button>
				<button>Submit</button>
			</div>
		</form>
	);
}

Using object as options

일반 문자열 대신 객체를 옵션으로 사용할 수 있어요. 이 경우 셀렉트가 제공된 옵션을 어떻게 다뤄야 하는지 알려줘야 해요. 이를 위해 다음 prop들을 반드시 사용해야 해요:

  • optionValue: 옵션의 값으로 사용할 프로퍼티 이름이에요(<form>과 함께 제출돼요).
  • optionTextValue: 키보드 탐색을 위한 옵션의 텍스트 값으로 사용할 프로퍼티 이름이에요.
  • optionDisabled: 옵션의 비활성화 플래그로 사용할 프로퍼티 이름이에요.
interface Fruit {
	value: string;
	label: string;
	disabled: boolean;
}

const options: Fruit[] = [
	{ value: "apple", label: "Apple", disabled: false },
	{ value: "banana", label: "Banana", disabled: false },
	{ value: "blueberry", label: "Blueberry", disabled: false },
	{ value: "grapes", label: "Grapes", disabled: true },
	{ value: "pineapple", label: "Pineapple", disabled: false },
];

function ObjectExample() {
	return (
		<Select
			options={options}
			optionValue="value"
			optionTextValue="label"
			optionDisabled="disabled"
			placeholder="Select a fruit…"
			itemComponent={props => (
				<Select.Item item={props.item}>
					<Select.ItemLabel>{props.item.rawValue.label}</Select.ItemLabel>
					<Select.ItemIndicator>
						<CheckIcon />
					</Select.ItemIndicator>
				</Select.Item>
			)}
		>
			<Select.Trigger aria-label="Fruit">
				<Select.Value<Fruit>>{state => state.selectedOption().label}</Select.Value>
				<Select.Icon>
					<CaretSortIcon />
				</Select.Icon>
			</Select.Trigger>
			<Select.Portal>
				<Select.Content>
					<Select.Listbox />
				</Select.Content>
			</Select.Portal>
		</Select>
	);
}

Using option groups

옵션 그룹을 사용할 때 셀렉트가 옵션과 그룹을 구별하는 방법을 알려줘야 해요. 이를 위해 다음 prop을 반드시 사용해야 해요:

  • optionGroupChildren: 옵션 그룹의 자식 옵션들을 가리키는 프로퍼티 이름이에요.

추가로, sectionComponent prop은 셀렉트에 옵션 그룹 라벨을 표시하는 데 사용돼요.

interface Food {
	value: string;
	label: string;
	disabled: boolean;
}

interface Category {
	label: string;
	options: Food[];
}

const options: Category[] = [
	{
		label: "Fruits",
		options: [
			{ value: "apple", label: "Apple", disabled: false },
			{ value: "banana", label: "Banana", disabled: false },
			{ value: "blueberry", label: "Blueberry", disabled: false },
			{ value: "grapes", label: "Grapes", disabled: true },
			{ value: "pineapple", label: "Pineapple", disabled: false },
		],
	},
	{
		label: "Meat",
		options: [
			{ value: "beef", label: "Beef", disabled: false },
			{ value: "chicken", label: "Chicken", disabled: false },
			{ value: "lamb", label: "Lamb", disabled: false },
			{ value: "pork", label: "Pork", disabled: false },
		],
	},
];

function OptionGroupExample() {
	return (
		<Select<Food, Category>
			options={options}
			optionValue="value"
			optionTextValue="label"
			optionDisabled="disabled"
			optionGroupChildren="options"
			placeholder="Select a food…"
			itemComponent={props => (
				<Select.Item item={props.item}>
					<Select.ItemLabel>{props.item.rawValue.label}</Select.ItemLabel>
					<Select.ItemIndicator>
						<CheckIcon />
					</Select.ItemIndicator>
				</Select.Item>
			)}
			sectionComponent={props => <Select.Section>{props.section.rawValue.label}</Select.Section>}
		>
			<Select.Trigger aria-label="Food">
				<Select.Value<Food>>{state => state.selectedOption().label}</Select.Value>
				<Select.Icon>
					<CaretSortIcon />
				</Select.Icon>
			</Select.Trigger>
			<Select.Portal>
				<Select.Content>
					<Select.Listbox />
				</Select.Content>
			</Select.Portal>
		</Select>
	);
}

참고: 제대로 된 TypeScript 지원을 위해 Select에 제네릭을 사용하고 있음을 주의하세요.

Multiple selection

multiple prop을 사용해 다중 선택이 가능한 셀렉트를 만들 수 있어요. 이 경우 value, defaultValue, onChange prop에 제공되는 값의 타입은 Array<T>예요.

Select.Value 자식 _render prop_은 선택된 옵션 배열과, 선택에서 옵션을 제거하고 선택을 비우는 두 가지 메서드를 노출해요.

또한 아래 예시는 W3C에 따라 HTML button이 인터랙티브 요소를 담을 수 없기 때문에 as prop을 사용해 Select.Trigger를 div로 렌더링해요.

import { createSignal } from "solid-js";

function MultipleSelectionExample() {
	const [values, setValues] = createSignal(["Blueberry", "Grapes"]);

	return (
		<>
			<Select<string>
				multiple
				value={values()}
				onChange={setValues}
				options={["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"]}
				placeholder="Select some fruits…"
				itemComponent={props => (
					<Select.Item item={props.item}>
						<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
						<Select.ItemIndicator>
							<CheckIcon />
						</Select.ItemIndicator>
					</Select.Item>
				)}
			>
				<Select.Trigger aria-label="Fruits" as="div">
					<Select.Value<string>>
						{state => (
							<>
								<div>
									<For each={state.selectedOptions()}>
										{option => (
											<span onPointerDown={e => e.stopPropagation()}>
											{option}
											<button onClick={() => state.remove(option)}>
												<CrossIcon />
											</button>
											</span>
										)}
									</For>
								</div>
								<button onPointerDown={e => e.stopPropagation()} onClick={state.clear}>
									<CrossIcon />
								</button>
							</>
						)}
					</Select.Value>
					<Select.Icon>
						<CaretSortIcon />
					</Select.Icon>
				</Select.Trigger>
				<Select.Portal>
					<Select.Content>
						<Select.Listbox />
					</Select.Content>
				</Select.Portal>
			</Select>
			<p>Your favorite fruits are: {values().join(", ")}.</p>
		</>
	);
}

Virtual scrolling

큰 항목 컬렉션을 다룰 때는 성능 향상을 위해 가상 스크롤(virtual scrolling) 솔루션을 사용하는 것이 좋아요.

Kobalte는 내장 가상 스크롤 API를 제공하지 않지만, 3rd party 라이브러리와 쉽게 통합할 수 있어요. 아래 예시는 @tanstack/solid-virtual 패키지를 사용해 100,000개 옵션의 배열을 가상화하는 방법을 보여줘요.

import { Select } from "@kobalte/core/select";
import { createVirtualizer } from "@tanstack/solid-virtual";

interface Item {
	value: string;
	label: string;
	disabled: boolean;
}

const options: Item[] = Array.from({ length: 100_000 }, (_, i) => ({
	value: `${i}`,
	label: `Item #${i + 1}`,
	disabled: false,
}));

function SelectContent(props: { options: Item[] }) {
	let listboxRef: HTMLUListElement | undefined;

	const virtualizer = createVirtualizer({
		count: props.options.length,
		getScrollElement: () => listboxRef,
		getItemKey: (index: number) => props.options[index].value,
		estimateSize: () => 32,
		enableSmoothScroll: false,
		overscan: 5,
	});

	return (
		<Select.Content>
			<Select.Listbox
				ref={listboxRef}
				scrollToItem={key =>
					virtualizer.scrollToIndex(props.options.findIndex(option => option.value === key))
				}
				style={{ height: "200px", width: "100%", overflow: "auto" }}
			>
				{items => (
					<div
						style={{
							height: `${virtualizer.getTotalSize()}px`,
							width: "100%",
							position: "relative",
						}}
					>
						<For each={virtualizer.getVirtualItems()}>
							{virtualRow => {
								const item = items().getItem(virtualRow.key);

								if (item) {
									return (
										<Select.Item
											item={item}
											style={{
												position: "absolute",
												top: 0,
												left: 0,
												width: "100%",
												height: `${virtualRow.size}px`,
												transform: `translateY(${virtualRow.start}px)`,
											}}
										>
											<Select.ItemLabel>{item.rawValue.label}</Select.ItemLabel>
											<Select.ItemIndicator>
												<CheckIcon />
											</Select.ItemIndicator>
										</Select.Item>
									);
								}
							}}
						</For>
					</div>
				)}
			</Select.Listbox>
		</Select.Content>
	);
}

function VirtualizedExample() {
	return (
		<Select
			virtualized
			options={options}
			optionValue="value"
			optionTextValue="label"
			optionDisabled="disabled"
			placeholder="Select an item…"
		>
			<Select.Trigger aria-label="Food">
				<Select.Value<Item>>{state => state.selectedOption().label}</Select.Value>
				<Select.Icon>
					<CaretSortIcon />
				</Select.Icon>
			</Select.Trigger>
			<Select.Portal>
				<SelectContent options={options} />
			</Select.Portal>
		</Select>
	);
}

Origin-aware animations

CSS 커스텀 프로퍼티 --kb-select-content-transform-origin을 노출하며, 이를 사용해 계산된 원점(origin)에서 콘텐츠를 애니메이션할 수 있어요.

/* style.css */
.select__content {
	transform-origin: var(--kb-select-content-transform-origin);
	animation: contentHide 250ms ease-in forwards;
}

.select__content[data-expanded] {
	animation: contentShow 250ms ease-out;
}

@keyframes contentShow {
	from {
		opacity: 0;
		transform: translateY(-8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes contentHide {
	from {
		opacity: 1;
		transform: translateY(0);
	}
	to {
		opacity: 0;
		transform: translateY(-8px);
	}
}

API Reference

Select

Select는 @kobalte/core/select의 Root import와 동일해요(그리고 폐기(deprecated)된 Select.Root).

Prop Description
options Array<T | U>
An array of options to display as the available options.
optionValue keyof T | ((option: T) => string | number)
Property name or getter function to use as the value of an option. This is the value that will be submitted when the select is part of a <form>.
optionTextValue keyof T | ((option: T) => string)
Property name or getter function to use as the text value of an option for typeahead purpose.
optionDisabled keyof T | ((option: T) => boolean)
Property name or getter function to use as the disabled flag of an option.
optionGroupChildren keyof U
Property name that refers to the children options of an option group.
itemComponent Component<SelectItemComponentProps<T>>
When NOT virtualized, the component to render as an item in the Select.Listbox.
sectionComponent Component<SelectSectionComponentProps<U>>
When NOT virtualized, the component to render as a section in the Select.Listbox.
multiple boolean
Whether the select allows multi-selection.
placeholder JSX.Element
The content that will be rendered when no value or defaultValue is set.
value T | Array<T>
The controlled value of the select.
defaultValue T | Array<T>
The value of the select when initially rendered. Useful when you do not need to control the value.
onChange (value: T | Array<T>) => void
Event handler called when the value changes.
open boolean
The controlled open state of the select.
defaultOpen boolean
The default open state when initially rendered. Useful when you do not need to control the open state.
onOpenChange (open: boolean) => void
Event handler called when the open state of the select changes.
allowDuplicateSelectionEvents boolean
Whether onChange should fire even if the new value is the same as the last.
disallowEmptySelection boolean
Whether the select allows empty selection or not.
closeOnSelection boolean
Whether the select closes after selection.
selectionBehavior 'toggle' | 'replace'
How selection should behave in the select.
virtualized boolean
Whether the select uses virtual scrolling.
modal boolean
Whether the select should be the only visible content for screen readers, when set to true:
- interaction with outside elements will be disabled.
- scroll will be locked.
- focus will be locked inside the select content.
- elements outside the select content will not be visible for screen readers.
preventScroll boolean
Whether the scroll should be locked even if the select is not modal.
forceMount boolean
Used to force mounting the select (portal, positioner and content) when more control is needed. Useful when controlling animation with SolidJS animation libraries.
name string
The name of the select. Submitted with its owning form as part of a name/value pair.
validationState 'valid' | 'invalid'
Whether the select should display its "valid" or "invalid" visual styling.
required boolean
Whether the user must select an item before the owning form can be submitted.
disabled boolean
Whether the select is disabled.
readOnly boolean
Whether the select items can be selected but not changed by the user.
autoComplete string
Describes the type of autocomplete functionality the input should provide if any. See MDN

Select also accepts the following props to customize the placement of the Select.Content.

Prop Description
placement Placement
The placement of the select content.
gutter number
The distance between the select content and the trigger element.
shift number
The skidding of the select content along the trigger element.
flip boolean | string
Controls the behavior of the select content when it overflows the viewport:
- If a boolean, specifies whether the select content should flip to the opposite side when it overflows.
- If a string, indicates the preferred fallback placements when it overflows.
The placements must be spaced-delimited, e.g. "top left".
slide boolean
Whether the select content should slide when it overflows.
overlap boolean
Whether the select content can overlap the trigger element when it overflows.
sameWidth boolean
Whether the select content should have the same width as the trigger element. This will be exposed to CSS as --kb-popper-anchor-width.
fitViewport boolean
Whether the select content should fit the viewport. If this is set to true, the select content will have maxWidth and maxHeight set to the viewport size. This will be exposed to CSS as --kb-popper-available-width and --kb-popper-available-height.
hideWhenDetached boolean
Whether to hide the select content when the trigger element becomes occluded.
detachedPadding number
The minimum padding in order to consider the trigger element occluded.
arrowPadding number
The minimum padding between the arrow and the select content corner.
overflowPadding number
The minimum padding between the select content and the viewport edge. This will be exposed to CSS as --kb-popper-overflow-padding.
Data attribute Description
data-valid Present when the select is valid according to the validation rules.
data-invalid Present when the select is invalid according to the validation rules.
data-required Present when the user must select an item before the owning form can be submitted.
data-disabled Present when the select is disabled.
data-readonly Present when the select is read only.

Select.Label, Select.Trigger, Select.Value, Select.Description and Select.ErrorMessage shares the same data-attributes.

Select.Trigger

Select.Trigger는 Button으로 구성돼요.

Data attribute Description
data-expanded Present when the select is open.
data-closed Present when the select is close.

Select.Value

Render Prop Description
selectedOption Accessor<T>
The first (or only, in case of single select) selected option.
selectedOptions Accessor<T[]>
An array of selected options. It will contain only one value in case of single select.
remove (option: T) => void
A function to remove an option from the selection.
clear () => void
A function to clear the selection.
Data attribute Description
data-placeholder-shown Present when the select placeholder is visible (no value selected).

Select.Icon

Data attribute Description
data-expanded Present when the select is open.
data-closed Present when the select is close.

Select.ErrorMessage

Prop Description
forceMount boolean
Used to force mounting when more control is needed. Useful when controlling animation with SolidJS animation libraries.

Select.Content

포퍼 포지셔너(popper positioner)는 Select.Content와 동일한 z-index를 복사해요.

Data attribute Description
data-expanded Present when the select is open.
data-closed Present when the select is close.

Select.Arrow

Prop Description
size number
The size of the arrow.

Select.Listbox

Prop Description
scrollRef Accessor<HTMLElement | undefined>
The ref attached to the scrollable element, used to provide automatic scrolling on item focus. If not provided, defaults to the listbox.
scrollToItem (key: string) => void
When virtualized, the Virtualizer function used to scroll to the item of the given key.
children (items: Accessor<Collection<CollectionNode<T | U>>>) => JSX.Element
When virtualized, a map function that receives an items signal representing all items and sections.

Select.Item

Prop Description
item CollectionNode
The collection node to render.
Data attribute Description
data-disabled Present when the item is disabled.
data-selected Present when the item is selected.
data-highlighted Present when the item is highlighted.

Select.ItemLabel, Select.ItemDescription and Select.ItemIndicator shares the same data-attributes.

Select.ItemIndicator

Prop Description
forceMount boolean
Used to force mounting when more control is needed. Useful when controlling animation with SolidJS animation libraries.

Rendered elements

Component Default rendered element
Select div
Select.Label span
Select.Description div
Select.ErrorMessage div
Select.Trigger button
Select.Value span
Select.Icon span
Select.Portal Portal
Select.Content div
Select.Arrow div
Select.Listbox ul
Select.Section li
Select.Item li
Select.ItemLabel div
Select.ItemDescription div
Select.ItemIndicator div

Accessibility

Keyboard Interactions

Key Description
Space When focus is on the trigger, opens the select and focuses the first or selected item.
When focus is on an item, selects the focused item.
Enter When focus is on the trigger, opens the select and focuses the first or selected item.
When focus is on an item, selects the focused item.
ArrowDown When focus is on the trigger, opens the select and focuses the first or selected item.
When focus is on an item, moves focus to the next item.
ArrowUp When focus is on the trigger, opens the select and focuses the last or selected item.
When focus is on an item, moves focus to the previous item.
Home When focus is on an item, moves focus to first item.
End When focus is on an item, moves focus to last item.
ArrowRight In Select, when focus is on the trigger, change the selection to the next item.
ArrowLeft In Select, when focus is on the trigger, change the selection to the previous item.
Shift + ArrowDown In Select, moves focus to and toggles the selected state of the next item.
Shift + ArrowUp In Select, moves focus to and toggles the selected state of the previous item.
Shift + Space In Select, selects contiguous items from the most recently selected item to the focused item.
Ctrl + Shift + Home In Select, selects the focused item and all options up to the first item.
Ctrl + Shift + End In Select, selects the focused item and all options down to the last item.
Ctrl + A In Select, selects all item in the list.
Esc Closes the select and moves focus to the trigger.

더 알아보기 (Learn more)