아코디언 (Accordion)
콘텐츠를 접을 수 있는 패널(collapsible panel)로 묶어 주는 컴포넌트예요. 여러 섹션을 한데 모아, 열고 닫으며 필요한 내용만 보여줄 수 있어요.
출처: 문서
본문
설치 (Installation)
Shadcn CLI Manual ```bash npx shadcn@latest add https://primereact.dev/r/accordion.json ``` Copy and paste the following code into your project Update the import paths to match your project setup.사용법 (Usage)
import { Accordion, AccordionContent, AccordionPanel, AccordionTrigger } from '@/components/ui/accordion';
<Accordion>
<AccordionPanel value="1">
<AccordionTrigger>Title</AccordionTrigger>
<AccordionContent>Content</AccordionContent>
</AccordionPanel>
</Accordion>
예제 (Examples)
기본 (Basic)
다중 열기 (Multiple)
각 Accordion.Panel은 고유한 value를 정의해야 해요. 기본적으로 한 번에 하나의 패널만 열려요. 여러 패널이 동시에 열리게 하려면 Accordion.Root에 multiple을 활성화하세요.
제어 (Controlled)
활성 패널 상태를 value와 onValueChange로 제어해요.
비활성화 (Disabled)
Accordion.Panel에 disabled를 설정하면 그 패널만, Accordion.Root에 설정하면 모든 패널을 비활성화해요.
라디오버튼과 함께 (With RadioButton)
RadioButton 컴포넌트로 여러 Accordion.Panel 컴포넌트를 그룹화할 수 있어요.
접근성 (Accessibility)
스크린 리더 (Screen Reader)
아코디언 헤더는 버튼이에요. aria-controls로 콘텐츠 영역을 참조하고, aria-expanded로 가시 상태를 반영해요. 발표되는 라벨은 pt를 통해 aria-label이나 aria-labelledby로 커스터마이즈할 수 있어요.
콘텐츠는 role="region"을 사용하고, 헤더 버튼의 aria-controls와 일치하는 id를 가져요.
헤더 키보드 지원 (Header Keyboard Support)
| Key | Function |
|---|---|
tab |
Moves focus to the next focusable element in the page tab sequence. |
shift + tab |
Moves focus to the previous focusable element in the page tab sequence. |
enter |
Toggles the visibility of the content. |
space |
Toggles the visibility of the content. |
down arrow |
Moves focus to the next header. If focus is on the last header, moves focus to the first header. |
up arrow |
Moves focus to the previous header. If focus is on the first header, moves focus to the last header. |
home |
Moves focus to the first header. |
end |
Moves focus to the last header. |
더 알아보기 (Learn more)
- 프리미티브 API —
AccordionRoot,AccordionPanel등 하위 컴포넌트 문서 - 헤들리스 API —
useAccordion훅 문서 - Tailwind 가이드 시작하기 — Tailwind 모드 개요