ScrollArea
손그림 테두리와 토큰으로 테마된 스크롤바를 갖춘 경계 스크롤 뷰포트입니다.
개요
ScrollArea는 경계 스크롤 뷰포트예요: 네이티브 스크롤바가 디자인 시스템에 맞게 테마된, 스크롤 가능한 영역 주위에 손그림 테두리를 그려요. 넘치는 콘텐츠 — 긴 목록, 코드 블록, 옵션 패널 — 의 높이(또는 너비)를 제한하면서 스케치 느낌을 일관되게 유지할 때 사용하세요.
구조
내부 뷰포트 주위의 손그림 테두리(@ghds/sketch-core)예요. 뷰포트는 표준 scrollbar-color / scrollbar-width CSS 속성을 사용하므로, 커스텀 스크롤바 오버레이 없이도 썸과 트랙이 comp.scrollArea.* 토큰을 가져와요(Firefox 및 Chromium 121+). style을 통해 maxHeight(또는 maxWidth)를 전달해 영역을 제한하세요.
변형 및 상태
인터랙티브 상태가 없어요 — 유일한 축은 스크롤 축을 선택하는 orientation이에요.
| State | Status | Notes |
|---|---|---|
| Hover | Not implemented | — |
| Focus | Not implemented | 스크롤 영역은 포커스되면 키보드로 스크롤 가능하지만, 자체적으로 포커스 스타일을 그리지 않아요. |
| 비활성화 | Not implemented | — |
| 로딩 | Not implemented | — |
| 오류 | Not implemented | — |
orientation prop은 'vertical'(기본값), 'horizontal', 'both'예요.
사용법
Do
- style을 통해 maxHeight(또는 maxWidth)로 박스를 제한하세요 — 그 경계가 콘텐츠를 스크롤되게 만들어요.
- orientation을 콘텐츠가 실제로 넘치는 축에 맞추세요.
- 스크롤되는 콘텐츠는 단순하게 유지하세요; 뷰포트는 일반 overflow 컨테이너예요.
Don't
- 같은 축에 스크롤 영역을 중첩하지 마세요; 스크롤바가 서로 다투어 사용자를 가둬요.
- Chromium 121보다 오래된 브라우저에서 테마된 스크롤바에 의존하지 마세요 — 네이티브 스크롤바로 폴백해요.
접근성
- 스크롤되는 영역은 키보드로 도달할 수 있어야 해요. 콘텐츠가 자연스럽게 포커스 가능하지 않을 때, 키보드 사용자가 스크롤할 수 있도록 뷰포트에
tabIndex={0}과aria-label을 지정하세요. - 테마된 스크롤바는 표준
scrollbar-*속성을 사용하므로 네이티브 스크롤바로 우아하게 저하돼요 — 스크롤 어포던스를 완전히 숨기지 않아요. - 공통 관례는 접근성 가이드를 참고하세요.
콘텐츠
N/A — ScrollArea는 고정된 콘텐츠 모델이 없어요. 안에 넣는 자식을 제한하고 선택한 축을 따라 넘치게 해요.
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'both' | 'vertical' | 영역이 스크롤하는 축(또는 축들). |
...rest | HTMLAttributes<HTMLDivElement> | — | 네이티브 <div> 속성이 전달돼요; style로 maxHeight / maxWidth를 설정하세요. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'both' | 'vertical' | 반영되는 속성; 영역이 스크롤하는 축(또는 축들). |
(기본 슬롯) | slot | — | 스크롤 가능한 콘텐츠. 호스트에 max-height(또는 max-width)를 설정하세요. |
React Native@ghds/react-native
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | 'vertical' | 'horizontal' | 'both' | 'vertical' | 영역이 스크롤하는 축(또는 축들)(네이티브 ScrollView를 감싸요). |
children | ReactNode | — | 스크롤 가능한 콘텐츠. |
style | StyleProp<ViewStyle> | — | 테두리 박스에 병합돼요; 여기서 높이/너비를 제한하세요(예: maxHeight). |
accessibilityLabel | string | — | 스크롤 영역의 접근 가능한 라벨. |
testID | string | — | 쿼리용 테스트 핸들. |
코드 예시
// React — @ghds/react
import { ScrollArea } from '@ghds/react/scroll-area';
<ScrollArea orientation="vertical" style={{ maxHeight: 200, maxWidth: 360 }}>
{/* 긴 콘텐츠 */}
</ScrollArea>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
import '@ghds/web-components/scroll-area';
</script>
<gh-scroll-area orientation="vertical" style="max-height: 200px; max-width: 360px;">
<!-- 긴 콘텐츠 -->
</gh-scroll-area>
// React Native — @ghds/react-native
import { ScrollArea } from '@ghds/react-native/scroll-area';
<ScrollArea orientation="vertical" style={{ maxHeight: 200 }}>
{/* 긴 콘텐츠 */}
</ScrollArea>;
라이브 데모
React와 Web Components가 아래에서 같은 토큰으로 라이브 렌더돼요 — 어느 쪽이든 스크롤하면 토큰으로 테마된 스크롤바가 나타나고, 헤더에서 다크 모드를 토글하면 둘이 동일하게 반응해요. React Native는 추가 react-native-web 연결 없이는 브라우저에서 실행할 수 없어요(이 사이트에 설정되지 않음), 따라서 사용법은 코드 샘플로 보여줘요. (React Native에서는 네이티브 스크롤바를 테마할 수 없어서 플랫폼 스크롤 인디케이터가 그대로 유지돼요.)
React @ghds/react
Web Components @ghds/web-components
1. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
2. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
3. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
4. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
5. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
6. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
7. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.
8. The quick brown fox jumps over the lazy dog, again and again until the box overflows and the themed scrollbar appears.