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

Combobox (콤보박스)

원문 보기 위키 갱신

텍스트 입력과 리스트박스를 결합해, 사용자가 쿼리에 일치하는 옵션 목록으로 필터링할 수 있게 해주는 컴포넌트예요. 단일·다중 선택, 옵션 그룹, 비활성 옵션, 사용자 정의 필터링을 지원해요.

출처: 문서

본문

임포트 (Import)

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

기능 (Features)

  • WAI ARIA Combobox 디자인 패턴을 사용해 보조 기술에 콤보박스로 노출돼요.
  • 단일 및 다중 선택을 지원해요.
  • 비활성 옵션을 지원해요.
  • 접근성을 위한 라벨링을 지원해요.
  • 버튼과 ARIA로 연결된 설명(description)·오류 메시지(error message) 도움말 텍스트를 지원해요.
  • 탭 정지(Tab stop) 포커스 관리를 제공해요.
  • 화살표 키를 사용해 리스트박스를 여는 키보드 지원 및 이에 따른 첫/마지막 항목 자동 포커스를 제공해요.
  • 타이핑 시, 포커스 시, 또는 수동으로 리스트박스를 여는 것을 지원해요.
  • 숨겨진 네이티브 <select> 요소를 통한 브라우저 자동 완성 통합을 제공해요.
  • VoiceOver 버그를 우회하기 위해 ARIA 라이브(live) 영역을 사용해 옵션 포커싱·필터링·선택에 대한 사용자 정의 현지화된 안내를 제공해요.
  • 항목과 항목 그룹을 지원해요.
  • 사용자 정의 플레이스홀더를 지원해요.
  • 제어(controlled) 또는 비제어(uncontrolled) 방식으로 사용할 수 있어요.

구조 (Anatomy)

콤보박스는 다음 요소로 구성돼요.

  • Combobox: 콤보박스 컴포넌트의 루트 컨테이너예요.
  • Combobox.Label: 콤보박스에 대한 정보를 사용자에게 알려주는 라벨이에요.
  • Combobox.Description: 콤보박스에 대한 자세한 정보를 사용자에게 알려주는 설명이에요.
  • Combobox.ErrorMessage: 콤보박스의 유효성 검사 오류를 해결하는 방법을 사용자에게 알려주는 오류 메시지예요.
  • Combobox.Control: 콤보박스 입력과 트리거를 포함해요.
  • Combobox.Input: 콤보박스 옵션을 필터링하고 선택된 값을 반영하는 입력 요소예요.
  • Combobox.Trigger: 콤보박스를 여는 버튼이에요.
  • Combobox.Icon: 입력 옆에 자주 표시되며 열릴 수 있다는 시각적 단서를 주는 작은 아이콘이에요.
  • Combobox.Portal: 콤보박스가 열렸을 때 자식들을 body로 포털(portal)해요.
  • Combobox.Content: 콤보박스가 열렸을 때 렌더링될 콘텐츠를 포함해요.
  • Combobox.Arrow: 콤보박스 콘텐츠 옆에 렌더링할 선택적 화살표 요소예요.
  • Combobox.Listbox: 항목 목록을 포함하고 사용자가 그중 하나 이상을 선택할 수 있게 해요.
  • Combobox.Section: 옵션 그룹의 라벨을 렌더링하는 데 사용돼요. 화살표 키로 포커스할 수 없어요.
  • Combobox.Item: 콤보박스의 항목이에요.
  • Combobox.ItemLabel: 항목에 대해 공지될 접근 가능한 라벨이에요.
  • Combobox.ItemDescription: 항목에 대해 공지될 선택적 접근 가능한 설명이에요.
  • Combobox.ItemIndicator: 항목이 선택됐을 때 렌더링되는 시각적 표시예요.
<Combobox>
	<Combobox.Label />
	<Combobox.Control>
		<Combobox.Input />
		<Combobox.Trigger>
			<Combobox.Icon />
		</Combobox.Trigger>
	</Combobox.Control>
	<Combobox.Description />
	<Combobox.ErrorMessage />

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

예제 (Example)

기본 예제는 공식 문서 페이지에서 확인할 수 있어요.

사용법 (Usage)

옵션 필터링 (Filtering options)

