Scroll Area
A box that scrolls its content, with thin scrollbars in the colours of the style. It is the browser's own scrolling, so touch, wheel, keyboard and find-in-page all work. Same markup and props in every style: switch the style in the header to see it change.
Vertical
A fixed-height list that scrolls up and down. Click it or Tab to it, then use the arrow keys, Page Up/Down, Home and End.
Releases
<div class="vin-scroll-area" role="region" aria-label="Releases" tabindex="0" style="width: 100%; max-width: 240px; height: 220px">
<div style="padding: 12px 16px">
<p style="margin: 0 0 8px; font-weight: 600">Releases</p>
<div style="padding: 6px 0">v2.4.0</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.3.1</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.3.0</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.2.0</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.1.2</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.1.1</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.1.0</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v2.0.0</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v1.9.0</div>
<hr class="vin-separator">
<div style="padding: 6px 0">v1.8.0</div>
</div>
</div>Releases
import { Fragment } from "react";
import { ScrollArea } from "@/components/vin/scroll-area";
import { Separator } from "@/components/vin/separator";
const releases = ["v2.4.0", "v2.3.1", "v2.3.0", "v2.2.0", "v2.1.2", "v2.1.1", "v2.1.0", "v2.0.0", "v1.9.0", "v1.8.0"];
export function ScrollAreaVertical() {
return (
<ScrollArea label="Releases" style={{ width: "100%", maxWidth: 240, height: 220 }}>
<div style={{ padding: "12px 16px" }}>
<p style={{ margin: "0 0 8px", fontWeight: 600 }}>Releases</p>
{releases.map((r, i) => (
<Fragment key={r}>
{i > 0 && <Separator />}
<div style={{ padding: "6px 0" }}>{r}</div>
</Fragment>
))}
</div>
</ScrollArea>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import ScrollArea from "@/components/vin/scroll-area.vue";
import Separator from "@/components/vin/separator.vue";
const releases = ["v2.4.0", "v2.3.1", "v2.3.0", "v2.2.0", "v2.1.2", "v2.1.1", "v2.1.0", "v2.0.0", "v1.9.0", "v1.8.0"];
</script>
<template>
<ScrollArea label="Releases" style="width: 100%; max-width: 240px; height: 220px">
<div style="padding: 12px 16px">
<p style="margin: 0 0 8px; font-weight: 600">Releases</p>
<template v-for="(r, i) in releases" :key="r">
<Separator v-if="i > 0" />
<div style="padding: 6px 0">{{ r }}</div>
</template>
</div>
</ScrollArea>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import ScrollArea from "$lib/components/vin/scroll-area.svelte";
import Separator from "$lib/components/vin/separator.svelte";
const releases = ["v2.4.0", "v2.3.1", "v2.3.0", "v2.2.0", "v2.1.2", "v2.1.1", "v2.1.0", "v2.0.0", "v1.9.0", "v1.8.0"];
</script>
<ScrollArea label="Releases" style="width: 100%; max-width: 240px; height: 220px">
<div style="padding: 12px 16px">
<p style="margin: 0 0 8px; font-weight: 600">Releases</p>
{#each releases as r, i (r)}
{#if i > 0}<Separator />{/if}
<div style="padding: 6px 0">{r}</div>
{/each}
</div>
</ScrollArea>Horizontal
A row wider than its box, like a shelf of cards. Shift + wheel, a trackpad swipe or the arrow keys scroll it sideways.
24 tracks
18 tracks
31 tracks
42 tracks
15 tracks
<div class="vin-scroll-area vin-scroll-area--horizontal" role="region" aria-label="Playlists" tabindex="0" style="width: 100%; max-width: 400px">
<div style="display: flex; gap: 12px; width: max-content; padding: 16px">
<figure style="margin: 0; width: 120px">
<div style="aspect-ratio: 1; border-radius: var(--vin-radius); background: linear-gradient(135deg, var(--vin-accent), color-mix(in srgb, var(--vin-accent) 35%, var(--vin-surface)))"></div>
<figcaption style="margin-top: 8px">Morning focus<br><span style="color: var(--vin-muted)">24 tracks</span></figcaption>
</figure>
<figure style="margin: 0; width: 120px">
<div style="aspect-ratio: 1; border-radius: var(--vin-radius); background: linear-gradient(200deg, color-mix(in srgb, var(--vin-accent) 70%, var(--vin-fg)), color-mix(in srgb, var(--vin-accent) 45%, var(--vin-surface)))"></div>
<figcaption style="margin-top: 8px">Deep work<br><span style="color: var(--vin-muted)">18 tracks</span></figcaption>
</figure>
<figure style="margin: 0; width: 120px">
<div style="aspect-ratio: 1; border-radius: var(--vin-radius); background: linear-gradient(45deg, color-mix(in srgb, var(--vin-accent) 25%, var(--vin-surface)), var(--vin-accent))"></div>
<figcaption style="margin-top: 8px">Late night<br><span style="color: var(--vin-muted)">31 tracks</span></figcaption>
</figure>
<figure style="margin: 0; width: 120px">
<div style="aspect-ratio: 1; border-radius: var(--vin-radius); background: linear-gradient(160deg, color-mix(in srgb, var(--vin-accent) 55%, var(--vin-surface)), color-mix(in srgb, var(--vin-accent) 80%, var(--vin-fg)))"></div>
<figcaption style="margin-top: 8px">Road trip<br><span style="color: var(--vin-muted)">42 tracks</span></figcaption>
</figure>
<figure style="margin: 0; width: 120px">
<div style="aspect-ratio: 1; border-radius: var(--vin-radius); background: linear-gradient(90deg, var(--vin-accent), color-mix(in srgb, var(--vin-accent) 20%, var(--vin-surface)))"></div>
<figcaption style="margin-top: 8px">Sunday<br><span style="color: var(--vin-muted)">15 tracks</span></figcaption>
</figure>
</div>
</div>24 tracks
18 tracks
31 tracks
42 tracks
15 tracks
import { ScrollArea } from "@/components/vin/scroll-area";
const mix = (pct: number, other: string) => `color-mix(in srgb, var(--vin-accent) ${pct}%, ${other})`;
const playlists = [
{ name: "Morning focus", tracks: 24, art: `linear-gradient(135deg, var(--vin-accent), ${mix(35, "var(--vin-surface)")})` },
{ name: "Deep work", tracks: 18, art: `linear-gradient(200deg, ${mix(70, "var(--vin-fg)")}, ${mix(45, "var(--vin-surface)")})` },
{ name: "Late night", tracks: 31, art: `linear-gradient(45deg, ${mix(25, "var(--vin-surface)")}, var(--vin-accent))` },
{ name: "Road trip", tracks: 42, art: `linear-gradient(160deg, ${mix(55, "var(--vin-surface)")}, ${mix(80, "var(--vin-fg)")})` },
{ name: "Sunday", tracks: 15, art: `linear-gradient(90deg, var(--vin-accent), ${mix(20, "var(--vin-surface)")})` },
];
export function ScrollAreaHorizontal() {
return (
<ScrollArea orientation="horizontal" label="Playlists" style={{ width: "100%", maxWidth: 400 }}>
<div style={{ display: "flex", gap: 12, width: "max-content", padding: 16 }}>
{playlists.map((p) => (
<figure key={p.name} style={{ margin: 0, width: 120 }}>
<div style={{ aspectRatio: 1, borderRadius: "var(--vin-radius)", background: p.art }} />
<figcaption style={{ marginTop: 8 }}>
{p.name}
<br />
<span style={{ color: "var(--vin-muted)" }}>{p.tracks} tracks</span>
</figcaption>
</figure>
))}
</div>
</ScrollArea>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import ScrollArea from "@/components/vin/scroll-area.vue";
const mix = (pct: number, other: string) => `color-mix(in srgb, var(--vin-accent) ${pct}%, ${other})`;
const playlists = [
{ name: "Morning focus", tracks: 24, art: `linear-gradient(135deg, var(--vin-accent), ${mix(35, "var(--vin-surface)")})` },
{ name: "Deep work", tracks: 18, art: `linear-gradient(200deg, ${mix(70, "var(--vin-fg)")}, ${mix(45, "var(--vin-surface)")})` },
{ name: "Late night", tracks: 31, art: `linear-gradient(45deg, ${mix(25, "var(--vin-surface)")}, var(--vin-accent))` },
{ name: "Road trip", tracks: 42, art: `linear-gradient(160deg, ${mix(55, "var(--vin-surface)")}, ${mix(80, "var(--vin-fg)")})` },
{ name: "Sunday", tracks: 15, art: `linear-gradient(90deg, var(--vin-accent), ${mix(20, "var(--vin-surface)")})` },
];
</script>
<template>
<ScrollArea orientation="horizontal" label="Playlists" style="width: 100%; max-width: 400px">
<div style="display: flex; gap: 12px; width: max-content; padding: 16px">
<figure v-for="p in playlists" :key="p.name" style="margin: 0; width: 120px">
<div :style="{ aspectRatio: 1, borderRadius: 'var(--vin-radius)', background: p.art }" />
<figcaption style="margin-top: 8px">
{{ p.name }}
<br />
<span style="color: var(--vin-muted)">{{ p.tracks }} tracks</span>
</figcaption>
</figure>
</div>
</ScrollArea>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import ScrollArea from "$lib/components/vin/scroll-area.svelte";
const mix = (pct: number, other: string) => `color-mix(in srgb, var(--vin-accent) ${pct}%, ${other})`;
const playlists = [
{ name: "Morning focus", tracks: 24, art: `linear-gradient(135deg, var(--vin-accent), ${mix(35, "var(--vin-surface)")})` },
{ name: "Deep work", tracks: 18, art: `linear-gradient(200deg, ${mix(70, "var(--vin-fg)")}, ${mix(45, "var(--vin-surface)")})` },
{ name: "Late night", tracks: 31, art: `linear-gradient(45deg, ${mix(25, "var(--vin-surface)")}, var(--vin-accent))` },
{ name: "Road trip", tracks: 42, art: `linear-gradient(160deg, ${mix(55, "var(--vin-surface)")}, ${mix(80, "var(--vin-fg)")})` },
{ name: "Sunday", tracks: 15, art: `linear-gradient(90deg, var(--vin-accent), ${mix(20, "var(--vin-surface)")})` },
];
</script>
<ScrollArea orientation="horizontal" label="Playlists" style="width: 100%; max-width: 400px">
<div style="display: flex; gap: 12px; width: max-content; padding: 16px">
{#each playlists as p (p.name)}
<figure style="margin: 0; width: 120px">
<div style="aspect-ratio: 1; border-radius: var(--vin-radius); background: {p.art}"></div>
<figcaption style="margin-top: 8px">
{p.name}
<br />
<span style="color: var(--vin-muted)">{p.tracks} tracks</span>
</figcaption>
</figure>
{/each}
</div>
</ScrollArea>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add scroll-areaimport { ScrollArea } from "@/components/vin/scroll-area";import ScrollArea from "@/components/vin/scroll-area.vue";import ScrollArea from "$lib/components/vin/scroll-area.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.
API
From spec/scroll-area.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
orientationWhich way the content scrolls. | verticalhorizontalboth | vertical | vin-scroll-area--horizontal / vin-scroll-area--both |
labelA name for the region, read by screen readers. Needed when nothing inside can take focus, so the box itself is in the Tab order. | string | — | role="region" aria-label="…" tabindex="0" |
childrenThe content. Give the box a height (or a width) so it has something to scroll. | ReactNode | — | the content of div.vin-scroll-area |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<ScrollArea> | .vin-scroll-area.vin-scroll-area--horizontal.vin-scroll-area--both |
Accessibility
- It is native scrolling: nothing is faked, so the wheel, touch, the keyboard and assistive technology work as on any page.
- The box has tabindex="0", so keyboard users can focus it and scroll with the arrow keys, Page Up/Down and Home/End. A focus ring shows when it has focus.
- Because it can take focus, it has a name: role="region" with an aria-label (React: label) that says what is inside.
- Scrollbars are thin, but they stay visible and draggable, in the style's colours.
Customize
Saved in this browser. Style and accent are in the header.