커스텀 스크롤바를 지원하는, 스타일 없고 접근 가능한 스크롤 영역 컴포넌트예요.
출처: 문서
본문
기능 (Features)
- 하위 컴포넌트 구성 API:
Root, Viewport, Content, Scrollbar, Handle, Corner
- 뷰포트 대 콘텐츠 비율에 기반한 자동 핸들 크기 조정
- 스크롤바 트랙과 핸들 모두에서의 포인터 기반 드래그 상호작용
- 콘텐츠 변경 시 자동 재계산을 위한 ResizeObserver
- 변형(variant) 기반 스크롤바 표시 제어 (
auto, hover, scroll, always, hidden)
- 페이드 효과와 로딩 표시기를 위한 스크롤 경계 감지
사용법 (Usage)
import { ScrollArea } from 'primereact/scrollarea';
<ScrollArea.Root>
<ScrollArea.Viewport>
<ScrollArea.Content></ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar>
<ScrollArea.Handle />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
동작 (Behavior)
다형적 렌더링 (Polymorphic Rendering)
as를 사용해 하위 컴포넌트가 렌더링할 HTML 요소를 바꿀 수 있어요.
<ScrollArea.Root as="section">
<ScrollArea.Viewport as="main">
<ScrollArea.Content as="article"></ScrollArea.Content>
</ScrollArea.Viewport>
</ScrollArea.Root>
렌더 함수 자식 (Render Function Children)
하위 컴포넌트는 children으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있어요.
<ScrollArea.Root>{(instance) => <div>{instance.state.scrolling ? 'Scrolling...' : 'Idle'}</div>}</ScrollArea.Root>
Pass Through
<DocPTViewer name="scrollarea-pt" components={['ScrollAreaRoot']} />
API
| Attribute |
Value |
data-scope |
"scrollarea" |
data-part |
"root" |
data-variant |
Current variant value |
data-scrolling |
Present when actively scrolling |
data-has-overflow-x |
Present when content overflows horizontal |
data-has-overflow-y |
Present when content overflows vertical |
data-scroll-x-before |
Present when scrolled past left edge |
data-scroll-x-after |
Present when content remains to the right |
data-scroll-y-before |
Present when scrolled past top edge |
data-scroll-y-after |
Present when content remains below |
CSS 커스텀 프로퍼티 (CSS Custom Properties)
Root 요소는 스크롤바 모서리 크기 조정을 위해 style에 CSS 커스텀 프로퍼티를 설정해요.
| CSS Variable |
Description |
--corner-height |
Height of the scrollbar corner in pixels |
--corner-width |
Width of the scrollbar corner in pixels |
| Label |
Type |
Description |
| root |
ScrollAreaRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| viewport |
ScrollAreaRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the viewport's DOM element. |
| scrollbar |
ScrollAreaRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the scrollbar's DOM element. |
| handle |
ScrollAreaRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the handle's DOM element. |
| corner |
ScrollAreaRootPassThroughType<HTMLAttributes> |
Used to pass attributes to the corner's DOM element. |
| Attribute |
Value |
data-scope |
"scrollarea" |
data-part |
"viewport" |
| Label |
Type |
Description |
| root |
ScrollAreaViewportPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
ScrollAreaContent
| Label |
Type |
Description |
| root |
ScrollAreaContentPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"scrollarea" |
data-part |
"scrollbar-y" or "scrollbar-x" |
CSS 커스텀 프로퍼티 (CSS Custom Properties)
Scrollbar 요소는 핸들 크기와 위치 지정을 위해 style에 CSS 커스텀 프로퍼티를 설정해요. 구체적인 변수는 스크롤바 방향에 따라 달라요.
| CSS Variable |
Description |
--handle-height |
Height of the vertical scrollbar handle in pixels |
--handle-width |
Width of the horizontal scrollbar handle in pixels |
--handle-offset |
Offset position of the handle along the scrollbar track |
| Label |
Type |
Description |
| root |
ScrollAreaScrollbarPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"scrollarea" |
data-part |
"handle-y" or "handle-x" |
| Label |
Type |
Description |
| root |
ScrollAreaHandlePassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Attribute |
Value |
data-scope |
"scrollarea" |
data-part |
"corner" |
| Label |
Type |
Description |
| root |
ScrollAreaCornerPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
ScrollAreaHandleYPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
| Label |
Type |
Description |
| root |
ScrollAreaHandleXPassThroughType<HTMLAttributes> |
Used to pass attributes to the root's DOM element. |
접근성 (Accessibility)
스크린 리더 (Screen Reader)
스크롤바는 스크롤 가능한 콘텐츠 컨테이너를 참조하는 aria-controls와 스크롤 방향을 나타내는 aria-orientation과 함께 scrollbar 역할을 사용해요.
키보드 지원 (Keyboard Support)
| Key |
Function |
tab |
Moves focus through the scrollable region. |
down arrow |
Scrolls content down when vertical scrolling is available. |
up arrow |
Scrolls content up when vertical scrolling is available. |
left arrow |
Scrolls content left when horizontal scrolling is available. |
right arrow |
Scrolls content right when horizontal scrolling is available. |
더 알아보기 (Learn more)