Scroll Area
Consistent scroll area across platforms.
Scroll Area
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.
Structure
Reusable Components
If you're planning to use the Scroll Area throughout your application, it's recommended to create a reusable component to reduce the amount of code you need to write each time.
This example shows you how to create a Scroll Area component that accepts a few custom props that make it more capable.
We'll use this custom component in the following examples to demonstrate how to customize the behavior of the Scroll Area.
Scroll Area Types
Hover
The hover
type is the default type of the scroll area, demonstrated in the featured example above. It only shows scrollbars when the user hovers over the scroll area and the content is larger than the viewport.
Scroll Area
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.
Scroll
The scroll
type displays the scrollbars when the user scrolls the content. This is similar to the behavior of MacOS.
Scroll Area
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.
Auto
The auto
type behaves similarly to your typical browser scrollbars. When the content is larger than the viewport, the scrollbars will appear and remain visible at all times.
Scroll Area
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.
Always
The always
type behaves as if you set overflow: scroll
on the scroll area. Scrollbars will always be visible, even when the content is smaller than the viewport. We've also set the orientation
prop on the CustomScrollArea
to 'both'
to ensure both scrollbars are rendered.
Scroll Area
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.
Customizing the Hide Delay
You can customize the hide delay of the scrollbars using the scrollHideDelay
prop.
Scroll Area
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Dignissimos impedit rem, repellat deserunt ducimus quasi nisi voluptatem cumque aliquid esse ea deleniti eveniet incidunt! Deserunt minus laborum accusamus iusto dolorum. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Blanditiis officiis error minima eos fugit voluptate excepturi eveniet dolore et, ratione impedit consequuntur dolorem hic quae corrupti autem? Dolorem, sit voluptatum.
API Reference
The container of all scroll area components. Overflow is hidden on this element to prevent double scrollbars.
Property | Type | Description |
---|---|---|
type | enum | The type of scroll area. Default: 'hover' |
scrollHideDelay | number | The delay in milliseconds before the scroll area hides itself when using Default: 600 |
dir | enum | The reading direction of the app. Default: ltr |
child | Snippet | Use render delegation to render your own element. See render delegation for more information. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
ref | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-scroll-area-root | —— | Present on the root element. |
The component which wraps the content and is responsible for computing the scroll area size.
Property | Type | Description |
---|---|---|
ref | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-scroll-area-viewport | —— | Present on the viewport element. |
A scrollbar of the scroll area.
Property | Type | Description |
---|---|---|
orientation Required | enum | The orientation of the scrollbar. Default: undefined |
forceMount | boolean | Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animnation library for the content. Default: false |
child | Snippet | Use render delegation to render your own element. See render delegation for more information. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
ref | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The visibility state of the scrollbar |
data-scroll-area-scrollbar-x | —— | Present on |
data-scroll-area-scrollbar-y | —— | Present on the |
A thumb of a scrollbar in the scroll area.
Property | Type | Description |
---|---|---|
forceMount | boolean | Whether or not to forcefully mount the content. This is useful if you want to use Svelte transitions or another animnation library for the content. Default: false |
child | Snippet | Use render delegation to render your own element. See render delegation for more information. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
ref | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-state | enum | The visibility state of the scrollbar |
data-scroll-area-thumb-x | —— | Present on |
data-scroll-area-thumb-y | —— | Present on the |
The corner element between the X and Y scrollbars.
Property | Type | Description |
---|---|---|
child | Snippet | Use render delegation to render your own element. See render delegation for more information. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
ref | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-scroll-area-corner | —— | Present on the corner element. |