Checkbox
Checkbox (체크박스)
사용자가 체크됨과 체크되지 않음 사이를 토글할 수 있게 해 주는 컨트롤이에요. indeterminate(불확정) 상태와 비활성화 상태도 지원해요.
출처: 문서
본문
해부 (Anatomy)
- Root: 체크박스의 루트 컨테이너
- Input: 화면에서 숨겨진 네이티브 html 입력 요소
사용법 (Usage)
체크박스를 만들려면 createCheckbox 빌더 함수를 사용하세요. 해부 구조나 위의 예제를 따라 체크박스를 만들면 돼요.
Indeterminate 상태
indeterminate 체크박스를 만들려면 checked 인자를 indeterminate로 설정하세요.
<script lang="ts">
import { createCheckbox } from '@melt-ui/svelte'
const { root, input, isChecked, isIndeterminate, checked } = createCheckbox({
checked: 'indeterminate'
})
// or
checked.set('indeterminate')
</script>
체크박스 비활성화하기
체크박스를 비활성화하려면 disabled 인자를 true로 설정하세요.
<script lang="ts">
import { createCheckbox } from '@melt-ui/svelte'
const { root, input, isChecked, isIndeterminate, checked, options } = createCheckbox({
disabled: true
})
// or
options.update((prev) => ({ ...prev, disabled: true }))
</script>
접근성 (Accessibility)
tri-state Checkbox WAI-ARIA 디자인 패턴을 준수해요.