Command palette

@yasinsensoy/web

Web · Components

ScrollArea

Scrollable area.

3 exports

Live example

Preview

tag-01
tag-02
tag-03
tag-04
tag-05
tag-06
tag-07
tag-08
tag-09
tag-10
tag-11
tag-12
tag-13
tag-14
tag-15
tag-16
tag-17
tag-18
tag-19
tag-20
tag-21
tag-22
tag-23
tag-24
tag-25
tag-26
tag-27
tag-28
tag-29
tag-30
tag-31
tag-32
tag-33
tag-34
tag-35
tag-36
tag-37
tag-38
tag-39
tag-40

On devices with a mouse the bar sits over the content and only appears while scrolling or when the pointer nears the edge; it takes no width. On touch screens the browser's bar is used. The page's own bar looks the same (UIProvider).

Code

import { ScrollArea, UIProvider } from "@yasinsensoy/web";

<ScrollArea label="Tags" className="h-64 rounded-md border" viewportClassName="p-4">
  {tags.map((t) => <div key={t}>{t}</div>)}
</ScrollArea>

// To go back to the native bar across the app:
<UIProvider scrollbar="native">…</UIProvider>

Events

  1. Events appear here when you interact with the preview.

Import

import { ScrollArea } from "@yasinsensoy/web";

ScrollArea

componentClient component

Scrollable area. Instead of the classic scrollbar on Windows and Linux, it draws a thin bar that sits over the content and appears only while scrolling or when the pointer reaches the edge; like on mobile and macOS it takes no width. Scrolling itself is native (wheel, touchpad, keyboard, find in page, scroll links); the bar can be dragged and clicking the track scrolls one page.

The same bar is drawn on touch screens (appears when scrolling with a finger, the thumb can be dragged). In Windows high contrast mode the browser's native bar is used. To go back to the native bar across the app, <UIProvider scrollbar="native">.

Give the height to the area itself (h-64, max-h-96, flex-1…); for content classes like padding use viewportClassName.

You don't need to do anything for the page's own bar; UIProvider sets it up. Dialog, Sheet and Table also use this bar in their scroll areas.

ScrollArea({ orientation, label, viewportClassName, viewportRef, className, children, ...props }: ScrollAreaProps): JSX.Element

Examples

<ScrollArea className="h-72 rounded-md border" viewportClassName="p-4" label="Tags">
  {tags.map((t) => <p key={t}>{t}</p>)}
</ScrollArea>

// Horizontal scrolling
<ScrollArea orientation="horizontal" className="w-full">
  <div className="flex w-max gap-4">…</div>
</ScrollArea>

Scroll direction.

type ScrollOrientation = "vertical" | "horizontal" | "both"

Props of the ScrollArea component.

Extends: ComponentProps<"div">

NameTypeDefaultDescription
orientation?ScrollOrientation"vertical"Which direction to scroll.
label?stringScreen reader name of the area. If given, the area can be focused with the keyboard and scrolled with arrow keys (recommended if there is no focusable element inside).
viewportClassName?stringClasses of the element that holds the content and actually scrolls (e.g. padding).
viewportRef?Ref<HTMLDivElement>Ref of the element that actually scrolls (e.g. to call scrollTo).