ScrollContainer

ScrollContainer

HkScrollContainer is the library's scroll host: a box that turns its default slot into the one scroll region of a surface, replaces the native scrollbar with the overlay chrome, and senses the live scroll geometry so that whatever the host hangs around the edge — a fade, a glow, a dock, a back-to-top signal — can react to it. Use it wherever content outgrows its box and the surrounding layout must not move.

  • For a card whose body scrolls inside its own chrome, use HkCard with scrollable; the card owns the scroll there.
  • To pin a toolbar or a step header against the edge while the content scrolls under it, put it in HkScrollPin inside this container, not in an absolutely positioned wrapper.
  • To name the visible row band of a list that is scrolling, wrap the content in HkScrollProgressDock.
  • Edge fades and glows are painted by HkEdgeGlow; this container mounts it for you while fade or overflowGlow is on.

Import

tsx
1
import { HkScrollContainer } from "@celestia-island/hikari";

This page documents the Vue implementation only: packages/components/src ships no Rust scroll container, so every example below is TSX.

Axis, overflow and the fade

axis picks the scroll direction — vertical (the default), horizontal or both. The container writes the sensed overflow per axis onto its root as data-h-overflow / data-v-overflow, each one of none / start / end / both, so a host can style an edge affordance in pure CSS. The sense uses a 1px deadband, so a sub-pixel layout never reports overflow.

fade masks the viewport on the sides where content still hides. fadeDistance (default 96) is the hidden distance in pixels over which a lit band deepens from a hard cut to the full band, so pulling the strip grows the trailing fade and scrolling back recedes it; 0 or a negative value degrades to the binary shape where any lit edge jumps straight to the full band.

A container needs a bounded box from its context — a grid stretch, a max-height, a flex parent — otherwise there is nothing to scroll.

TSX

Line one.

Line two.

Line three.

Line four.

Line five.

OneTwoThreeFourFiveSix

The horizontal example is the case the overlay scrollbar and the inline-axis fades exist for: a strip wider than its box. align="center" is also valid there and centres content that fits while overflowing content falls back to the inline start — the safe centring justify-content: center cannot give, because it clips instead of scrolling.

Docks, selection hints and the overflow glow

Three opt-ins ride the sense. overflowGlow lights the physical edges that still hide content and breathes, for surfaces that removed the native bar and must still say "there is more"; selectionHint lights the top or bottom edge when a descendant matching selectionSelector (by default aria-current, aria-selected="true" or .is-active) lies outside the visible band. Both mount the shared HkEdgeGlow painter as a non-scrolling child of the root, which is why the band never scrolls away with the content.

dockTop / dockBottom slots hold a dock that stays pinned while the content scrolls: in the default dockMode="pin" the dock is a non-scrolling flex sibling of the viewport, so the viewport shrinks by its height and the leftover window height shows under short content. dockMode="ride" instead mounts the bottom dock inside the flow, after the content, behind a block spacer of exactly the measured dock height — short content trails the dock directly under itself, long content gets the same air at the scroll end. Ride is ignored on axis="horizontal", and it is documented as unsupported together with autoFollow.

TSX

Line one.

Line two.

Line three.

Line four.

Line five.

12 rows · pinned dock

A pinned dock is a flex sibling: the box you give the container is the whole surface, the dock takes its own height out of it, and the content scrolls in what is left. dockFade is on by default and applies to a pinned dock: the bottom edge dissolves under it mid-scroll, then the band retires once the last row is flush, so a parked list is not permanently shaded.

Keyboard, naming and the exposed API

keyboardScroll (on by default) makes the viewport focusable with tabindex="0" and handles arrows, PageUp / PageDown, Home and End — but only while the viewport itself holds focus, so an inner input or button keeps its own keys. A held modifier bails out, so IME and browser zoom are untouched. scrollRole and scrollLabel name the viewport; use a non-live role such as region for streaming content, because log and feed announce every appended line.

The component exposes an imperative surface: scrollTo, scrollToElement, scrollToEnd, scrollToStart, getScrollElement, getScrollTop, refresh, getOverflow, isNearEnd, recheck and a backTopVisible ref. approachEnd plus approachDistance emit approachEnd when the viewport comes within the threshold of its vertical end — the infinite-loading hook. Both are interactive features, so they have no still example here.

API

Vue

Props

NameTypeDefaultRequired
asString"div"—
axisString as PropType<ScrollAxis>"vertical"—
modeString as PropType<ScrollMode>"traditional"—
scrollbarBooleantrue—
markersArray as PropType<OverlayScrollbarMarker[]>() => []—
markersWidthNumberundefined—
mapSegmentsArray as PropType<OverlayScrollMapSegment[]>undefined—
autoFollowBooleanfalse—
keyboardScrollBooleantrue—
scrollRoleStringundefined—
scrollLabelStringundefined—
overscanScreensNumber1—
alignString as PropType<ScrollAlign>"start"—
anchor<code>String as PropType<"start" | "end"></code>"start"—
fadeBooleanfalse—
fadeDistanceNumber96—
overflowGlowBooleanfalse—
followAffordanceBooleanfalse—
approachEndBooleanfalse—
approachDistanceNumber160—
dockFadeBooleantrue—
dockTailClearanceBooleanfalse—
dockMode<code>String as PropType<"pin" | "ride"></code>"pin"—
backTopShowNumberundefined—
backTopHideNumberundefined—
selectionHintBooleanfalse—
selectionSelectorString'[aria-current]:not([aria-current="false"]), [aria-selected="true"], .is-active'—

Emits

EventPayload
approachEnd—
update:backTopVisibleboolean

Accessibility

  • The viewport is focusable by default (keyboardScroll), which is what lets a keyboard user reach the scroll region at all; turning it off trades compliance for one less tab stop.
  • scrollRole and scrollLabel are the viewport's aria surface. A scrollable region with neither is unnamed: give a scroll region that holds distinct content scrollRole="region" and a scrollLabel so it appears in a screen reader's landmark list.
  • Prefer a non-live role for content that keeps growing. log and feed carry implicit live semantics and would read out every appended line as it arrives.
  • Home and End jump to the start and end of the viewport without changing focus, so the scroll position can move while the keyboard focus stays put.
  • The overlay scrollbar is chrome; the region's scrolling is still the browser's own, so a keyboard or screen-reader user is never blocked by the painted bar.

Related components

  • HkScrollPin — sticky content inside this container's viewport, with a whitespace contract.
  • HkScrollProgressDock — the pill that names the visible row band of a list inside the viewport.
  • HkEdgeGlow — the shared edge painter this container mounts for fade and overflowGlow.
  • HkCard — a smaller surface that scrolls its own body.