defaultFilter prop을 사용해 Combobox가 옵션 목록을 필터링하는 방식을 커스터마이즈할 수 있어요.

편의를 위해, 로컬 감각(locale-sensitive) 매칭을 지원하는 부분 문자열(substring) 매칭 기반의 내장 필터링 메커니즘 3가지를 제공해요. 앱이 설정한 현재 로케일(브라우저 기본 언어 또는 I18nProvider를 통한 로케일)을 자동으로 사용해요.

  • startsWith: 입력 값으로 시작하는 옵션을 보여줘요.
  • endsWith: 입력 값으로 끝나는 옵션을 보여줘요.
  • contains: 입력 값을 포함하는 옵션을 보여줘요.

defaultFilter prop에 사용자 정의 필터 함수를 전달할 수도 있어요. 이 함수는 _옵션과 입력 값_을 매개변수로 받고 boolean을 반환해야 해요.

import { Combobox } from "@kobalte/core/combobox";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

function FilteringExample() {
	return (
		<Combobox options={ALL_OPTIONS} defaultFilter="startsWith">
			//...rest of the component.
		</Combobox>
	);
}

기본값 (Default value)

비제어 상태의 초기값은 defaultValue prop으로 제공할 수 있어요. 이 값은 options에 대응하는 값을 받아요.

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

function DefaultValueExample() {
	return (
		<Combobox
			defaultValue="Blueberry"
			options={ALL_OPTIONS}
			placeholder="Search a fruit…"
			itemComponent={props => (
				<Combobox.Item item={props.item}>
					<Combobox.ItemLabel>{props.item.rawValue}</Combobox.ItemLabel>
					<Combobox.ItemIndicator>
						<CheckIcon />
					</Combobox.ItemIndicator>
				</Combobox.Item>
			)}
		>
			<Combobox.Control aria-label="Fruit">
				<Combobox.Input />
				<Combobox.Trigger>
					<Combobox.Icon>
						<CaretSortIcon />
					</Combobox.Icon>
				</Combobox.Trigger>
			</Combobox.Control>
			<Combobox.Portal>
				<Combobox.Content>
					<Combobox.Listbox />
				</Combobox.Content>
			</Combobox.Portal>
		</Combobox>
	);
}

제어값 (Controlled value)

options prop에 대응하는 값을 받는 value prop을 사용해 값을 제어할 수 있어요. 사용자가 옵션을 선택하면 onChange 이벤트가 발생하며 선택된 옵션을 받아요.

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";
import { createSignal } from "solid-js";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

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

	const onInputChange = (value: string) => {
		// Remove selection when input is cleared.
		if (value === "") {
			setValue("");
		}
	};

	return (
		<>
			<Combobox
				options={ALL_OPTIONS}
				value={value()}
				onChange={setValue}
				onInputChange={onInputChange}
				placeholder="Search a fruit…"
				itemComponent={props => (
					<Combobox.Item item={props.item}>
						<Combobox.ItemLabel>{props.item.rawValue}</Combobox.ItemLabel>
						<Combobox.ItemIndicator>
							<CheckIcon />
						</Combobox.ItemIndicator>
					</Combobox.Item>
				)}
			>
				<Combobox.Control aria-label="Fruit">
					<Combobox.Input />
					<Combobox.Trigger>
						<Combobox.Icon>
							<CaretSortIcon />
						</Combobox.Icon>
					</Combobox.Trigger>
				</Combobox.Control>
				<Combobox.Portal>
					<Combobox.Content>
						<Combobox.Listbox />
					</Combobox.Content>
				</Combobox.Portal>
			</Combobox>
			<p>Your favorite fruit is: {value()}.</p>
		</>
	);
}

설명 (Description)

Combobox.Description 컴포넌트를 사용해 콤보박스에 추가 도움말 텍스트를 연결할 수 있어요.

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

