Scroll Area
A native scroll container with custom scrollbars.
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
import styles from './index.module.css';
</script>
<template>
<ScrollArea.Root :class="styles.ScrollArea">
<ScrollArea.Viewport :class="styles.Viewport">
<ScrollArea.Content :class="styles.Content">
<p :class="styles.Paragraph">
Vernacular architecture is building done outside any academic tradition, and without
professional guidance. It is not a particular architectural movement or style, but rather
a broad category, encompassing a wide range and variety of building types, with differing
methods of construction, from around the world, both historical and extant and classical
and modern. Vernacular architecture constitutes 95% of the world's built environment, as
estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
buildings every year designed by architects and built by engineers.
</p>
<p :class="styles.Paragraph">
This type of architecture usually serves immediate, local needs, is constrained by the
materials available in its particular region and reflects local traditions and cultural
practices. The study of vernacular architecture does not examine formally schooled
architects, but instead that of the design skills and tradition of local builders, who
were rarely given any attribution for the work. More recently, vernacular architecture has
been examined by designers and the building industry in an effort to be more energy
conscious with contemporary design and construction—part of a broader interest in
sustainable design.
</p>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar :class="styles.Scrollbar">
<ScrollArea.Thumb :class="styles.Thumb" />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
</template>.ScrollArea {
box-sizing: border-box;
width: 24rem;
height: 8.5rem;
max-width: calc(100vw - 8rem);
background-color: white;
@media (prefers-color-scheme: dark) {
background-color: oklch(14.5% 0 0deg);
}
}
.Viewport {
box-sizing: border-box;
height: 100%;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Content {
display: flex;
flex-direction: column;
gap: 1rem;
padding-block: 0.5rem;
padding-left: 0.75rem;
padding-right: 1.25rem;
}
.Paragraph {
margin: 0;
font-size: 0.875rem;
line-height: 1.375rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Scrollbar {
display: flex;
justify-content: center;
background-color: rgb(0 0 0 / 12%);
width: 1rem;
margin: 1px;
opacity: 0;
transition: opacity 150ms;
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: rgb(255 255 255 / 12%);
}
&[data-scrolling] {
transition-duration: 0ms;
}
&[data-scrolling] {
opacity: 1;
pointer-events: auto;
}
@media (hover: hover) {
.ScrollArea:hover & {
opacity: 1;
pointer-events: auto;
}
}
}
.Thumb {
width: 100%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>
<template>
<ScrollArea.Root
class="group h-[8.5rem] w-96 max-w-[calc(100vw-8rem)] bg-white dark:bg-neutral-950"
>
<ScrollArea.Viewport
class="h-full border border-neutral-950 dark:border-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
<ScrollArea.Content
class="flex flex-col gap-4 py-2 pr-5 pl-3 text-sm leading-[1.375rem] text-neutral-950 dark:text-white"
>
<p>
Vernacular architecture is building done outside any academic tradition, and without
professional guidance. It is not a particular architectural movement or style, but rather
a broad category, encompassing a wide range and variety of building types, with differing
methods of construction, from around the world, both historical and extant and classical
and modern. Vernacular architecture constitutes 95% of the world's built environment, as
estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
buildings every year designed by architects and built by engineers.
</p>
<p>
This type of architecture usually serves immediate, local needs, is constrained by the
materials available in its particular region and reflects local traditions and cultural
practices. The study of vernacular architecture does not examine formally schooled
architects, but instead that of the design skills and tradition of local builders, who
were rarely given any attribution for the work. More recently, vernacular architecture has
been examined by designers and the building industry in an effort to be more energy
conscious with contemporary design and construction—part of a broader interest in
sustainable design.
</p>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar
class="m-px flex w-4 justify-center bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0 data-scrolling:pointer-events-auto"
>
<ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
</template>Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>
<template>
<ScrollArea.Root>
<ScrollArea.Viewport>
<ScrollArea.Content />
</ScrollArea.Viewport>
<ScrollArea.Scrollbar>
<ScrollArea.Thumb />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>
</template>Examples
Both scrollbars
Use <ScrollArea.Corner> so that the two scrollbars do not cross.
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
import styles from './index.module.css';
</script>
<template>
<ScrollArea.Root :class="styles.ScrollArea">
<ScrollArea.Viewport :class="styles.Viewport">
<ScrollArea.Content :class="styles.Content">
<ul :class="styles.Grid">
<li v-for="i in 100" :key="i" :class="styles.Item">{{ i }}</li>
</ul>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar :class="styles.Scrollbar">
<ScrollArea.Thumb :class="styles.Thumb" />
</ScrollArea.Scrollbar>
<ScrollArea.Scrollbar :class="styles.Scrollbar" orientation="horizontal">
<ScrollArea.Thumb :class="styles.Thumb" />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>
</template>.ScrollArea {
box-sizing: border-box;
width: 20rem;
height: 20rem;
max-width: calc(100vw - 8rem);
}
.Viewport {
box-sizing: border-box;
height: 100%;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Content {
padding: 0.75rem 1.5rem 1.5rem 0.75rem;
}
.Grid {
display: grid;
grid-template-columns: repeat(10, 6.25rem);
grid-template-rows: repeat(10, 6.25rem);
gap: 0.75rem;
margin: 0;
padding: 0;
list-style: none;
}
.Item {
background-color: oklch(92.2% 0 0deg);
display: flex;
align-items: center;
justify-content: center;
font-size: 0.875rem;
font-weight: 700;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
color: oklch(70.8% 0 0deg);
}
}
.Scrollbar {
display: flex;
position: relative;
background-color: rgb(0 0 0 / 12%);
margin: 1px;
opacity: 0;
transition: opacity 150ms;
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: rgb(255 255 255 / 12%);
}
&[data-scrolling] {
transition-duration: 0ms;
}
&[data-scrolling] {
opacity: 1;
pointer-events: auto;
}
@media (hover: hover) {
.ScrollArea:hover & {
opacity: 1;
pointer-events: auto;
}
}
&[data-orientation='vertical'] {
width: 1rem;
}
&[data-orientation='horizontal'] {
height: 1rem;
}
}
.Thumb {
width: 100%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>
<template>
<ScrollArea.Root class="group h-80 w-80 max-w-[calc(100vw-8rem)]">
<ScrollArea.Viewport
class="h-full border border-neutral-950 dark:border-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
<ScrollArea.Content class="pt-3 pr-6 pb-6 pl-3">
<ul
class="m-0 grid list-none grid-cols-[repeat(10,6.25rem)] grid-rows-[repeat(10,6.25rem)] gap-3 p-0"
>
<li
v-for="i in 100"
:key="i"
class="flex items-center justify-center bg-neutral-200 dark:bg-neutral-800 text-sm font-bold text-neutral-600 dark:text-neutral-400"
>
{{ i }}
</li>
</ul>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar
class="relative m-px flex bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-[orientation=vertical]:w-4 data-[orientation=horizontal]:h-4 group-hover:pointer-events-auto group-hover:opacity-100 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0"
>
<ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
</ScrollArea.Scrollbar>
<ScrollArea.Scrollbar
class="relative m-px flex bg-black/12 dark:bg-white/12 opacity-0 transition-opacity pointer-events-none data-[orientation=vertical]:w-4 data-[orientation=horizontal]:h-4 group-hover:pointer-events-auto group-hover:opacity-100 data-scrolling:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0"
orientation="horizontal"
>
<ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
</ScrollArea.Scrollbar>
<ScrollArea.Corner />
</ScrollArea.Root>
</template>Gradient scroll fade
Use the overflow CSS variables of the viewport in a CSS mask. The fade then grows as the user scrolls away from an edge.
The server HTML has no value for the variables. A var() with no fallback then makes the mask invalid, and the browser shows no fade. To show the fade before the hydration, give each var() a fallback. Use 0px for the start edge, and the size of the fade for the end edge.
The viewport writes the variables at each scroll, and each element in it inherits them. With thousands of elements in the viewport, the browser can then need some milliseconds in a frame. Register the variables with inherits: false. Then set each variable that a child uses to inherit:
@property --scroll-area-overflow-y-start {
syntax: '<length>';
inherits: false;
initial-value: 0px;
}
.Child {
--scroll-area-overflow-y-start: inherit;
}Before the measurement, a registered variable has its initial-value, not the fallback of var().
<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
import styles from './index.module.css';
</script>
<template>
<ScrollArea.Root :class="styles.ScrollArea">
<ScrollArea.Viewport :class="styles.Viewport">
<ScrollArea.Content :class="styles.Content">
<p :class="styles.Paragraph">
Vernacular architecture is building done outside any academic tradition, and without
professional guidance. It is not a particular architectural movement or style, but rather
a broad category, encompassing a wide range and variety of building types, with differing
methods of construction, from around the world, both historical and extant and classical
and modern. Vernacular architecture constitutes 95% of the world's built environment, as
estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
buildings every year designed by architects and built by engineers.
</p>
<p :class="styles.Paragraph">
This type of architecture usually serves immediate, local needs, is constrained by the
materials available in its particular region and reflects local traditions and cultural
practices. The study of vernacular architecture does not examine formally schooled
architects, but instead that of the design skills and tradition of local builders, who
were rarely given any attribution for the work. More recently, vernacular architecture has
been examined by designers and the building industry in an effort to be more energy
conscious with contemporary design and construction—part of a broader interest in
sustainable design.
</p>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar :class="styles.Scrollbar">
<ScrollArea.Thumb :class="styles.Thumb" />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
</template>.ScrollArea {
box-sizing: border-box;
width: 24rem;
height: 12rem;
max-width: calc(100vw - 8rem);
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
&:has(.Viewport:focus-visible) {
outline: 2px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Viewport {
--fade-size: 40px;
height: 100%;
background: oklch(97% 0 0deg);
mask-image: linear-gradient(
to bottom,
transparent 0,
black min(var(--fade-size), var(--scroll-area-overflow-y-start)),
black calc(100% - min(var(--fade-size), var(--scroll-area-overflow-y-end, var(--fade-size)))),
transparent 100%
);
mask-repeat: no-repeat;
outline: none;
@media (prefers-color-scheme: dark) {
background: oklch(26.9% 0 0deg);
}
}
.Content {
display: flex;
flex-direction: column;
gap: 1rem;
padding-block: 0.5rem;
padding-left: 0.75rem;
padding-right: 1.25rem;
}
.Paragraph {
margin: 0;
font-size: 0.875rem;
line-height: 1.375rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Scrollbar {
display: flex;
justify-content: center;
background-color: rgb(0 0 0 / 8%);
width: 1rem;
margin: 1px;
opacity: 0;
transition: opacity 150ms;
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: rgb(255 255 255 / 12%);
}
&[data-scrolling] {
transition-duration: 0ms;
}
&[data-scrolling] {
opacity: 1;
pointer-events: auto;
}
@media (hover: hover) {
.ScrollArea:hover & {
opacity: 1;
pointer-events: auto;
}
}
}
.Thumb {
width: 100%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}<script setup lang="ts">
import { ScrollArea } from '@vase-ui/vue/scroll-area';
</script>
<template>
<ScrollArea.Root
class="group h-48 w-96 max-w-[calc(100vw-8rem)] bg-neutral-100 dark:bg-neutral-800 has-[>_:first-child:focus-visible]:outline-2 has-[>_:first-child:focus-visible]:outline-offset-0 has-[>_:first-child:focus-visible]:outline-neutral-950 dark:has-[>_:first-child:focus-visible]:outline-white"
>
<ScrollArea.Viewport
class="h-full bg-neutral-100 dark:bg-neutral-800 outline-none mask-linear-[to_bottom,transparent_0,black_min(40px,var(--scroll-area-overflow-y-start)),black_calc(100%_-_min(40px,var(--scroll-area-overflow-y-end,40px))),transparent_100%] mask-no-repeat"
>
<ScrollArea.Content
class="flex flex-col gap-4 py-2 pr-5 pl-3 text-sm leading-[1.375rem] text-neutral-950 dark:text-white"
>
<p>
Vernacular architecture is building done outside any academic tradition, and without
professional guidance. It is not a particular architectural movement or style, but rather
a broad category, encompassing a wide range and variety of building types, with differing
methods of construction, from around the world, both historical and extant and classical
and modern. Vernacular architecture constitutes 95% of the world's built environment, as
estimated in 1995 by Amos Rapoport, as measured against the small percentage of new
buildings every year designed by architects and built by engineers.
</p>
<p>
This type of architecture usually serves immediate, local needs, is constrained by the
materials available in its particular region and reflects local traditions and cultural
practices. The study of vernacular architecture does not examine formally schooled
architects, but instead that of the design skills and tradition of local builders, who
were rarely given any attribution for the work. More recently, vernacular architecture has
been examined by designers and the building industry in an effort to be more energy
conscious with contemporary design and construction—part of a broader interest in
sustainable design.
</p>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar
class="m-px flex w-4 justify-center bg-black/8 dark:bg-white/12 opacity-0 transition-opacity duration-150 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto data-scrolling:opacity-100 data-scrolling:duration-0 data-scrolling:pointer-events-auto"
>
<ScrollArea.Thumb class="w-full bg-neutral-950 dark:bg-white" />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
</template>API reference
ScrollArea.Root
Groups all parts of the scroll area. It hides the native scrollbars of the viewport. With the
element slot, the server HTML has no style element, so the native scrollbars show until the
mount.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
overflowEdgeThreshold | number | { xStart?: number | undefined; xEnd?: number | undefined; yStart?: number | undefined; yEnd?: number | undefined; } | undefined | 0 | The distance in pixels from an edge within which the edge has no overflow state. A number is for
each edge. A missing or negative number is 0. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ScrollAreaRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ScrollAreaRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-scrolling] | The user scrolls, with a wheel, a touch, the keyboard or a drag. It ends 500 ms after the last scroll. A scroll of a script does not count. |
[data-has-overflow-x] | The content overflows the viewport on the horizontal axis. |
[data-has-overflow-y] | The content overflows the viewport on the vertical axis. |
[data-overflow-x-start] | The content overflows the inline start edge. |
[data-overflow-x-end] | The content overflows the inline end edge. |
[data-overflow-y-start] | The content overflows the top edge. |
[data-overflow-y-end] | The content overflows the bottom edge. |
CSS variables
| Variable | Description |
|---|---|
--scroll-area-corner-width | The width of the corner, in pixels. It is 0px with no corner. |
--scroll-area-corner-height | The height of the corner, in pixels. It is 0px with no corner. |
ScrollArea.Viewport
The actual scrollable container of the scroll area. It is a native scroll container on the two
axes, so the wheel, a touch, the keyboard and scroll snap work as in each browser. It is a tab
stop while it can scroll. When it is a landmark of the page, give it role="region" and a name,
such as aria-label.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ScrollAreaRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ScrollAreaRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-scrolling] | The user scrolls, with a wheel, a touch, the keyboard or a drag. It ends 500 ms after the last scroll. A scroll of a script does not count. |
[data-has-overflow-x] | The content overflows the viewport on the horizontal axis. |
[data-has-overflow-y] | The content overflows the viewport on the vertical axis. |
[data-overflow-x-start] | The content overflows the inline start edge. |
[data-overflow-x-end] | The content overflows the inline end edge. |
[data-overflow-y-start] | The content overflows the top edge. |
[data-overflow-y-end] | The content overflows the bottom edge. |
CSS variables
| Variable | Description |
|---|---|
--scroll-area-overflow-x-start | The distance to the inline start edge of the content, in pixels. |
--scroll-area-overflow-x-end | The distance to the inline end edge of the content, in pixels. |
--scroll-area-overflow-y-start | The distance to the top edge of the content, in pixels. |
--scroll-area-overflow-y-end | The distance to the bottom edge of the content, in pixels. |
ScrollArea.Content
A container for the content of the scroll area.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ScrollAreaRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ScrollAreaRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-scrolling] | The user scrolls, with a wheel, a touch, the keyboard or a drag. It ends 500 ms after the last scroll. A scroll of a script does not count. |
[data-has-overflow-x] | The content overflows the viewport on the horizontal axis. |
[data-has-overflow-y] | The content overflows the viewport on the vertical axis. |
[data-overflow-x-start] | The content overflows the inline start edge. |
[data-overflow-x-end] | The content overflows the inline end edge. |
[data-overflow-y-start] | The content overflows the top edge. |
[data-overflow-y-end] | The content overflows the bottom edge. |
ScrollArea.Scrollbar
A vertical or horizontal scrollbar for the scroll area. It lies over the viewport and takes no
space. Assistive technology does not read it. It renders while its axis has overflow. To show it
at a hover, select :hover of the root.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
keepMounted | boolean | undefined | false | The scrollbar renders also while its axis has no overflow, in the server HTML too. Hide such a
scrollbar with :not([data-has-overflow-y]) or :not([data-has-overflow-x]). |
orientation | "vertical" | "horizontal" | undefined | 'vertical' | The axis that the scrollbar scrolls. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ScrollAreaScrollbarState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ScrollAreaScrollbarState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The axis of the scrollbar: vertical or horizontal. |
[data-scrolling] | The user scrolls the axis of the scrollbar. |
[data-has-overflow-x] | The content overflows the viewport on the horizontal axis. |
[data-has-overflow-y] | The content overflows the viewport on the vertical axis. |
[data-overflow-x-start] | The content overflows the inline start edge. |
[data-overflow-x-end] | The content overflows the inline end edge. |
[data-overflow-y-start] | The content overflows the top edge. |
[data-overflow-y-end] | The content overflows the bottom edge. |
CSS variables
| Variable | Description |
|---|---|
--scroll-area-thumb-height | The length of the thumb of a vertical scrollbar, in pixels. It counts the padding of the scrollbar and the margins of the thumb. |
--scroll-area-thumb-width | The length of the thumb of a horizontal scrollbar, in pixels. It counts the padding of the scrollbar and the margins of the thumb. |
ScrollArea.Thumb
The draggable part of the scrollbar that indicates the current scroll position. It moves with
the CSS property translate, so transform stays free for your styles. Give a horizontal thumb
equal inline margins: in right-to-left text, the part counts the start margin two times in WebKit.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: ScrollAreaThumbState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: ScrollAreaThumbState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-orientation] | The axis of the scrollbar: vertical or horizontal. |
[data-scrolling] | The user scrolls the axis of the thumb. |
ScrollArea.Corner
A small rectangular area that appears at the intersection of horizontal and vertical scrollbars.
It renders while the two axes have overflow. Assistive technology does not read it.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. | |
element | props: Record<string, unknown>elementRef: (target: unknown) => void | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Differences from Base UI
Vase UI ports Scroll Area from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
ScrollArea.Scrollbar | CSS :hover of the root gives the same hook, so the state has no hovering, and the scrollbar has no data-hovering. |
ScrollArea.Corner | ScrollAreaCornerState holds no field, so the corner gives no state and no state type. |
Behavior
| Vase UI | Evidence |
|---|---|
| When two scroll area parts of one kind are mounted, the last one added serves, and the one before it serves again when it leaves. When the corner leaves, the tracks get its width and height back. Base UI reads one ref for each part, and it writes the corner size only while a corner exists. | |
When the content of a viewport becomes empty and the auto height of the viewport decreases to 0, the root measures the viewport. The parts lose data-has-overflow-y, --scroll-area-overflow-y-end becomes 0px, the scrollbar unmounts and the viewport leaves the tab order. Base UI skips a viewport whose scroll height or scroll width is 0, so it keeps the old overflow, the scrollbar and tabindex=0. |
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.