아코디언

접을 수 있는 섹션들로 구성된 손그림 스타일의 아코디언(공개 패턴)입니다.

개요

Accordion은 접을 수 있는 섹션들을 세로로 쌓아, 사람들이 필요한 콘텐츠만 펼쳐 볼 수 있게 해줘요. FAQ처럼 최대 한 개 섹션만 열려 있게 하려면 type="single"을, 여러 섹션이 동시에 열려 있게 하려면 type="multiple"을 사용하세요.

구조

손그림 스타일의 박스(@ghds/sketch-core)들을 세로로 쌓고, 각 박스는 헤더 버튼(aria-expanded, aria-controls)과 접을 수 있는 role="region"을 가져요. 헤더의 셰브론은 펼친 상태에서 회전해요. API는 데이터 기반이에요 — { value, label, content } 형태의 items 배열을 전달하세요. 열린 상태는 값들의 집합(string[])이며, 제어/비제어 방식 모두 지원해요.

변형 및 상태

State Status Notes
접힘 Implemented 기본값; 콘텐츠 숨김, aria-expanded=false.
펼침 Implemented 콘텐츠 표시, 셰브론 회전, aria-expanded=true.
단일 vs 다중 Implemented type이 한 번에 하나 또는 여러 개를 열 수 있는지 결정해요.
비활성화 Implemented 항목별; 헤더를 토글할 수 없고 화살표 키로 건너뛰어요.

사용법

Do

  • 상호 배타적인 콘텐츠(FAQ)에는 단일 모드를, 섹션이 독립적일 때는 다중 모드를 사용하세요.
  • 간결하고 빠르게 훑어볼 수 있는 헤더 라벨을 작성하세요.
  • 열린 상태가 다른 UI와 동기화되어야 한다면 제어 방식(value + onValueChange)을 사용하세요.

Don't

  • 사용자가 반드시 봐야 하는 중요한 콘텐츠를 아코디언 뒤에 숨기지 마세요.
  • 아코디언을 깊게 중첩하지 마세요 — 콘텐츠가 묻혀요.

접근성

Key Action
Enter / Space 포커스된 섹션을 토글해요.
Arrow Up / Down 이전 / 다음 헤더로 포커스 이동(순환).
Home / End 첫 번째 / 마지막 헤더로 포커스 이동.

콘텐츠

각 섹션의 짧은 헤더 라벨과 펼쳐지는 콘텐츠예요. 콘텐츠는 React/React Native에서 ReactNode이고, Web Components에서는 섹션 텍스트(content 문자열)예요.

Props API

React@ghds/react

PropTypeDefaultDescription
itemsAccordionItem[]—섹션별 { value, label, content, disabled? }.
type'single' | 'multiple''single'열 수 있는 섹션 수.
valuestring[]—제어 방식의 열린 값 집합.
defaultValuestring[]—비제어 방식의 초기 열린 값.
onValueChange(values: string[]) => void—열린 집합이 변경될 때 호출돼요.

Web Components@ghds/web-components

PropTypeDefaultDescription
itemsGhAccordionItemData[]—{ value, label, content?: string, disabled? } (프로퍼티).
type'single' | 'multiple''single'열 수 있는 섹션 수.
valuestring[]—제어 방식의 열린 값 집합(프로퍼티).
value-change eventCustomEvent<string[]>—열린 집합과 함께 발생해요.

React Native@ghds/react-native

PropTypeDefaultDescription
itemsAccordionItem[]—섹션별 { value, label, content, disabled? }.
type'single' | 'multiple''single'열 수 있는 섹션 수.
valuestring[]—제어 방식의 열린 값 집합.
defaultValuestring[]—비제어 방식의 초기 열린 값.
onValueChange(values: string[]) => void—열린 집합이 변경될 때 호출돼요.
testIDstring—쿼리용 테스트 핸들.

코드 예시

// React — @ghds/react
import { Accordion } from '@ghds/react/accordion';

<Accordion
  type="single"
  defaultValue={['shipping']}
  items={[
    { value: 'shipping', label: 'Shipping', content: <p>Ships in 2–3 business days.</p> },
    { value: 'returns', label: 'Returns', content: <p>Free returns within 30 days.</p> },
  ]}
/>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
  import '@ghds/web-components/accordion';
  const el = document.getElementById('acc');
  el.type = 'single';
  el.value = ['shipping'];
  el.items = [
    { value: 'shipping', label: 'Shipping', content: 'Ships in 2–3 business days.' },
    { value: 'returns', label: 'Returns', content: 'Free returns within 30 days.' },
  ];
  el.addEventListener('value-change', (e) => {
    el.value = e.detail;
  });
</script>
<gh-accordion id="acc"></gh-accordion>
// React Native — @ghds/react-native
import { Accordion } from '@ghds/react-native/accordion';
import { Text } from '@ghds/react-native/theme';

<Accordion
  type="single"
  items={[{ value: 'shipping', label: 'Shipping', content: <Text>Ships in 2–3 days.</Text> }]}
/>;

라이브 데모

React @ghds/react

Web Components @ghds/web-components