function DescriptionExample() {
	return (
		<Combobox
			options={ALL_OPTIONS}
			placeholder="Search a fruit…"
			itemComponent={props => (
				<Combobox.Item item={props.item}>
					<Combobox.ItemLabel>{props.item.rawValue}</Combobox.ItemLabel>
					<Combobox.ItemIndicator>
						<CheckIcon />
					</Combobox.ItemIndicator>
				</Combobox.Item>
			)}
		>
			<Combobox.Control aria-label="Fruit">
				<Combobox.Input />
				<Combobox.Trigger>
					<Combobox.Icon>
						<CaretSortIcon />
					</Combobox.Icon>
				</Combobox.Trigger>
			</Combobox.Control>
			<Combobox.Description>Choose the fruit you like the most.</Combobox.Description>
			<Combobox.Portal>
				<Combobox.Content>
					<Combobox.Listbox />
				</Combobox.Content>
			</Combobox.Portal>
		</Combobox>
	);
}

오류 메시지 (Error message)

Combobox.ErrorMessage 컴포넌트를 사용해 사용자가 유효성 검사 오류를 해결하도록 도울 수 있어요. 보조 기술에 콤보박스를 의미상 유효하지 않은 상태로 표시하려면 validationState prop과 함께 사용해야 해요.

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

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";
import { createSignal } from "solid-js";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

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

	const onInputChange = (value: string) => {
		// Remove selection when input is cleared.
		if (value === "") {
			setValue("");
		}
	};

	return (
		<Combobox
			options={ALL_OPTIONS}
			value={value()}
			onChange={setValue}
			onInputChange={onInputChange}
			validationState={value() !== "Apple" ? "invalid" : "valid"}
			placeholder="Search a fruit…"
			itemComponent={props => (
				<Combobox.Item item={props.item}>
					<Combobox.ItemLabel>{props.item.rawValue}</Combobox.ItemLabel>
					<Combobox.ItemIndicator>
						<CheckIcon />
					</Combobox.ItemIndicator>
				</Combobox.Item>
			)}
		>
			<Combobox.Control aria-label="Fruit">
				<Combobox.Input />
				<Combobox.Trigger>
					<Combobox.Icon>
						<CaretSortIcon />
					</Combobox.Icon>
				</Combobox.Trigger>
			</Combobox.Control>
			<Combobox.ErrorMessage>Hmm, I prefer apples.</Combobox.ErrorMessage>
			<Combobox.Portal>
				<Combobox.Content>
					<Combobox.Listbox />
				</Combobox.Content>
			</Combobox.Portal>
		</Combobox>
	);
}

HTML 폼 (HTML forms)

콤보박스의 name prop을 Combobox.HiddenSelect 컴포넌트와 함께 사용해 HTML 폼과 통합할 수 있어요.

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

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

	return (
		<form onSubmit={onSubmit}>
			<Combobox
				name="fruit"
				options={ALL_OPTIONS}
				placeholder="Search a fruit…"
				itemComponent={props => (
					<Combobox.Item item={props.item}>
						<Combobox.ItemLabel>{props.item.rawValue}</Combobox.ItemLabel>
						<Combobox.ItemIndicator>
							<CheckIcon />
						</Combobox.ItemIndicator>
					</Combobox.Item>
				)}
			>
				<Combobox.HiddenSelect />
				<Combobox.Control aria-label="Fruit">
					<Combobox.Input />
					<Combobox.Trigger>
						<Combobox.Icon>
							<CaretSortIcon />
						</Combobox.Icon>
					</Combobox.Trigger>
				</Combobox.Control>
				<Combobox.Portal>
					<Combobox.Content>
						<Combobox.Listbox />
					</Combobox.Content>
				</Combobox.Portal>
			</Combobox>
			<div>
				<button type="reset">Reset</button>
				<button>Submit</button>
			</div>
		</form>
	);
}

옵션으로 객체 사용 (Using object as options)

문자열 대신 객체를 옵션으로 사용할 수 있어요. 이 경우 제공된 옵션을 어떻게 다룰지 콤보박스에 알려줘야 해요. 이를 위해 다음 prop들을 반드시 사용해야 해요.

  • optionValue: 옵션의 값으로 사용할 속성 이름이에요 (<form>과 함께 제출됨).
  • optionTextValue: 필터링과 키보드 탐색에 사용할 옵션의 텍스트 값으로 쓸 속성 이름이에요.
  • optionLabel: 콤보박스 입력에 표시되는 옵션의 라벨로 사용할 속성 이름이에요.
  • optionDisabled: 옵션의 비활성 플래그로 사용할 속성 이름이에요.
import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";

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

