Tabs
WAI-ARIA Tabs 패턴을 따르는 손그림 스타일의 탭 인터페이스입니다.
개요
Tabs는 같은 공간에서 관련된 콘텐츠 패널 사이를 전환하게 해줘요. 한 번에 하나의 탭이 활성화되고,
해당 패널이 표시되며 나머지는 숨겨져요.
구조
role="tabpanel" 영역 위에 role="tab" 버튼의 role="tablist"가 있어요. 활성 탭은 스케치 스타일의
박스(@ghds/sketch-core)로 채워지고 강조 텍스트 색상으로 표시돼요; 해당 패널은 aria-controls/
aria-labelledby로 연결돼요. API는 데이터 기반이에요 — { value, label, content }의 items 배열을
전달하세요.
변형 및 상태
| State | Status | Notes |
|---|---|---|
| 선택됨 | Implemented | 활성 탭: 채워진 박스 + 강조 라벨 + aria-selected. |
| 비활성화 | Implemented | 항목별; 키보드 탐색에서 건너뛰어져요. |
| 포커스 | Implemented | 루빙 tabindex — 포커스가 활성 탭에 있어요. |
| 호버 | Implemented | — |
사용법
Do
- 탭 라벨을 짧고 표현을 병렬로 유지하세요.
- 순차적 단계가 아니라 동등한 콘텐츠의 대체 보기에 탭을 사용하세요.
- 활성 탭이 다른 상태와 동기화되어야 한다면 제어 방식으로 유지하세요 (value + onValueChange).
Don't
- 모든 콘텐츠를 한 번에 보여야 할 때 탭을 사용하지 마세요 — 섹션을 대신 사용하세요.
- 탭 안에 탭을 중첩하지 마세요; 빠르게 혼란스러워져요.
접근성
- React / Web Components: 완전한 WAI-ARIA Tabs 패턴 —
tablist/tab/tabpanel역할,aria-selected,aria-controls/aria-labelledby, 그리고 루빙 tabindex(활성 탭만 탭 순서에 있어요). 화살표 키 / Home / End로 탭을 이동하고 활성화해요 (자동 활성화). Web Components는value-change이벤트를 디스패치해요. - React Native: 탭은
accessibilityState.selected를 가진role="tab"이에요; 탭으로 선택해요. 화살표 키 루빙 탐색은 React Native의 알려진 차이예요 (Pressable에onKeyDown이 없어요) — React와 Web Component 빌드에서 사용할 수 있어요.
| Key | Action |
|---|---|
Arrow keys | 이전/다음 탭으로 이동하고 활성화해요 (순환). |
Home / End | 첫 번째 / 마지막 탭을 활성화해요. |
Tab | 포커스를 탭리스트에서 벗어나 활성 패널로 이동해요. |
콘텐츠
탭당 짧은 라벨과 패널 콘텐츠. 패널 콘텐츠는 React/React Native에서 ReactNode예요;
Web Components에서는 패널 텍스트(content 문자열)예요 — 풍부한 마크업이 필요하면 자체 패널을
렌더링하고 value-change 이벤트로 구동하세요.
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
items | TabItem[] | — | 탭당 { value, label, content, disabled? }. |
value | string | — | 제어되는 활성 값. |
defaultValue | string | — | 비제어 시 초기 값 (기본값은 첫 번째). |
onValueChange | (value: string) => void | — | 활성 탭이 변경될 때 발생해요. |
label | string | — | 탭리스트의 접근성 이름. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
items | GhTabItem[] | — | { value, label, content?: string, disabled? } (속성). |
value | string | — | 제어되는 활성 값. |
label | string | — | 탭리스트의 접근성 이름. |
value-change event | CustomEvent<string> | — | 새 값과 함께 디스패치돼요. |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
items | TabItem[] | — | 탭당 { value, label, content, disabled? }. |
value | string | — | 제어되는 활성 값. |
defaultValue | string | — | 비제어 시 초기 값. |
onValueChange | (value: string) => void | — | 활성 탭이 변경될 때 발생해요. |
label | string | — | 접근성 이름. |
testID | string | — | 쿼리용 테스트 핸들. |
코드 예시
// React — @ghds/react
import { Tabs } from '@ghds/react/tabs';
<Tabs
label="Product details"
items={[
{ value: 'overview', label: 'Overview', content: <p>The overview panel.</p> },
{ value: 'specs', label: 'Specs', content: <p>The specifications panel.</p> },
]}
/>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
import '@ghds/web-components/tabs';
</script>
<gh-tabs id="my-tabs" label="Product details"></gh-tabs>
<script>
const el = document.getElementById('my-tabs');
el.items = [
{ value: 'overview', label: 'Overview', content: 'The overview panel.' },
{ value: 'specs', label: 'Specs', content: 'The specifications panel.' },
];
el.addEventListener('value-change', (e) => { el.value = e.detail; });
</script>
// React Native — @ghds/react-native
import { Tabs } from '@ghds/react-native/tabs';
import { Text } from '@ghds/react-native/theme';
<Tabs
label="Product details"
items={[
{ value: 'overview', label: 'Overview', content: <Text>Overview</Text> },
{ value: 'specs', label: 'Specs', content: <Text>Specs</Text> },
]}
/>;