컴포넌트
Combobox
검색할 수 있는 선택. 단일·다중.
import { useState } from 'react'
import { Combobox } from '@zest/primitives/Combobox.js'
import { Field } from '@zest/primitives/Field.js'
const depts = [{ value: 'hr', label: '경영지원' }, { value: 'dev', label: '개발' }, { value: 'ops', label: '개발운영' }, { value: 'design', label: '디자인' }, { value: 'biz', label: '사업개발' }]
export default function Demo() {
const [one, setOne] = useState<string>()
const [many, setMany] = useState<string[]>([])
return (
<div className="flex w-full max-w-[320px] flex-col gap-4">
<Field label="부서"><Combobox options={depts} value={one} onValueChange={setOne} placeholder="부서 선택" searchPlaceholder="부서 이름" /></Field>
<Field label="참조 부서"><Combobox multiple options={depts} value={many} onValueChange={setMany} placeholder="여러 개 선택" /></Field>
</div>
)
}설치
shadcn CLI 로 소스를 프로젝트에 가져와요. 테마·유틸·의존 부품이 함께 설치돼요.
npx shadcn@latest add @zest/combobox패키지로 쓰려면 @zest-im/ui 에서 가져와요. 설치 안내
사용법
import { Combobox } from '@/components/ui/combobox'위 미리보기의 「코드」 탭이 실제로 동작하는 예제예요.
API
| prop | 타입 | 설명 |
|---|---|---|
multiple? | boolean | — |
value? | string | string[] | — |
onValueChange | ((v: string) => void) | ((v: string[]) => void) | — |
options | SelectOption[] | — |
placeholder? | string | — |
searchPlaceholder? | string | — |
emptyText? | string | — |
disabled? | boolean | — |
id? | string | — |
className? | string | — |
aria-describedby? | string | — |
aria-invalid? | boolean | — |
aria-label? | string | — |
표에 없는 HTML·Radix 속성은 그대로 전달돼요.
접근성
선택된 항목은 「선택됨」으로 낭독한다.