const ALL_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 (
		<Combobox
			options={ALL_OPTIONS}
			optionValue="value"
			optionTextValue="label"
			optionLabel="label"
			optionDisabled="disabled"
			placeholder="Search a fruit…"
			itemComponent={props => (
				<Combobox.Item item={props.item}>
					<Combobox.ItemLabel>{props.item.rawValue.label}</Combobox.ItemLabel>
					<Combobox.ItemIndicator>
						<CheckIcon />
					</Combobox.ItemIndicator>
				</Combobox.Item>
			)}
		>
			<Combobox.Control aria-label="Fruit">
				<Combobox.Input />
				<Combobox.Trigger>
					<Combobox.Icon>
						<CaretSortIcon />
					</Combobox.Icon>
				</Combobox.Trigger>
			</Combobox.Control>
			<Combobox.Portal>
				<Combobox.Content>
					<Combobox.Listbox />
				</Combobox.Content>
			</Combobox.Portal>
		</Combobox>
	);
}

옵션 그룹 사용 (Using option groups)

옵션 그룹을 사용할 때는 옵션과 그룹을 구분하는 방법을 콤보박스에 알려줘야 해요. 이를 위해 다음 prop을 반드시 사용해야 해요.

  • optionGroupChildren: 옵션 그룹의 자식 옵션들을 가리키는 속성 이름이에요.

추가로 sectionComponent prop이 콤보박스에 옵션 그룹 라벨을 표시하는 데 사용돼요.

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";

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

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

const ALL_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 },
		],
	},
];

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

참고: 올바른 TypeScript 지원을 위해 Combobox에서 제네릭(사용)을 확인하세요.

다중 선택 (Multiple selection)

multiple prop을 사용해 다중 선택을 허용하는 콤보박스를 만들 수 있어요. 이 경우 value, defaultValue, onChange prop에 제공되는 값의 타입은 Array<T>예요.

이 경우 Combobox.Input은 값을 표시할 수 없어요. 대신 Combobox.Control 자식 _render prop_이 선택된 옵션 배열과, 선택에서 옵션을 제거하고 선택을 비우는 두 메서드를 노출해요.

import { Combobox } from "@kobalte/core/combobox";
import { CaretSortIcon, CheckIcon } from "some-icon-library";
import { createSignal } from "solid-js";

const ALL_OPTIONS = ["Apple", "Banana", "Blueberry", "Grapes", "Pineapple"];

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

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

원점 인식 애니메이션 (Origin-aware animations)

CSS 사용자 정의 속성 --kb-combobox-content-transform-origin을 노출해서 콘텐츠를 계산된 원점에서 애니메이션할 수 있어요.

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

.combobox__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 참조 (API Reference)

Combobox

Combobox는 @kobalte/core/combobox의 Root 임포트(그리고 더 이상 사용되지 않는 Combobox.Root)와 동일해요.

Prop Description
defaultFilter "startsWith" | "endsWith" | "contains" | ((option: Option, inputValue: string) => boolean)
The filter function used to determine if an option should be included in the combo box list.
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 combobox 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.
optionLabel keyof T | ((option: T) => string)
Property name or getter function to use as the label of an option. This is the string representation of the option to display in the Combobox.Input.
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<ComboboxItemComponentProps<T>>
When NOT virtualized, the component to render as an item in the Combobox.Listbox.
sectionComponent Component<ComboboxSectionComponentProps<U>>
When NOT virtualized, the component to render as a section in the Combobox.Listbox.
multiple boolean
Whether the combobox 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 combobox.
defaultValue T | Array<T>
The value of the combobox 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 combobox.
defaultOpen boolean
The default open state when initially rendered. Useful when you do not need to control the open state.
onOpenChange (open: boolean, triggerMode?: ComboboxTriggerMode) => void
Event handler called when the open state of the combobox changes. Returns the new open state and the action that caused the opening of the menu.
onInputChange (value: string) => void
Handler that is called when the combobox input value changes.
triggerMode ComboboxTriggerMode
The interaction required to display the combobox menu, it can be one of the following:
- input: open the combobox menu when the user is typing.
- focus: open the combobox menu when the input is focused.
- manual: open the combobox menu when pressing arrow down/up while focus is on the input or clicking on the trigger.
removeOnBackspace boolean
When multiple is true, whether the last selected option should be removed when the user press the Backspace key and the input is empty.
allowDuplicateSelectionEvents boolean
Whether onChange should fire even if the new value is the same as the last.
disallowEmptySelection boolean
Whether the combobox allows empty selection or not.
allowsEmptyCollection boolean
Whether the combobox allows the menu to be open when the collection is empty.
closeOnSelection boolean
Whether the combobox closes after selection.
selectionBehavior 'toggle' | 'replace'
How selection should behave in the combobox.
virtualized boolean
Whether the combobox uses virtual scrolling.
modal boolean
Whether the combobox 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 combobox content.
- elements outside the combobox content will not be visible for screen readers.
preventScroll boolean
Whether the scroll should be locked even if the combobox is not modal.
forceMount boolean
Used to force mounting the combobox (portal, positioner and content) when more control is needed. Useful when controlling animation with SolidJS animation libraries.
name string
The name of the combobox. Submitted with its owning form as part of a name/value pair.
validationState 'valid' | 'invalid'
Whether the combobox 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 combobox is disabled.
readOnly boolean
Whether the combobox 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
translations ComboboxIntlTranslations
Localization strings.
noResetInputOnBlur boolean
Prevents input reset on combobox blur when content is displayed.

