Checkbox (체크박스)
체크박스는 한 세트 안에서 여러 항목을 동시에 선택할 수 있게 해주는 컨트롤 요소예요. 체크된 상태, 라벨, 숨겨진 입력 요소를 조합해서 접근성 좋은 폼 컨트롤을 만들 수 있어요.
출처: 문서
본문
구조 (Anatomy)
<Checkbox.Root>
<Checkbox.Control>
<Checkbox.Indicator />
</Checkbox.Control>
<Checkbox.Label />
<Checkbox.HiddenInput />
</Checkbox.Root>
예제 (Examples)
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const Basic = () => (
<Checkbox.Root className={styles.Root}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Checkbox</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
기본 체크 (Default Checked)
defaultChecked prop을 사용하면 비제어(uncontrolled) 방식으로 초기 체크 상태를 설정할 수 있어요. 이때 체크박스는 내부적으로 자체 상태를 관리해요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const DefaultChecked = () => (
<Checkbox.Root className={styles.Root} defaultChecked>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Checkbox</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
제어 (Controlled)
checked와 onCheckedChange prop을 사용하면 체크박스의 상태를 프로그래밍 방식으로 제어할 수 있어요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/checkbox.module.css'
export const Controlled = () => {
const [checked, setChecked] = useState<Checkbox.CheckedState>(true)
return (
<Checkbox.Root className={styles.Root} checked={checked} onCheckedChange={(e) => setChecked(e.checked)}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Checkbox</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
}
RootProvider
체크박스를 제어하는 또 다른 방법으로 RootProvider 컴포넌트와 useCheckbox 훅을 사용할 수 있어요. 이렇게 하면 컴포넌트 외부에서도 상태와 메서드에 접근할 수 있어요.
import { Checkbox, useCheckbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
import button from 'styles/button.module.css'
export const RootProvider = () => {
const checkbox = useCheckbox()
return (
<div className="vstack">
<Checkbox.RootProvider className={styles.Root} value={checkbox}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Checkbox</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.RootProvider>
{checkbox.checked ? (
<button type="button" onClick={() => checkbox.setChecked(false)} className={button.Root}>
Uncheck
</button>
) : (
<button type="button" onClick={() => checkbox.setChecked(true)} className={button.Root}>
Check
</button>
)}
</div>
)
}
비활성화 (Disabled)
disabled prop을 사용하면 체크박스를 상호작용할 수 없게 만들 수 있어요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const Disabled = () => (
<Checkbox.Root className={styles.Root} disabled>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Checkbox</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
불확정 (Indeterminate)
indeterminate prop을 사용하면 부분적으로 체크된 불확정 상태의 체크박스를 만들 수 있어요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon, MinusIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const Indeterminate = () => (
<Checkbox.Root className={styles.Root} checked="indeterminate">
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
<Checkbox.Indicator className={styles.Indicator} indeterminate>
<MinusIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Checkbox</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
Field
체크박스는 Field 컴포넌트와 자연스럽게 통합되어 폼 상태, 도움말 텍스트, 오류 텍스트를 처리해 접근성을 제대로 보장할 수 있어요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { Field } from '@ark-ui/react/field'
import { CheckIcon, MinusIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
import field from 'styles/field.module.css'
export const WithField = () => (
<Field.Root className={field.Root} data-inline>
<Checkbox.Root className={styles.Root}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
<Checkbox.Indicator className={styles.Indicator} indeterminate>
<MinusIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>Label</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
<Field.HelperText className={field.HelperText}>Additional Info</Field.HelperText>
<Field.ErrorText className={field.ErrorText}>Error Info</Field.ErrorText>
</Field.Root>
)
폼 (Form)
name과 value prop을 Checkbox.Root 컴포넌트에 전달하면 체크박스를 폼의 일부로 만들 수 있어요. 사용자가 폼을 제출하면 체크박스의 값도 함께 제출돼요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
import button from 'styles/button.module.css'
export const WithForm = () => (
<form
style={{ display: 'flex', flexDirection: 'column', gap: '1rem', alignItems: 'flex-start' }}
onSubmit={(e) => {
e.preventDefault()
const formData = new FormData(e.currentTarget)
console.log('terms:', formData.get('terms'))
}}
>
<Checkbox.Root className={styles.Root} name="terms" value="accepted">
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>I agree to the terms and conditions</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
<button className={button.Root} data-variant="solid" type="submit">
Submit
</button>
</form>
)
Context
Checkbox.Context 또는 useCheckboxContext 훅으로 체크박스의 상태와 메서드에 접근할 수 있어요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const Context = () => (
<Checkbox.Root className={styles.Root}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Context>
{(checkbox) => <Checkbox.Label className={styles.Label}>Checked: {String(checkbox.checked)}</Checkbox.Label>}
</Checkbox.Context>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
Checkbox Group
Checkbox.Group 컴포넌트를 사용하면 체크박스 여러 개를 하나의 그룹으로 관리할 수 있어요. Checkbox.Group 컴포넌트는 체크박스들의 상태를 관리하고, 체크된 값에 접근할 방법을 제공해요.
<Checkbox.Group>
<Checkbox.Root>
<Checkbox.Control>
<Checkbox.Indicator />
</Checkbox.Control>
<Checkbox.Label />
<Checkbox.HiddenInput />
</Checkbox.Root>
</Checkbox.Group>
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const Group = () => (
<Checkbox.Group className={styles.Group} defaultValue={['react']} name="framework">
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.Group>
)
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
제어 (Controlled)
value와 onValueChange prop을 사용하면 체크박스 그룹의 상태를 프로그래밍 방식으로 제어할 수 있어요. 이 예제는 선택된 체크박스를 배열로 관리하고 현재 선택 상태를 표시하는 방법을 보여줘요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/checkbox.module.css'
export const GroupControlled = () => {
const [value, setValue] = useState(['react'])
return (
<div className="vstack">
<output>value: {JSON.stringify(value)}</output>
<Checkbox.Group className={styles.Group} value={value} name="framework" onValueChange={setValue}>
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.Group>
</div>
)
}
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
RootProvider
useCheckboxGroup 훅으로 체크박스 그룹 저장소(store)를 만들고, 이 값을 Checkbox.GroupProvider 컴포넌트에 전달할 수 있어요. 이 방식은 개별 체크박스에서 RootProvider가 동작하는 것처럼, 그룹을 프로그래밍 방식으로 최대한 제어할 수 있게 해줘요.
import { Checkbox, useCheckboxGroup } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const GroupProvider = () => {
const group = useCheckboxGroup({
defaultValue: ['react'],
name: 'framework',
})
return (
<Checkbox.GroupProvider className={styles.Group} value={group}>
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.GroupProvider>
)
}
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
유효하지 않은 상태 (Invalid)
Checkbox.Group에 invalid prop을 사용하면 유효성 검사 목적으로 그룹 전체를 유효하지 않은 상태로 표시할 수 있어요. 이는 그룹 안의 모든 체크박스에 invalid 상태를 적용해요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const GroupWithInvalid = () => (
<Checkbox.Group className={styles.Group} invalid>
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.Group>
)
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
최대 선택 개수 (Max Selected)
maxSelectedValues prop을 사용하면 한 번에 선택할 수 있는 체크박스의 개수를 제한할 수 있어요. 최대 개수에 도달하면 나머지 체크박스는 비활성화돼요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
export const GroupWithMaxSelected = () => (
<Checkbox.Group className={styles.Group} defaultValue={['react']} maxSelectedValues={2} name="framework">
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.Group>
)
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
{ label: 'Svelte', value: 'svelte' },
]
전체 선택 (Select All)
한 그룹 안의 모든 체크박스를 제어하는 "전체 선택" 체크박스를 구현할 수 있어요. 부모 체크박스는 일부(전부는 아닌) 항목이 선택됐을 때 불확정(indeterminate) 상태를 자동으로 표시하고, 모든 항목이 선택되면 완전히 체크된 상태가 돼요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon, MinusIcon } from 'lucide-react'
import { useState } from 'react'
import styles from 'styles/checkbox.module.css'
const CheckboxItem = (props: Checkbox.RootProps) => {
return (
<Checkbox.Root className={styles.Root} {...props}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
<Checkbox.Indicator className={styles.Indicator} indeterminate>
<MinusIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{props.children}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
)
}
export const GroupWithSelectAll = () => {
const [value, setValue] = useState<string[]>([])
const handleSelectAll = (checked: boolean) => {
setValue(checked ? items.map((item) => item.value) : [])
}
const allSelected = value.length === items.length
const indeterminate = value.length > 0 && value.length < items.length
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
<output>Selected: {JSON.stringify(value)}</output>
<CheckboxItem
value="all"
checked={indeterminate ? 'indeterminate' : allSelected}
onCheckedChange={(e) => handleSelectAll(!!e.checked)}
>
JSX Frameworks
</CheckboxItem>
<Checkbox.Group
className={styles.Group}
style={{ marginInlineStart: '1rem' }}
value={value}
name="framework"
onValueChange={setValue}
>
{items.map((item) => (
<CheckboxItem value={item.value} key={item.value}>
{item.label}
</CheckboxItem>
))}
</Checkbox.Group>
</div>
)
}
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
폼 (Form)
폼 안에서 Checkbox.Group 컴포넌트를 사용하면 여러 체크박스 값을 폼 제출과 함께 처리할 수 있어요. name prop은 폼 제출 시 FormData.getAll()을 사용해 선택된 모든 값을 배열로 모을 수 있게 해줘요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
import button from 'styles/button.module.css'
export const GroupWithForm = () => (
<form
className="vstack"
onSubmit={(e) => {
e.preventDefault()
console.log(new FormData(e.currentTarget).getAll('framework'))
}}
>
<Checkbox.Group className={styles.Group} defaultValue={['react']} name="framework">
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.Group>
<button className={button.Root} type="submit">
Submit
</button>
</form>
)
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
Fieldset
Checkbox.Group와 함께 Fieldset 컴포넌트를 사용하면 legend(범례), 도움말 텍스트, 오류 텍스트를 지원하는 의미론적 그룹을 만들 수 있어요.
import { Checkbox } from '@ark-ui/react/checkbox'
import { Fieldset } from '@ark-ui/react/fieldset'
import { CheckIcon } from 'lucide-react'
import styles from 'styles/checkbox.module.css'
import fieldset from 'styles/fieldset.module.css'
export const GroupWithFieldset = () => (
<Fieldset.Root className={fieldset.Root}>
<Fieldset.Legend className={fieldset.Legend}>Select frameworks</Fieldset.Legend>
<Fieldset.HelperText className={fieldset.HelperText}>Choose your preferred frameworks</Fieldset.HelperText>
<Checkbox.Group className={styles.Group} defaultValue={['react']} name="framework">
{items.map((item) => (
<Checkbox.Root className={styles.Root} value={item.value} key={item.value}>
<Checkbox.Control className={styles.Control}>
<Checkbox.Indicator className={styles.Indicator}>
<CheckIcon />
</Checkbox.Indicator>
</Checkbox.Control>
<Checkbox.Label className={styles.Label}>{item.label}</Checkbox.Label>
<Checkbox.HiddenInput />
</Checkbox.Root>
))}
</Checkbox.Group>
</Fieldset.Root>
)
const items = [
{ label: 'React', value: 'react' },
{ label: 'Solid', value: 'solid' },
{ label: 'Vue', value: 'vue' },
]
가이드 (Guides)
asChild 동작 (asChild Behavior)
체크박스의 Checkbox.Root 요소는 label 요소예요. 체크박스는 폼 컨트롤이므로 사용자에게 맥락과 의미를 주기 위해 라벨과 연결되어야 하기 때문이에요. 그렇지 않으면 HTML과 접근성 구조가 올바르지 않게 돼요.
asChild속성을 사용해야 한다면,label요소가Checkbox.Root컴포넌트의 직접적인 자식이 되도록 해주세요.
API 참조 (API Reference)
Props
Root
Props
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
checked
Type: CheckedState
Required: false
Default Value: undefined
Description: 체크박스의 제어된 체크 상태예요.
defaultChecked
Type: CheckedState
Required: false
Default Value: undefined
Description: 렌더링될 때 체크박스의 초기 체크 상태예요.
체크박스의 체크 상태를 직접 제어할 필요가 없을 때 사용해요.
disabled
Type: boolean
Required: false
Default Value: undefined
Description: 체크박스가 비활성화되었는지 여부예요.
form
Type: string
Required: false
Default Value: undefined
Description: 체크박스가 속한 폼의 id예요.
id
Type: string
Required: false
Default Value: undefined
Description: 머신의 고유 식별자예요.
ids
Type: Partial<{ root: string; hiddenInput: string; control: string; label: string }>
Required: false
Default Value: undefined
Description: 체크박스 안 요소들의 id예요. 컴포지션에 유용해요.
invalid
Type: boolean
Required: false
Default Value: undefined
Description: 체크박스가 유효하지 않은지 여부예요.
name
Type: string
Required: false
Default Value: undefined
Description: 체크박스의 입력 필드 이름이에요.
폼 제출에 유용해요.
onCheckedChange
Type: (details: CheckedChangeDetails) => void
Required: false
Default Value: undefined
Description: 체크 상태가 변경될 때 호출되는 콜백이에요.
readOnly
Type: boolean
Required: false
Default Value: undefined
Description: 체크박스가 읽기 전용인지 여부예요.
required
Type: boolean
Required: false
Default Value: undefined
Description: 체크박스가 필수인지 여부예요.
value
Type: string
Required: false
Default Value: "on"
Description: 체크박스 입력의 값이에요. 폼 제출에 유용해요.
데이터 속성 (Data Attributes)
data-active: 활성화되거나 눌렸을 때 표시돼요.
data-focus: 포커스됐을 때 표시돼요.
data-focus-visible: 키보드로 포커스됐을 때 표시돼요.
data-readonly: 읽기 전용일 때 표시돼요.
data-hover: 호버됐을 때 표시돼요.
data-disabled: 비활성화됐을 때 표시돼요.
data-state: "indeterminate" | "checked" | "unchecked"
data-invalid: 유효하지 않을 때 표시돼요.
data-required: 필수일 때 표시돼요.
Control
Props
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
데이터 속성 (Data Attributes)
data-active: 활성화되거나 눌렸을 때 표시돼요.
data-focus: 포커스됐을 때 표시돼요.
data-focus-visible: 키보드로 포커스됐을 때 표시돼요.
data-readonly: 읽기 전용일 때 표시돼요.
data-hover: 호버됐을 때 표시돼요.
data-disabled: 비활성화됐을 때 표시돼요.
data-state: "indeterminate" | "checked" | "unchecked"
data-invalid: 유효하지 않을 때 표시돼요.
data-required: 필수일 때 표시돼요.
Group
Props
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
defaultValue
Type: string[]
Required: false
Default Value: undefined
Description: 비제어 방식일 때 value의 초기 값이에요.
disabled
Type: boolean
Required: false
Default Value: undefined
Description: true이면 체크박스 그룹이 비활성화돼요.
invalid
Type: boolean
Required: false
Default Value: undefined
Description: true이면 체크박스 그룹이 유효하지 않은 상태예요.
maxSelectedValues
Type: number
Required: false
Default Value: undefined
Description: 선택할 수 있는 값의 최대 개수예요.
name
Type: string
Required: false
Default Value: undefined
Description: 체크박스 그룹의 입력 필드 이름이에요.
(폼 제출에 유용해요.)
onValueChange
Type: (value: string[]) => void
Required: false
Default Value: undefined
Description: 값이 변경될 때 호출할 콜백이에요.
readOnly
Type: boolean
Required: false
Default Value: undefined
Description: true이면 체크박스 그룹이 읽기 전용이에요.
value
Type: string[]
Required: false
Default Value: undefined
Description: 체크박스 그룹의 제어된 값이에요.
GroupProvider
Props
value
Type: UseCheckboxGroupContext
Required: true
Default Value: undefined
Description: undefined
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
HiddenInput
Props
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
Indicator
Props
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
indeterminate
Type: boolean
Required: false
Default Value: undefined
Description: undefined
데이터 속성 (Data Attributes)
data-active: 활성화되거나 눌렸을 때 표시돼요.
data-focus: 포커스됐을 때 표시돼요.
data-focus-visible: 키보드로 포커스됐을 때 표시돼요.
data-readonly: 읽기 전용일 때 표시돼요.
data-hover: 호버됐을 때 표시돼요.
data-disabled: 비활성화됐을 때 표시돼요.
data-state: "indeterminate" | "checked" | "unchecked"
data-invalid: 유효하지 않을 때 표시돼요.
data-required: 필수일 때 표시돼요.
Label
Props
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
데이터 속성 (Data Attributes)
data-active: 활성화되거나 눌렸을 때 표시돼요.
data-focus: 포커스됐을 때 표시돼요.
data-focus-visible: 키보드로 포커스됐을 때 표시돼요.
data-readonly: 읽기 전용일 때 표시돼요.
data-hover: 호버됐을 때 표시돼요.
data-disabled: 비활성화됐을 때 표시돼요.
data-state: "indeterminate" | "checked" | "unchecked"
data-invalid: 유효하지 않을 때 표시돼요.
data-required: 필수일 때 표시돼요.
RootProvider
Props
value
Type: UseCheckboxReturn
Required: true
Default Value: undefined
Description: undefined
asChild
Type: boolean
Required: false
Default Value: undefined
Description: 제공된 자식 요소를 기본 렌더링 요소로 사용하고, 그 props와 동작을 결합해요.
Context
API:
| Property | Type | Description |
|---|---|---|
checked |
boolean |
체크박스가 체크되었는지 여부예요. |
disabled |
`boolean | undefined` |
indeterminate |
boolean |
체크박스가 불확정 상태인지 여부예요. |
focused |
`boolean | undefined` |
checkedState |
CheckedState |
체크박스의 체크 상태예요. |
setChecked |
(checked: CheckedState) => void |
체크박스의 체크 상태를 설정하는 함수예요. |
toggleChecked |
VoidFunction |
체크박스의 체크 상태를 토글하는 함수예요. |
접근성 (Accessibility)
Checkbox WAI-ARIA 디자인 패턴을 준수해요.
키보드 지원 (Keyboard Support)
Space
Description: 체크박스를 토글해요.