Carousel
네이티브 스크롤 기반으로 만든, 이전/다음 컨트롤을 갖춘 손그림 스크롤 스냅 캐러셀입니다.
개요
Carousel은 가로(또는 세로)로 스크롤되는 슬라이드의 슬라이드쇼예요. 서드파티 엔진 없이 네이티브 CSS 스크롤 스냅으로 만들어졌어요. 한 번에 한 뷰포트씩 동등한 항목 집합을 탐색할 때 사용하세요: 사진 갤러리, 기능 카드 세트, 온보딩 시퀀스. CarouselContent, CarouselItem, CarouselPrevious, CarouselNext로 조합하세요.
구조
캐러셀로 이름 지어진 role="region"이 슬라이드(CarouselItem, 각각 슬라이드로 설명된 role="group")의 스크롤 스냅 트랙(CarouselContent)을 감싸요. CarouselPrevious / CarouselNext는 한 스텝에 한 뷰포트씩 이동하고 각각 시작 / 끝에서 비활성화되는 Button이에요. 화살표 키가 방향 축을 따라 스크롤하고, 스냅은 네이티브로 유지되면서 스크롤바는 시각적으로 숨겨져요.
변형 및 상태
유일한 변형 축은 orientation('horizontal' 기본값, 또는 'vertical')이에요. 컨트롤 상태는 스크롤 위치에서 나와요.
| State | Status | Notes |
|---|---|---|
| At start | Implemented | 뷰포트가 시작에 있으면 CarouselPrevious가 비활성화돼요. |
| At end | Implemented | 뷰포트가 끝에 있으면 CarouselNext가 비활성화돼요. |
| Focus | Implemented | 영역은 포커스되면 화살표 키로 스크롤 가능해요. |
| 비활성화 | Not implemented | 캐러셀 자체는 비활성화 상태가 없어요. |
| 로딩 | Not implemented | — |
사용법
Do
- 캐러셀(또는 래퍼)에 명시적인 너비를 지정하세요 — 세로 캐러셀의 경우 CarouselContent에 경계 높이도 지정하세요.
- 슬라이드 집합을 설명하는 aria-label을 제공하세요(예: "Photos").
- CarouselItem의 flexBasis를 의도적으로 재정의하지 않는 한 뷰포트당 하나의 슬라이드를 유지하세요.
Don't
- 필수적이고 시간에 민감한 콘텐츠를 캐러셀에 넣지 마세요 — 사용자가 첫 슬라이드를 지나 스크롤하지 않을 수 있어요.
- 일시정지 컨트롤 없이 자동 전환하지 마세요; 멈출 수 없는 모션은 접근성 문제예요.
접근성
- 루트는 ARIA APG 캐러셀 패턴이에요:
role="region"+aria-roledescription="carousel",aria-label로 이름 지어져요. 각 슬라이드는aria-roledescription="slide"가 있는role="group"이에요. - 컨트롤은 “Previous slide” / “Next slide”로 라벨이 지정된 실제
<button>이며 각 끝에서disabled가 되므로 상태가 알려져요. - 화살표 키(가로일 때 Left/Right, 세로일 때 Up/Down)가 영역을 스크롤하고, 네이티브 스크롤 컨테이너는 키보드와 터치로 조작 가능하게 유지돼요.
- 공통 관례는 접근성 가이드를 참고하세요.
콘텐츠
슬라이드는 대략 동등한 비중의 동료여야 해요. 각 슬라이드를 자족적으로 유지하고 — 사용자가 어느 것이든 먼저 볼 수 있어요 — 하나의 메시지를 여러 슬라이드에 나누지 마세요.
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | 스크롤 축(Carousel). |
...rest | HTMLAttributes<HTMLDivElement> | — | 네이티브 <div> 속성(aria-label 등)이 영역으로 전달돼요. |
CarouselContent | HTMLAttributes<HTMLDivElement> | — | 스크롤 스냅 트랙; style로 maxHeight/maxWidth를 설정해 제한하세요. |
CarouselItem | HTMLAttributes<HTMLDivElement> | — | 단일 슬라이드; 뷰포트당 여러 개를 위해 style로 flexBasis를 재정의하세요. |
CarouselPrevious / CarouselNext | ButtonProps | — | 이전/다음 컨트롤(Button); 끝에서 자동 비활성화돼요. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | reflected 속성; 스크롤 축. |
slides | <gh-carousel-item> | — | <gh-carousel-item> 슬라이드를 기본 슬롯에 배치하세요. @ghds/web-components/carousel과 /carousel-item을 모두 import 하세요. |
controls | built-in | — | 요소가 자체 이전/다음 버튼과 인디케이터 점을 렌더해요 — 별도의 컨트롤 요소가 없어요. |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | 스크롤 축(Carousel). |
accessibilityLabel | string | — | 캐러셀 영역의 접근 가능한 라벨. |
children | ReactNode | — | CarouselContent / CarouselItem / CarouselPrevious / CarouselNext / CarouselIndicators로 조합하세요. |
testID | string | — | 쿼리용 테스트 핸들. |
코드 예시
// React — @ghds/react
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselPrevious,
CarouselNext,
} from '@ghds/react/carousel';
<Carousel orientation="horizontal" aria-label="Photos">
<CarouselContent>
<CarouselItem>Slide 1</CarouselItem>
<CarouselItem>Slide 2</CarouselItem>
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>;
<!-- Web Components — @ghds/web-components (이전/다음 버튼과 점 표시를 직접 렌더해요) -->
<script type="module">
import '@ghds/web-components/carousel';
import '@ghds/web-components/carousel-item';
</script>
<gh-carousel aria-label="Photos">
<gh-carousel-item>Slide 1</gh-carousel-item>
<gh-carousel-item>Slide 2</gh-carousel-item>
</gh-carousel>
// React Native — @ghds/react-native
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselPrevious,
CarouselNext,
CarouselIndicators,
} from '@ghds/react-native/carousel';
<Carousel accessibilityLabel="Photos">
<CarouselContent>
<CarouselItem>{/* 슬라이드 1 */}</CarouselItem>
<CarouselItem>{/* 슬라이드 2 */}</CarouselItem>
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
<CarouselIndicators />
</Carousel>;
라이브 데모
아래에서 React와 Web Components가 동일한 토큰으로 구동되며 라이브 렌더돼요 — 헤더에서 다크 모드를 토글하면 둘 다 동일하게 반응해요. React Native는 추가 react-native-web 연결 없이는 브라우저에서 실행할 수 없어요(이 사이트에 설정되지 않음), 따라서 사용법은 코드 샘플로 보여줘요. (Web Components 요소는 자체 이전/다음 컨트롤과 인디케이터 점을 렌더해요.)