Combobox는 Combobox.Content의 배치를 커스터마이즈하기 위한 다음 prop들도 받아요.

Prop Description
placement Placement
The placement of the combobox content.
gutter number
The distance between the combobox content and the trigger element.
shift number
The skidding of the combobox content along the trigger element.
flip boolean | string
Controls the behavior of the combobox content when it overflows the viewport:
- If a boolean, specifies whether the combobox 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 combobox content should slide when it overflows.
overlap boolean
Whether the combobox content can overlap the trigger element when it overflows.
sameWidth boolean
Whether the combobox 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 combobox content should fit the viewport. If this is set to true, the combobox 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 combobox 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 combobox content corner.
overflowPadding number
The minimum padding between the combobox content and the viewport edge. This will be exposed to CSS as --kb-popper-overflow-padding.
Data attribute Description
data-valid Present when the combobox is valid according to the validation rules.
data-invalid Present when the combobox 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 combobox is disabled.
data-readonly Present when the combobox is read only.

Combobox.Label, Combobox.Control, Combobox.Input, Combobox.Trigger, Combobox.Description 및 Combobox.ErrorMessage는 동일한 data-attributes를 공유해요.

Combobox.Control

Render Prop Description
selectedOptions Accessor<T[]>
An array of selected options.
remove (option: T) => void
A function to remove an option from the selection.
clear () => void
A function to clear the selection.

Combobox.Trigger

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

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

Combobox.Icon

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

Combobox.ErrorMessage

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

Combobox.Content

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

Combobox.Arrow

Prop Description
size number
The size of the arrow.

Combobox.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.

Combobox.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.

Combobox.ItemLabel, Combobox.ItemDescription 및 Combobox.ItemIndicator는 동일한 data-attributes를 공유해요.

Combobox.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
Combobox div
Combobox.Label span
Combobox.Description div
Combobox.ErrorMessage div
Combobox.Control div
Combobox.Input input
Combobox.Trigger button
Combobox.Icon span
Combobox.Portal Portal
Combobox.Content div
Combobox.Arrow div
Combobox.Listbox ul
Combobox.Section li
Combobox.Item li
Combobox.ItemLabel div
Combobox.ItemDescription div
Combobox.ItemIndicator div

접근성 (Accessibility)

키보드 상호작용 (Keyboard Interactions)

Key Description
Enter When focus is virtually on an item, selects the focused item.
ArrowDown When focus is on the input, opens the combobox and virtual focuses the first or selected item.
When focus is virtually on an item, moves virtual focus to the next item.
ArrowUp When focus is on the input, opens the combobox and virtual focuses the last or selected item.
When focus is virtually on an item, moves virtual focus to the previous item.
Alt + ArrowDown When focus is on the input, opens the combobox.
Alt + ArrowUp When focus is on the input, closes the combobox.
Home When focus is on the input, moves virtual focus to first item.
End When focus is on the input, moves virtual focus to last item.
Esc When the combobox is open, closes the combobox.
When the combobox is closed, clear the input and selection unless noResetInputOnBlur is set to true.

더 알아보기 (Learn more)