Listbox — 목록에서 단일·다중 항목 선택
목록에서 단일 또는 여러 항목을 선택하는 컴포넌트예요. 그룹화, 확장 선택, 그리드 레이아웃, 필터링 같은 다양한 선택 시나리오를 지원해요.
출처: 문서
본문
구조 (Anatomy)
{/* */}
<Listbox.Root>
<Listbox.Label />
<Listbox.Content>
<Listbox.ItemGroup>
<Listbox.ItemGroupLabel />
<Listbox.Item>
<Listbox.ItemText />
<Listbox.ItemIndicator />
</Listbox.Item>
</Listbox.ItemGroup>
</Listbox.Content>
<Listbox.ValueText />
</Listbox.Root>
예제 (Examples)
기본 (Basic)
Listbox 컴포넌트의 기본 예제예요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Basic = () => {
const collection = createListCollection({
items: [
{ label: 'United States', value: 'us' },
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Canada', value: 'ca' },
{ label: 'Australia', value: 'au' },
{ label: 'Germany', value: 'de' },
{ label: 'France', value: 'fr' },
{ label: 'Japan', value: 'jp' },
],
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Select Country</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
제어 (Controlled)
Listbox 컴포넌트는 value와 onValueChange 프롭을 사용해 제어할 수 있어요. 선택된 값을 외부에서 관리할 수 있게 해 줘요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/listbox.module.css'
export const Controlled = () => {
const collection = createListCollection({
items: [
{ label: 'Small', value: 'sm' },
{ label: 'Medium', value: 'md' },
{ label: 'Large', value: 'lg' },
{ label: 'Extra Large', value: 'xl' },
],
})
const [value, setValue] = useState(['md'])
return (
<Listbox.Root
className={styles.Root}
collection={collection}
value={value}
onValueChange={(e) => setValue(e.value)}
>
<Listbox.Label className={styles.Label}>Select Size</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
루트 프로바이더 (Root Provider)
다른 방식으로 listbox를 제어하려면 RootProvider 컴포넌트와 useListbox 훅을 사용할 수 있어요. 이렇게 하면 컴포넌트 밖에서도 상태와 메서드에 접근할 수 있어요.
import { Listbox, createListCollection, useListbox } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import button from 'styles/button.module.css'
import styles from 'styles/listbox.module.css'
export const RootProvider = () => {
const collection = createListCollection({
items: [
{ label: 'Low', value: 'low' },
{ label: 'Medium', value: 'medium' },
{ label: 'High', value: 'high' },
{ label: 'Critical', value: 'critical' },
],
})
const listbox = useListbox({ collection })
return (
<div className="stack">
<button className={button.Root} onClick={() => listbox.setValue(['high'])}>
Set to High
</button>
<Listbox.RootProvider className={styles.Root} value={listbox}>
<Listbox.Label className={styles.Label}>Select Priority</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.RootProvider>
</div>
)
}
비활성화된 항목 (Disabled Item)
Listbox 항목은 컬렉션 항목의 disabled 프롭을 사용해 비활성화할 수 있어요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const DisabledItem = () => {
const collection = createListCollection({
items: [
{ label: 'Free', value: 'free' },
{ label: 'Pro', value: 'pro' },
{ label: 'Enterprise', value: 'enterprise', disabled: true },
{ label: 'Custom', value: 'custom' },
],
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Select Plan</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
createListCollection안에서isItemDisabled를 사용해 조건에 따라 항목을 비활성화할 수도 있어요.
다중 선택 (Multiple)
selectionMode 속성을 multiple로 설정하면 사용자가 한 번에 여러 항목을 선택할 수 있어요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Multiple = () => {
const collection = createListCollection({
items: [
{ label: 'Monday', value: 'mon' },
{ label: 'Tuesday', value: 'tue' },
{ label: 'Wednesday', value: 'wed' },
{ label: 'Thursday', value: 'thu' },
{ label: 'Friday', value: 'fri' },
{ label: 'Saturday', value: 'sat' },
{ label: 'Sunday', value: 'sun' },
],
})
return (
<Listbox.Root className={styles.Root} collection={collection} selectionMode="multiple">
<Listbox.Label className={styles.Label}>Select Days</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
그룹화 (Grouping)
Listbox 컴포넌트는 항목 그룹화를 지원해요. groupBy 함수를 사용해 특정 속성을 기준으로 항목을 그룹화할 수 있어요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Group = () => {
const collection = createListCollection({
items: [
{ label: 'New York', value: 'nyc', region: 'North America' },
{ label: 'Los Angeles', value: 'lax', region: 'North America' },
{ label: 'Toronto', value: 'yyz', region: 'North America' },
{ label: 'London', value: 'lhr', region: 'Europe' },
{ label: 'Paris', value: 'cdg', region: 'Europe' },
{ label: 'Berlin', value: 'ber', region: 'Europe' },
{ label: 'Tokyo', value: 'nrt', region: 'Asia Pacific' },
{ label: 'Singapore', value: 'sin', region: 'Asia Pacific' },
{ label: 'Sydney', value: 'syd', region: 'Asia Pacific' },
],
groupBy: (item) => item.region,
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Select Region</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.group().map(([region, items]) => (
<Listbox.ItemGroup className={styles.ItemGroup} key={region}>
<Listbox.ItemGroupLabel className={styles.ItemGroupLabel}>{region}</Listbox.ItemGroupLabel>
{items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.ItemGroup>
))}
</Listbox.Content>
</Listbox.Root>
)
}
확장 선택 (Extended Selection)
확장 선택 모드에서는 Cmd(Mac) 또는 Ctrl(Windows/Linux) 같은 키보드 수정자를 사용해 여러 항목을 선택할 수 있어요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const ExtendedSelect = () => {
const collection = createListCollection({
items: [
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
{ label: 'Angular', value: 'angular' },
{ label: 'Svelte', value: 'svelte' },
{ label: 'Solid', value: 'solid' },
{ label: 'Preact', value: 'preact' },
],
})
return (
<Listbox.Root className={styles.Root} collection={collection} selectionMode="extended">
<Listbox.Label className={styles.Label}>
Hold <kbd>⌘</kbd> or <kbd>Ctrl</kbd> to select multiple
</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
가로 (Horizontal)
orientation 프롭을 사용해 listbox 항목을 가로로 표시할 수 있어요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const Horizontal = () => {
const collection = createListCollection({
items: [
{
title: 'Midnight Dreams',
artist: 'Luna Ray',
image: 'https://picsum.photos/seed/album1/300/300',
},
{
title: 'Neon Skyline',
artist: 'The Electric',
image: 'https://picsum.photos/seed/album2/300/300',
},
{
title: 'Acoustic Sessions',
artist: 'Sarah Woods',
image: 'https://picsum.photos/seed/album3/300/300',
},
{
title: 'Urban Echoes',
artist: 'Metro Collective',
image: 'https://picsum.photos/seed/album4/300/300',
},
{
title: 'Summer Vibes',
artist: 'Coastal Waves',
image: 'https://picsum.photos/seed/album5/300/300',
},
],
itemToValue: (item) => item.title,
itemToString: (item) => item.title,
})
return (
<Listbox.Root className={styles.Root} collection={collection} orientation="horizontal">
<Listbox.Label className={styles.Label}>Select Album</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.ItemCard} key={item.title} item={item}>
<Listbox.ItemIndicator className={styles.ItemCardIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
<img className={styles.ItemCardImage} src={item.image} alt={item.title} />
<span className={styles.ItemCardTitle}>{item.title}</span>
<span className={styles.ItemCardArtist}>{item.artist}</span>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
그리드 레이아웃 (Grid Layout)
createGridCollection을 사용하면 키보드 내비게이션을 지원하는 그리드 레이아웃으로 항목을 표시할 수 있어요.
import { createGridCollection } from '@ark-ui/react/collection'
import { Listbox } from '@ark-ui/react/listbox'
import styles from 'styles/listbox.module.css'
export const Grid = () => {
const collection = createGridCollection({
items: [
{ label: '😀', value: 'grinning' },
{ label: '😍', value: 'heart-eyes' },
{ label: '🥳', value: 'partying' },
{ label: '😎', value: 'sunglasses' },
{ label: '🤩', value: 'star-struck' },
{ label: '😂', value: 'joy' },
{ label: '🥰', value: 'smiling-hearts' },
{ label: '😊', value: 'blush' },
{ label: '🤗', value: 'hugging' },
{ label: '😇', value: 'innocent' },
{ label: '🔥', value: 'fire' },
{ label: '✨', value: 'sparkles' },
{ label: '💯', value: 'hundred' },
{ label: '🎉', value: 'tada' },
{ label: '❤️', value: 'heart' },
{ label: '👍', value: 'thumbs-up' },
{ label: '👏', value: 'clap' },
{ label: '🚀', value: 'rocket' },
{ label: '⭐', value: 'star' },
{ label: '🌈', value: 'rainbow' },
],
columnCount: 5,
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Pick a reaction</Listbox.Label>
<Listbox.Content className={styles.GridContent}>
{collection.items.map((item) => (
<Listbox.Item className={styles.GridItem} key={item.value} item={item}>
<Listbox.ItemText>{item.label}</Listbox.ItemText>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
필터링 (Filtering)
useListCollection과 filter 함수를 사용해 항목 필터링을 활성화할 수 있어요.
import { useListCollection } from '@ark-ui/react/collection'
import { Listbox } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import field from 'styles/field.module.css'
import styles from 'styles/listbox.module.css'
export const Filtering = () => {
const { collection, filter } = useListCollection({
initialItems: [
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
{ label: 'Angular', value: 'angular' },
{ label: 'Svelte', value: 'svelte' },
{ label: 'Solid', value: 'solid' },
{ label: 'Next.js', value: 'nextjs' },
{ label: 'Nuxt.js', value: 'nuxtjs' },
{ label: 'Remix', value: 'remix' },
{ label: 'Gatsby', value: 'gatsby' },
{ label: 'Preact', value: 'preact' },
],
filter: (itemText, filterText) => itemText.toLowerCase().includes(filterText.toLowerCase()),
})
return (
<Listbox.Root className={styles.Root} collection={collection}>
<Listbox.Label className={styles.Label}>Select Framework</Listbox.Label>
<Listbox.Input
className={field.Input}
placeholder="Search frameworks..."
onChange={(e) => filter(e.target.value)}
/>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
<Listbox.Empty className={styles.Empty}>No frameworks found</Listbox.Empty>
</Listbox.Content>
</Listbox.Root>
)
}
전체 선택 (Select All)
useListboxContext를 사용해 모든 항목을 한 번에 선택하거나 해제하는 "전체 선택" 기능을 구현할 수 있어요.
import { Listbox, createListCollection, useListboxContext } from '@ark-ui/react/listbox'
import { CheckIcon, MinusIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
const frameworks = createListCollection({
items: [
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
{ label: 'Angular', value: 'angular' },
{ label: 'Svelte', value: 'svelte' },
{ label: 'Next.js', value: 'nextjs' },
{ label: 'Nuxt.js', value: 'nuxtjs' },
{ label: 'Remix', value: 'remix' },
{ label: 'Gatsby', value: 'gatsby' },
],
})
const SelectAllHeader = () => {
const listbox = useListboxContext()
const isAllSelected = listbox.value.length === frameworks.items.length
const isSomeSelected = listbox.value.length > 0 && listbox.value.length < frameworks.items.length
const handleSelectAll = () => {
if (isAllSelected) {
listbox.setValue([])
} else {
listbox.setValue(frameworks.items.map((item) => item.value))
}
}
return (
<button className={styles.SelectAllHeader} type="button" onClick={handleSelectAll}>
<span className={styles.SelectAllHeaderIndicator}>
{isAllSelected ? <CheckIcon /> : isSomeSelected ? <MinusIcon /> : null}
</span>
<span className={styles.Label}>Select All</span>
</button>
)
}
export const SelectAll = () => {
return (
<Listbox.Root className={styles.Root} collection={frameworks} selectionMode="multiple">
<SelectAllHeader />
<Listbox.Content className={styles.Content}>
{frameworks.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
값 텍스트 (Value Text)
Listbox.ValueText를 사용해 선택된 값을 쉼표로 구분된 문자열로 표시할 수 있어요.
import { Listbox, createListCollection } from '@ark-ui/react/listbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/listbox.module.css'
export const ValueText = () => {
const collection = createListCollection({
items: [
{ label: 'Red', value: 'red' },
{ label: 'Blue', value: 'blue' },
{ label: 'Green', value: 'green' },
{ label: 'Yellow', value: 'yellow' },
{ label: 'Purple', value: 'purple' },
],
})
return (
<Listbox.Root
className={styles.Root}
collection={collection}
selectionMode="multiple"
defaultValue={['red', 'blue']}
>
<Listbox.Label className={styles.Label}>
Colors: <Listbox.ValueText className={styles.ValueText} />
</Listbox.Label>
<Listbox.Content className={styles.Content}>
{collection.items.map((item) => (
<Listbox.Item className={styles.Item} key={item.value} item={item}>
<Listbox.ItemText className={styles.ItemText}>{item.label}</Listbox.ItemText>
<Listbox.ItemIndicator className={styles.ItemIndicator}>
<CheckIcon />
</Listbox.ItemIndicator>
</Listbox.Item>
))}
</Listbox.Content>
</Listbox.Root>
)
}
가이드 (Guides)
타입 안전성 (Type Safety)
Listbox.RootComponent 타입을 사용하면 컬렉션 항목에 대한 완전한 타입 안전성을 유지하는 타입화된 래퍼 컴포넌트를 만들 수 있어요.
const Listbox: ArkListbox.RootComponent = (props) => {
return <ArkListbox.Root {...props}>{/* ... */}</ArkListbox.Root>
}
onValueChange 및 다른 콜백에서 완전한 타입 추론과 함께 래퍼를 사용하세요:
const App = () => {
const collection = createListCollection({
initialItems: [
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
],
})
return (
<Listbox
collection={collection}
onValueChange={(e) => {
// e.items is typed as Array<{ label: string, value: string }>
console.log(e.items)
}}
>
{/* ... */}
</Listbox>
)
}
API 참조 (API Reference)
프롭 (Props)
Root
프롭 (Props)
collection
Type: ListCollection<T>
Required: true
Default Value: undefined
Description: 항목 컬렉션이에요.
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
defaultHighlightedValue
Type: string
Required: false
Default Value: undefined
Description: 열렸을 때 하이라이트된 항목의 초기 값이에요.
listbox의 하이라이트 값을 제어할 필요가 없을 때 사용해요.
defaultValue
Type: string[]
Required: false
Default Value: []
Description: 렌더링될 때 listbox의 초기 기본 값이에요.
listbox의 값을 제어할 필요가 없을 때 사용해요.
deselectable
Type: boolean
Required: false
Default Value: undefined
Description: 빈 선택을 허용하지 않을지 여부예요.
disabled
Type: boolean
Required: false
Default Value: undefined
Description: listbox가 비활성화되었는지 여부예요.
disallowSelectAll
Type: boolean
Required: false
Default Value: undefined
Description: meta+a를 눌렀을 때 모든 항목 선택을 허용하지 않을지 여부예요.
highlightedValue
Type: string
Required: false
Default Value: undefined
Description: 하이라이트된 항목의 제어된 키예요.
id
Type: string
Required: false
Default Value: undefined
Description: 머신의 고유 식별자예요.
ids
Type: Partial<{ root: string content: string label: string item: (id: string | number) => string itemGroup: (id: string | number) => string itemGroupLabel: (id: string | number) => string }>
Required: false
Default Value: undefined
Description: listbox에 있는 요소들의 id예요. 합성(composition)에 유용해요.
loopFocus
Type: boolean
Required: false
Default Value: false
Description: 옵션들을 키보드 내비게이션으로 순환(loop)할지 여부예요.
onHighlightChange
Type: (details: HighlightChangeDetails<T>) => void
Required: false
Default Value: undefined
Description: 하이라이트된 항목이 변경될 때 호출되는 콜백이에요.
onSelect
Type: (details: SelectionDetails) => void
Required: false
Default Value: undefined
Description: 항목이 선택될 때 호출되는 함수예요.
onValueChange
Type: (details: ValueChangeDetails<T>) => void
Required: false
Default Value: undefined
Description: 선택된 항목이 변경될 때 호출되는 콜백이에요.
orientation
Type: 'horizontal' | 'vertical'
Required: false
Default Value: "vertical"
Description: listbox의 방향이에요.
scrollToIndexFn
Type: (details: ScrollToIndexDetails) => void
Required: false
Default Value: undefined
Description: 특정 인덱스로 스크롤하는 함수예요.
selectionMode
Type: SelectionMode
Required: false
Default Value: "single"
Description: listbox에서 다중 선택이 어떻게 동작해야 하는지예요.
single: 사용자가 단일 항목을 선택할 수 있어요.multiple: 수정자 키 없이 여러 항목을 선택할 수 있어요.extended: 수정자 키를 사용해 여러 항목을 선택할 수 있어요.
selectOnHighlight
Type: boolean
Required: false
Default Value: undefined
Description: 항목이 하이라이트될 때 선택할지 여부예요.
typeahead
Type: boolean
Required: false
Default Value: undefined
Description: listbox에서 타입어헤드를 활성화할지 여부예요.
value
Type: string[]
Required: false
Default Value: undefined
Description: 선택된 항목들의 제어된 키예요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: root
data-orientation: listbox의 방향
data-disabled: 비활성화될 때 존재
Content
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: content
data-activedescendant: 콘텐츠의 활성 하위 요소(active descendant) id
data-orientation: 콘텐츠의 방향
data-layout:
data-empty: 콘텐츠가 비어 있을 때 존재
Empty
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
Input
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
autoHighlight
Type: boolean
Required: false
Default Value: false
Description: 입력할 때 항목을 자동으로 하이라이트할지 여부예요.
keyboardPriority
Type: 'caret' | 'navigate'
Required: false
Default Value: "caret"
Description: input에서 키보드 충돌을 해결하는 방법을 결정해요.
- "caret": 네이티브 텍스트 편집 동작을 유지해요
- "navigate": 지원되는 키를 listbox 내비게이션으로 전달해요
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: input
data-disabled: 비활성화될 때 존재
ItemGroupLabel
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
ItemGroup
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: item-group
data-disabled: 비활성화될 때 존재
data-orientation: 항목의 방향
data-empty: 콘텐츠가 비어 있을 때 존재
ItemIndicator
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: item-indicator
data-state: "checked" | "unchecked"
Item
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
highlightOnHover
Type: boolean
Required: false
Default Value: undefined
Description: hover 시 항목을 하이라이트할지 여부예요.
item
Type: any
Required: false
Default Value: undefined
Description: 렌더링할 항목이에요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: item
data-value: 항목의 값
data-selected: 선택되었을 때 존재
data-layout:
data-state: "checked" | "unchecked"
data-orientation: 항목의 방향
data-highlighted: 하이라이트되었을 때 존재
data-disabled: 비활성화될 때 존재
ItemText
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: item-text
data-state: "checked" | "unchecked"
data-disabled: 비활성화될 때 존재
data-highlighted: 하이라이트되었을 때 존재
Label
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: label
data-disabled: 비활성화될 때 존재
RootProvider
프롭 (Props)
value
Type: UseListboxReturn<T>
Required: true
Default Value: undefined
Description: undefined
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
ValueText
프롭 (Props)
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 프롭과 동작을 결합해요.
placeholder
Type: string
Required: false
Default Value: undefined
Description: 값이 없을 때 표시할 텍스트예요.
데이터 속성 (Data Attributes)
data-scope: listbox
data-part: value-text
data-disabled: 비활성화될 때 존재
Context
API:
| Property | Type | Description |
|---|---|---|
empty |
boolean |
선택 값이 비어 있는지 여부 |
highlightedValue |
`string | null` |
highlightedItem |
`V | null` |
highlightValue |
(value: string) => void |
값을 하이라이트하는 함수 |
highlightFirst |
VoidFunction |
첫 번째 값을 하이라이트하는 함수 |
highlightLast |
VoidFunction |
마지막 값을 하이라이트하는 함수 |
highlightNext |
VoidFunction |
다음 값을 하이라이트하는 함수 |
highlightPrevious |
VoidFunction |
이전 값을 하이라이트하는 함수 |
clearHighlightedValue |
VoidFunction |
하이라이트된 값을 지우는 함수 |
selectedItems |
V[] |
선택된 항목들 |
hasSelectedItems |
boolean |
선택된 옵션이 있는지 여부 |
value |
string[] |
선택된 항목 키들 |
valueAsString |
string |
선택된 항목들의 문자열 표현 |
selectValue |
(value: string) => void |
값을 선택하는 함수 |
selectAll |
VoidFunction |
모든 값을 선택하는 함수. |
참고: 이 함수는 selectionMode가 multiple 또는 extended일 때만 호출해야 해요.
그렇지 않으면 예외가 발생해요. |
| setValue | (value: string[]) => void | select의 값을 설정하는 함수 |
| clearValue | (value?: string) => void | select의 값을 지우는 함수.
값이 제공되면 그 값만 지우고, 그렇지 않으면 모든 값을 지워요. |
| getItemState | (props: ItemProps) => ItemState | select 항목의 상태를 반환해요 |
| collection | ListCollection<V> | select를 토글하는 함수 |
| disabled | boolean | select가 비활성화되었는지 여부 |