체크박스

중간 상태와 CheckboxGroup 래퍼를 가진 손그림 스타일의 체크박스입니다.

개요

Checkbox는 켜기/끄기 불리언 입력이에요 — indeterminate(“일부만 선택됨”) 상태도 보여줄 수 있어요. CheckboxGroup은 관련 체크박스들을 묶고 결합된 값을 배열로 관리해요.

구조

실제 <input type="checkbox">(React/Web Components) 또는 accessibilityRole="checkbox"를 가진 Pressable(React Native) 뒤에 그려진 손그림 박스예요. 체크되거나 중간 상태일 때 손그림 체크 또는 마이너스 표시가 위에 렌더돼요 — 새로운 글리프 형상을 만드는 대신 기존 Icon/gh-icon 컴포넌트를 재사용해요.

변형 및 상태

체크박스에는 시각적 변형이 없어요 — 상태만 있어요.

State Status Notes
체크 안 됨 Implemented —
체크됨 Implemented 박스가 단색으로 채워지고; 체크 표시가 렌더돼요.
중간 상태 Implemented 체크됨처럼 박스가 단색으로 채워지고, 체크 대신 대시 표시가 렌더돼요. DOM 전용 프로퍼티이며 폼 값은 아니에요.
비활성화 Implemented —
로딩 Not implemented —

사용법

Do

  • 여러 체크박스가 하나의 다중 선택 필드를 나타낼 때 CheckboxGroup을 사용하세요.
  • "모두 선택" 체크박스에 일부(전체는 아닌) 자식이 체크되었을 때 indeterminate를 사용하세요.

Don't

  • 즉각적인 설정 토글처럼 Switch가 더 적합한 이진 선택에 단일 Checkbox를 사용하지 마세요 — Checkbox는 폼 필드를, Switch는 즉각적인 상태 변화를 의미해요.
  • indeterminate가 체크 토글 후에도 유지되길 기대하지 마세요 — checked를 설정하면 해제돼요(네이티브 체크박스 동작과 동일).

접근성

콘텐츠

라벨은 동작이 아니라 무엇에 동의하는지를 나타내요(“Subscribe to updates”) — Button과 대조돼요.

Props API

React@ghds/react

PropTypeDefaultDescription
labelstring—Radix Label로 연결된 보이는 라벨.
indeterminateboolean—3상태 시각 표시. DOM 프로퍼티로 명령형 설정.
valuestring—CheckboxGroup 내에서 이 체크박스를 식별해요. 단독 사용 시 무시돼요.
checkedboolean—제어 방식의 체크 상태.
defaultCheckedbooleanfalse비제어 방식의 초기 체크 상태.
disabledbooleanfalse인터랙션을 비활성화해요.
...restInputHTMLAttributes—다른 모든 네이티브 input 속성(onChange, name 등)이 전달돼요.

Web Components@ghds/web-components

PropTypeDefaultDescription
checkedbooleanfalsereflected 속성.
indeterminatebooleanfalsereflected 속성. 내부 input의 DOM 프로퍼티로도 설정돼요.
disabledbooleanfalse인터랙션과 폼 참여를 비활성화해요.
namestring—제출되는 컨트롤 이름.
valuestring'on'체크 시 제출되는 값.
labelstring—선택적 보이는 라벨이자 접근성 이름.

React Native@ghds/react-native

PropTypeDefaultDescription
labelstring—보이는 접근성 라벨 — 필수(RN에는 별도 라벨 요소가 없어요).
checkedboolean—제어 방식의 체크 상태.
defaultCheckedboolean—비제어 방식의 초기 체크 상태.
onCheckedChange(checked: boolean) => void—토글 시 다음 체크 상태로 호출돼요.
indeterminateboolean—3상태 시각 표시.
disabledbooleanfalse인터랙션을 비활성화해요.
valuestring—CheckboxGroup 내에서 이 체크박스를 식별해요.
testIDstring—쿼리용 테스트 핸들.

코드 예시

// React — @ghds/react (onChange는 이벤트를 받아요. event.target.checked를 읽으세요)
import { Checkbox } from '@ghds/react/checkbox';

<Checkbox
  label="Subscribe to updates"
  checked={subscribed}
  onChange={(event) => setSubscribed(event.target.checked)}
/>;
<Checkbox label="Select all" indeterminate />;
<!-- Web Components — @ghds/web-components (콜백 prop이 없어요. `change` 이벤트 리스너를 등록하세요) -->
<script type="module">
  import '@ghds/web-components/checkbox';
</script>
<gh-checkbox label="Subscribe to updates"></gh-checkbox>
<gh-checkbox label="Select all" indeterminate></gh-checkbox>
// React Native — @ghds/react-native (onCheckedChange는 이벤트가 아니라 불리언 값을 그대로 받아요)
import { Checkbox } from '@ghds/react-native/checkbox';

<Checkbox label="Subscribe to updates" checked={subscribed} onCheckedChange={setSubscribed} />;

라이브 데모

React와 Web Components가 아래에 라이브로 렌더돼요. React Native는 추가 react-native-web 연결 없이는 브라우저에서 실행할 수 없어요(이 사이트에 설정되지 않음), 따라서 사용법은 코드 샘플로 보여줘요.

React @ghds/react

Web Components @ghds/web-components