CheckboxGroup
CheckboxGroup은 여러 체크박스를 묶어서 공통된 값을 관리하는 컴포넌트예요. 여러 항목을 한 번에 선택하게 할 때, 각각의 상태를 일일이 관리하는 대신 그룹 차원에서 다루고 싶다면 유용해요.
출처: 문서
본문
사용법 (Usage)
import { Checkbox } from '@primereact/ui/checkbox';
import { CheckboxGroup } from '@primereact/ui/checkboxgroup';
<CheckboxGroup></CheckboxGroup>
예시 (Examples)
기본 (Basic)
공통된 값 배열을 공유하는 체크박스 그룹이에요.
제어 (Controlled)
value와 onValueChange로 선택 상태를 직접 제어해, 상태를 내가 관리할 수 있어요.
동적 (Dynamic)
값 목록을 이용해 체크박스들을 생성할 수 있어요.
카드 (Card)
체크박스들을 카드 형태로 표시할 수 있어요.
불확정 상태 (Indeterminate)
Checkbox.Root(보통 부모/전체 선택 옵션)에 indeterminate를 사용해서 부분 선택 상태를 표시할 수 있어요.
중첩 그룹 (Nested Group)
접근 제어 흐름에서 팀 단위와 권한 단위 선택을 관리할 때 중첩 그룹을 사용할 수 있어요.
인디케이터 (Indicator)
각 그룹 항목에서 Checkbox.Indicator를 사용해서 체크 상태를 렌더링할 수 있어요.
Checkbox.Indicator는 체크박스 상태에 따라 렌더링할 match prop도 받을 수 있어요.
<Checkbox.Root indeterminate>
<Checkbox.Box>
<Checkbox.Indicator match="checked">
<Check />
</Checkbox.Indicator>
<Checkbox.Indicator match="unchecked">
<Times />
</Checkbox.Indicator>
<Checkbox.Indicator match="indeterminate">
<Minus />
</Checkbox.Indicator>
</Checkbox.Box>
</Checkbox.Root>
사용 가능한 match 값은 checked, unchecked, indeterminate예요. match prop이 없으면 인디케이터는 모든 상태에서 렌더링돼요.
접근성 (Accessibility)
화면 낭독기 (Screen Reader)
CheckboxGroup의 각 옵션은 보조 기술에서 체크박스로 알려져요. inputId + <label htmlFor>로 라벨을 연결하거나, 각 Checkbox.Root에 aria-label / aria-labelledby를 제공하세요.
키보드 지원 (Keyboard Support)
| Key | Function |
|---|---|
tab |
Moves focus to the next checkbox. |
space |
Toggles checked or unchecked state. |
테마 (Theming)
CSS 클래스 (CSS Classes)
styled 모드에서 사용하는 클래스 이름 목록이에요.
| ClassName | Description |
|---|---|
| p-checkbox-group | Class name of the root element |
디자인 토큰 (Design Tokens)
디자인 토큰 목록이에요.
더 알아보기 (Learn more)
- CheckboxGroup과 함께 쓰는 Checkbox 서브 컴포넌트 구조를 확인해 보세요.
indeterminate와 중첩 그룹으로 접근 제어 UI를 구성해 보세요.