ScrollArea
Features
- Scrollbar sits on top of the scrollable content, taking up no space.
- Scrolling is native; no underlying position movements via CSS transformations.
- Shims pointer behaviors only when interacting with the controls, so keyboard controls are unaffected.
- Supports Right to Left direction.
Installation
Install the component from your command line.
$ npm add reka-ui
Anatomy
Import all parts and piece them together.
<script setup>
import { ScrollAreaRoot, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport } from 'reka-ui'
</script>
<template>
<ScrollAreaRoot>
<ScrollAreaViewport />
<ScrollAreaScrollbar orientation="horizontal">
<ScrollAreaThumb />
</ScrollAreaScrollbar>
<ScrollAreaScrollbar orientation="vertical">
<ScrollAreaThumb />
</ScrollAreaScrollbar>
<ScrollAreaCorner />
</ScrollAreaRoot>
</template>
API Reference
Root
Contains all the parts of a scroll area.
Prop | Default | Type |
---|---|---|
as | 'div' | AsTag | Component The element or component this component should render as. Can be overwrite by |
asChild | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
dir | 'ltr' | 'rtl' The reading direction of the combobox when applicable. | |
scrollHideDelay | 600 | number If type is set to either |
type | 'hover' | 'scroll' | 'always' | 'auto' | 'hover' Describes the nature of scrollbar visibility, similar to how the scrollbar preferences in MacOS control visibility of native scrollbars.
|
Methods | Type |
---|---|
scrollTop | () => void Scroll viewport to top |
scrollTopLeft | () => void Scroll viewport to top-left |
Viewport
The viewport area of the scroll area.
Prop | Default | Type |
---|---|---|
as | 'div' | AsTag | Component The element or component this component should render as. Can be overwrite by |
asChild | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
nonce | string Will add |
Scrollbar
The vertical scrollbar. Add a second Scrollbar
with an orientation
prop to enable horizontal scrolling.
Prop | Default | Type |
---|---|---|
as | 'div' | AsTag | Component The element or component this component should render as. Can be overwrite by |
asChild | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
forceMount | boolean Used to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | |
orientation | 'vertical' | 'vertical' | 'horizontal' The orientation of the scrollbar |
Data Attribute | Value |
---|---|
[data-state] | "visible" | "hidden" |
[data-orientation] | "vertical" | "horizontal" |
Thumb
The thumb to be used in ScrollAreaScrollbar
.
Prop | Default | Type |
---|---|---|
as | 'div' | AsTag | Component The element or component this component should render as. Can be overwrite by |
asChild | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
Data Attribute | Value |
---|---|
[data-state] | "visible" | "hidden" |
Corner
The corner where both vertical and horizontal scrollbars meet.
Prop | Default | Type |
---|---|---|
as | 'div' | AsTag | Component The element or component this component should render as. Can be overwrite by |
asChild | boolean Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
Accessibility
In most cases, it's best to rely on native scrolling and work with the customization options available in CSS. When that isn't enough, ScrollArea
provides additional customizability while maintaining the browser's native scroll behavior (as well as accessibility features, like keyboard scrolling).
Keyboard Interactions
Scrolling via keyboard is supported by default because the component relies on native scrolling. Specific keyboard interactions may differ between platforms, so we do not specify them here or add specific event listeners to handle scrolling via key events.