Scroll Area Primitive
Use Scroll Area when a region needs to scroll within a fixed space. The scrollbar and thumb follow the position of the content.
Project 1
Project 2
Project 3
Project 4
Project 5
Project 6
Project 7
Project 8
Project 9
Project 10
Project 11
Project 12
Anatomy
Use the Astro primitive adapter to render ScrollArea anatomy with the Runtime wiring included.
---import { ScrollArea } from "@starwind-ui/astro/scroll-area";---
<ScrollArea.Root> <ScrollArea.Viewport> <ScrollArea.Content>Scrollable content</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Corner /></ScrollArea.Root>Use the React primitive adapter when ScrollArea state participates in React rendering.
import { ScrollArea } from "@starwind-ui/react/scroll-area";
export function Example() { return ( <ScrollArea.Root> <ScrollArea.Viewport> <ScrollArea.Content>Scrollable content</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Corner /> </ScrollArea.Root> );}Use the Vue components to build ScrollArea.
<script setup lang="ts">import ScrollArea from "@starwind-ui/vue/scroll-area";</script>
<template> <ScrollArea.Root> <ScrollArea.Viewport> <ScrollArea.Content>Scrollable content</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Corner /> </ScrollArea.Root></template>Use the Svelte components to build ScrollArea.
<script lang="ts"> import { ScrollArea } from "@starwind-ui/svelte/scroll-area";</script>
<ScrollArea.Root> <ScrollArea.Viewport> <ScrollArea.Content>Scrollable content</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Corner /></ScrollArea.Root>Render the ScrollArea data-sw-* contract yourself, then initialize createScrollArea.
<div data-sw-scroll-area role="presentation"> <div data-sw-scroll-area-viewport role="presentation" tabindex="-1" style="overflow: scroll;"> <div data-sw-scroll-area-content role="presentation">Scrollable content</div> </div> <div data-sw-scroll-area-scrollbar aria-hidden="true"> <div data-sw-scroll-area-thumb></div> </div> <div data-sw-scroll-area-corner aria-hidden="true"></div></div>
<script type="module"> import { createScrollArea } from "@starwind-ui/runtime/scroll-area";
const root = document.querySelector("[data-sw-scroll-area]"); if (root) { createScrollArea(root); }</script>Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed package’s types for the available props and events. Plain HTML uses DOM events and Runtime methods.
API Reference
Root
The main element that owns the Scroll Area Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-scroll-area
- Role
- presentation
Props
overflowEdgeThreshold number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number; }> -
- Description
- Configures the overflow edge threshold option for the Root part.
- Kind
- option
- Targets
- root
- Full type
- number | Partial<{ xStart: number; xEnd: number; yStart: number; yEnd: number; }>
Data Attributes
Runtime hooks
Metadata
Viewport
The visible viewport for Scroll Area content.
- Default element
- div
- Discovery hook
- data-sw-scroll-area-viewport
- Role
- presentation
Data Attributes
Runtime hooks
Content
The content container rendered by Scroll Area.
- Default element
- div
- Discovery hook
- data-sw-scroll-area-content
- Role
- presentation
Data Attributes
Runtime hooks
Scrollbar
A scrollbar used to scroll Scroll Area content.
- Default element
- div
- Discovery hook
- data-sw-scroll-area-scrollbar
- Role
- -
Props
keepMounted boolean false
- Description
- Keeps the Scrollbar part in the DOM when hidden.
- Kind
- rendering
- Targets
- scrollbar
- Full type
- boolean
orientation "horizontal" | "vertical" "vertical"
- Description
- Sets the Scroll Area orientation.
- Kind
- option
- Targets
- scrollbar
- Full type
- "horizontal" | "vertical"
Data Attributes
Runtime hooks
Metadata
Thumb
The draggable thumb for Scroll Area.
- Default element
- div
- Discovery hook
- data-sw-scroll-area-thumb
- Role
- -
Data Attributes
Runtime hooks
Corner
The corner where Scroll Area scrollbars meet.
- Default element
- div
- Discovery hook
- data-sw-scroll-area-corner
- Role
- -
Data Attributes
Runtime hooks
Runtime API
- Factory
createScrollArea- Import
@starwind-ui/runtime/scroll-area- Root hook
- root
data-sw-scroll-area - Option props
- overflowEdgeThreshold
Option Lifecycles
| Option | Lifecycle |
|---|---|
| overflowEdgeThreshold | refresh-required |
Related Styled Components
Changelog
View version history v1.1.0 7 releases
v1.1.0
- Scroll Area thumbs track RTL scroll positions in supported browsers.
- In Vue, this component now needs Vue 3.5.21 or newer.
v1.0.3
- In Astro, an attribute that you set on a Scroll Area part now wins over the part's own default for the same attribute, such as `role` or `aria-label`.
- In Svelte, the Scroll Area viewport no longer adds `!important` to its `overflow` style, so your own `style="overflow: hidden !important"` on the viewport now applies.
v1.0.2
- Internal maintenance. No change to how the component behaves.
- Reduced repeated JavaScript when Astro Scroll Area is used with other Starwind components.
v1.0.1
- Removed old comments from the Vue Primitive files that said the code was internal and not for release. The CLI also removes the blank line that these comments left in the Vue Primitive `index.ts` files that it copies into your project.
v1.0.0
- This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.
v0.1.1
- The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.
v0.1.0
- First release. Scroll Area measures its viewport and keeps the scrollbar, thumb, and corner parts in step with it.