Fragiola

API: components

ScrollArea

A natively scrolling area with custom scrollbars that drag, take a track press and report its overflow edges, as Base UI's ScrollArea, in each framework.

A scrolling container whose content scrolls natively (keyboard, wheel, touch, find-in-page) and whose scrollbars are parts you style: the thumb drags, the track takes a press, and every part reports how far the content overflows each edge. The APG has no scroll area pattern: it follows Base UI's ScrollArea (the behaviour rule).

Sidebar channels
Gallery

Behaviour

  • Native scrolling: the Viewport is the element that scrolls; its native scrollbars are hidden (scrollbar-width: none), and the keyboard, the wheel and touch scroll it as the browser does.
  • Scrollbars: one per axis, rendered only while that axis overflows (unless keepMounted). The thumb's size is the visible fraction of the track (at least 16 px), its position the scroll's fraction of its range. A thumb drag scrolls by its share of the track; a press on the track brings the thumb's center under the pointer, then drags; the wheel over a scrollbar scrolls its axis. A press on a scrollbar moves no focus.
  • Edges: data-overflow-x-start, -x-end, -y-start, -y-end and the matching --scroll-area-overflow-* distances (logical: the x start is the right edge in RTL), for a fade or a shadow at an edge; overflowEdgeThreshold sets how far from an edge counts.
  • Scrolling and hover: data-scrolling while the user scrolls (500 ms after the last scroll; a programmatic scroll sets none), data-hovering on the scrollbars while a mouse is over the area.
  • Focus: the Viewport takes a tab stop only while it overflows and holds nothing focusable, so a keyboard user can scroll it; a list of links needs none.
  • Measurement: on mount, on scroll, and when the viewport or the content resizes (ResizeObserver). A server render has no scrollbar and no overflow attribute; the first measurement after hydration adds them.

Anatomy

partelementdata-primitives-partrole
Rootdivscroll-area-rootthe box the scrollbars are placed in (role="presentation")
Viewportdivscroll-area-viewportthe element that scrolls
Contentdivscroll-area-contentthe scrolled content, measured (role="presentation")
Scrollbardivscroll-area-scrollbarthe track of one axis (aria-hidden)
Thumbdivscroll-area-thumbinside a Scrollbar
Cornerdivscroll-area-cornerwhere both scrollbars meet (aria-hidden)

Usage

import { ScrollArea } from "@fragiola/primitives-react/scroll-area";

<ScrollArea.Root className="h-64 w-56">
    <ScrollArea.Viewport role="region" aria-label="Channels">
        <ScrollArea.Content>{/* the long list */}</ScrollArea.Content>
    </ScrollArea.Viewport>
    <ScrollArea.Scrollbar orientation="vertical">
        <ScrollArea.Thumb />
    </ScrollArea.Scrollbar>
    <ScrollArea.Scrollbar orientation="horizontal">
        <ScrollArea.Thumb />
    </ScrollArea.Scrollbar>
    <ScrollArea.Corner />
</ScrollArea.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Vue binds them as props (:overflow-edge-threshold, keep-mounted), and Angular as inputs.

Root

proptypedefaultdescription
overflowEdgeThresholdnumber | { xStart?, xEnd?, yStart?, yEnd? }0how far, in pixels, the content must be scrolled from an edge before its data-overflow-* attribute is set

Viewport

No props of its own. Name it when its content needs a name (role="region" and aria-label).

Content

No props of its own.

Scrollbar

proptypedefaultdescription
orientation (react, vue)"vertical" | "horizontal""vertical"its axis
keepMounted (react, vue)booleanfalserendered even when its axis does not overflow
scrollAreaScrollbar (angular)"vertical" | "horizontal" | { orientation?, keepMounted? }"vertical"the structural directive's value: the axis, or both options

Thumb

No props of its own.

Corner

No props of its own.

State and part attributes

The overflow attributes are on the Root, the Viewport, the Content and each Scrollbar: data-has-overflow-x, data-has-overflow-y, data-overflow-x-start, data-overflow-x-end, data-overflow-y-start, data-overflow-y-end, and data-scrolling (a Scrollbar's and a Thumb's: their own axis).

partattributes
Rootrole="presentation"; --scroll-area-corner-width, --scroll-area-corner-height; structural position: relative
Viewporttabindex="0" while it overflows with nothing focusable in it; --scroll-area-overflow-x-start, -x-end, -y-start, -y-end (pixels to each edge); structural overflow: scroll, scrollbar-width: none
Contentrole="presentation"; structural min-width: fit-content
Scrollbararia-hidden="true", data-orientation, data-hovering; --scroll-area-thumb-height (vertical) or --scroll-area-thumb-width (horizontal); structural position: absolute at the inline end or the bottom, touch-action: none, user-select: none
Thumbdata-orientation, data-scrolling; structural height: var(--scroll-area-thumb-height) or width: var(--scroll-area-thumb-width), and the transform that places it
Corneraria-hidden="true"; structural position: absolute, width and height from the Root's corner variables

Keyboard

The browser's, on the Viewport: the arrows, Page Up, Page Down, Space, Home and End scroll it while it, or an element in it, has the focus. The scrollbars take no key and no focus.

Exports

entryexports
@fragiola/primitives-react/scroll-areaScrollArea, RenderProp, ScrollAreaContentProps, ScrollAreaCornerProps, ScrollAreaCornerState, ScrollAreaOrientation, ScrollAreaRootProps, ScrollAreaScrollbarProps, ScrollAreaScrollbarState, ScrollAreaState, ScrollAreaThreshold, ScrollAreaThresholdInput, ScrollAreaThumbProps, ScrollAreaThumbState, ScrollAreaViewportProps
@fragiola/primitives-vue/scroll-areaScrollArea, RenderSlotProps, ScrollAreaCornerState, ScrollAreaOrientation, ScrollAreaRootProps, ScrollAreaScrollbarProps, ScrollAreaScrollbarState, ScrollAreaState, ScrollAreaThreshold, ScrollAreaThresholdInput, ScrollAreaThumbState
@fragiola/primitives-angular/scroll-areaScrollAreaContent, ScrollAreaCorner, ScrollAreaOrientation, ScrollAreaRoot, ScrollAreaScrollbar, ScrollAreaScrollbarOptions, ScrollAreaScrollbarState, ScrollAreaState, ScrollAreaThreshold, ScrollAreaThresholdInput, ScrollAreaThumb, ScrollAreaThumbState, ScrollAreaViewport