Skip to main content

Scroll Area

A native scroll area for bounded overflow: popup lists, dialog bodies, wide tables, carousels and removable-chip rows. Never use it for a whole page or a reading column.

import { ScrollArea } from '@fairgarden/design/data/scroll-area'

The viewport is the browser's own scroller, and its scrollbar is the native one, colored by the scope: the thumb is the rule color, the track is the surface's own opaque color, and hovering the area steps the thumb to the heading ink. The scrollbar keeps the platform's width, and in forced colors it takes the system colors. Overflow is also shown by a hard 2 px rule on each side that has hidden content, never by a fade. The viewport is focusable whenever it scrolls; give it a label to make it a named region. Set focusable={false} when the content's own items are the focus stops and scroll themselves into view, as in a tab list.

Panel, wide and rail

Panel, wide and rail

panel is the default: it scrolls vertically, always keeps its scrollbar's gutter, so content that grows or filters never moves sideways, and it caps at half the viewport height; maxBlockSize sets another cap, such as the space a popup's positioner reports. wide scrolls horizontally and snaps to its content's snap points when near one; the Table uses it. rail scrolls horizontally and always snaps, for carousels; pair it with Prev and Next buttons and an "n of N" count. A horizontal scrollbar takes its room in the first paint whenever the content overflows, and an overlay scrollbar takes none. With fitContent={false} the content keeps the viewport's width and its children overflow it, so a carousel track's slide percentages resolve against the viewport.

Panel

  • American Goldfinch
  • Barn Swallow
  • Belted Kingfisher
  • Black-capped Chickadee
  • Cedar Waxwing
  • Common Yellowthroat
  • Eastern Bluebird
  • Great Blue Heron
  • Indigo Bunting
  • Northern Cardinal
  • Red-winged Blackbird
  • Song Sparrow
  • Tree Swallow
  • Wood Thrush

Wide

  1. Jan
  2. Feb
  3. Mar
  4. Apr
  5. May
  6. Jun
  7. Jul
  8. Aug
  9. Sep
  10. Oct
  11. Nov
  12. Dec

Rail

  1. American Goldfinch
  2. Barn Swallow
  3. Belted Kingfisher
  4. Black-capped Chickadee
  5. Cedar Waxwing
  6. Common Yellowthroat
  7. Eastern Bluebird
  8. Great Blue Heron
import { ScrollArea } from '@fairgarden/design/data/scroll-area'
import styles from './kinds.module.css'

const species = [
  'American Goldfinch',
  'Barn Swallow',
  'Belted Kingfisher',
  'Black-capped Chickadee',
  'Cedar Waxwing',
  'Common Yellowthroat',
  'Eastern Bluebird',
  'Great Blue Heron',
  'Indigo Bunting',
  'Northern Cardinal',
  'Red-winged Blackbird',
  'Song Sparrow',
  'Tree Swallow',
  'Wood Thrush',
]

const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

/** Panel (vertical), wide (horizontal, proximity snap) and rail (horizontal, mandatory snap). */
export function ScrollAreaKinds() {
  return (
    <div className={styles.stack}>
      <section className={styles.example}>
        <h3 className={styles.name}>Panel</h3>
        <ScrollArea label="Species seen" className={styles.panel}>
          <ul className={styles.list}>
            {species.map((name) => (
              <li key={name}>{name}</li>
            ))}
          </ul>
        </ScrollArea>
      </section>
      <section className={styles.example}>
        <h3 className={styles.name}>Wide</h3>
        <ScrollArea kind="wide" label="Monthly visits">
          <ol className={styles.row}>
            {months.map((month) => (
              <li key={month} className={styles.cell}>
                {month}
              </li>
            ))}
          </ol>
        </ScrollArea>
      </section>
      <section className={styles.example}>
        <h3 className={styles.name}>Rail</h3>
        <ScrollArea kind="rail" label="Featured preserves">
          <ol className={styles.row}>
            {species.slice(0, 8).map((name) => (
              <li key={name} className={styles.slide}>
                {name}
              </li>
            ))}
          </ol>
        </ScrollArea>
      </section>
    </div>
  )
}

Overflow edges

Each edge rule follows the viewport's scroll position through a scroll-driven animation, so it needs no script where the browser supports one. Elsewhere, a small effect writes data-overflow-x-start, data-overflow-x-end and data-has-overflow-x (or the y ones on a panel) on the root, and only there. The viewport names its scroll timeline --scroll-area-inline (wide, rail) or --scroll-area-block (panel). A composed component that reads it outside the root, as the Table's scroll cue does, scopes that name on its own element and sets the root's timeline-scope to none. --scroll-area-edge-start: none on the root hides the start edge, for a pinned column that draws its own; --scroll-area-overscroll-x and --scroll-area-overscroll-y set the viewport's scroll chaining, and --scroll-area-scroll-padding-inline its inline scroll padding, which insets the snapport. On wide and rail it defaults to 16 px (--size-px-3), the demos' item gap, so a snapped or focused item rests one gap inside the edge rule and the item before it clears the edge with no sliver showing; set it to your row's own gap or inset. The Carousel sets its start to 0 and its end to the bleed, so slides snap on the content line they rest on.

Removed from the Base UI Scroll Area

The Scroll Area no longer wraps Base UI's. These parts, props, attributes and variables are gone:

  • Parts: ScrollArea.Scrollbar, ScrollArea.Thumb and ScrollArea.Corner, with the module's scrollbar, thumb and corner classes.
  • Root props: overflowEdgeThreshold, render, and the state-function forms of className and style. The root takes plain div props.
  • Attributes: data-scrolling on every part; data-hovering and data-orientation on the scrollbar, and data-orientation on the thumb; data-has-overflow-x, data-has-overflow-y and data-overflow-{x,y}-{start,end} on the viewport, the content and the scrollbar. The root keeps its overflow attributes only where scroll-driven animations are missing.
  • CSS variables: --scroll-area-corner-height, --scroll-area-corner-width, --scroll-area-thumb-height, --scroll-area-thumb-width and --scroll-area-overflow-{x,y}-{start,end}, and the module's --scroll-area-gutter and --scroll-area-thumb.
  • Inline styles: the viewport's overflow: scroll and the content's min-width: fit-content, now plain module rules. The viewport's role="presentation" is gone too.

In print

Overflow is removed: the content prints at full height and width, and the edge rules are hidden.

API Reference

A native scroll area: the browser’s own scrollbar, in the scope’s thumb and track colors, and a hard --border-size-2 --role-rule edge on each side with hidden content, never a fade [D21, D68, D207]. Content prints at full height with the edges hidden. Don’t nest two scroll areas on the same axis.

PropTypeDescription
label
string | undefined

Accessible name for the scrollable region. Given, the viewport becomes a named region; the viewport is focusable whenever it scrolls.

contentClassName
string | undefined

Class for the content wrapper, the layout box of the children.

fitContent
boolean | undefined

true (default): the content is at least as wide as its children, so wide content scrolls. false: the content keeps the viewport’s width and its children overflow it, so their percentages resolve against the viewport (a carousel track).

focusable
boolean | undefined

true (default): the viewport joins the tab order whenever it scrolls, so a keyboard can scroll it (§10.19). false keeps it out, for content whose own items are the focus stops and scroll themselves into view (a tab list).

kind
'panel' | 'wide' | 'rail' | null | undefined

panel (default): vertical; its scrollbar gutter is always reserved; the area caps at 50% of the viewport height (maxBlockSize changes the cap). wide: horizontal, with proximity snap (wide tables). rail: horizontal, with mandatory snap (carousels and removable-chip rows).

maxBlockSize
string | number | undefined

The area’s maximum block size, a CSS length such as calc(var(--available-height) - 2px) (a number is px). Default: 50dvh for panel, none for wide and rail.

primary
| 'ruby'
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| null
| undefined

Primary Radix scale: every part (thumb, edges, focus ring). Never defaulted; omitted, it inherits the scope [D133].

secondary
| 'ruby'
| 'olive'
| 'sage'
| 'slate'
| 'sand'
| 'gray'
| 'mauve'
| 'brown'
| 'bronze'
| 'gold'
| 'red'
| 'crimson'
| 'tomato'
| 'pink'
| 'plum'
| 'indigo'
| 'iris'
| 'violet'
| 'purple'
| 'amber'
| 'blue'
| 'cyan'
| 'grass'
| 'green'
| 'jade'
| 'lime'
| 'mint'
| 'orange'
| 'sky'
| 'teal'
| 'yellow'
| null
| undefined

Secondary Radix scale: unused by the scroll area. Never defaulted.

viewportRef
React.Ref<HTMLDivElement> | undefined

Ref to the scrolling viewport, e.g. to scroll it from Prev/Next buttons.

scrollArea
ScrollAreaProps

Props for ScrollArea: div props for the root plus the kind and color axes.

type ScrollAreaProps = React.ClassAttributes<HTMLDivElement> &
  React.HTMLAttributes<HTMLDivElement> & {
    kind?: 'panel' | 'wide' | 'rail' | null;
    primary?:
      | 'ruby'
      | 'olive'
      | 'sage'
      | 'slate'
      | 'sand'
      | 'gray'
      | 'mauve'
      | 'brown'
      | 'bronze'
      | 'gold'
      | 'red'
      | 'crimson'
      | 'tomato'
      | 'pink'
      | 'plum'
      | 'indigo'
      | 'iris'
      | 'violet'
      | 'purple'
      | null;
    secondary?:
      | 'ruby'
      | 'olive'
      | 'sage'
      | 'slate'
      | 'sand'
      | 'gray'
      | 'mauve'
      | 'brown'
      | 'bronze'
      | 'gold'
      | 'red'
      | 'crimson'
      | 'tomato'
      | 'pink'
      | 'plum'
      | 'indigo'
      | 'iris'
      | 'violet'
      | 'purple'
      | 'amber'
      | 'blue'
      | 'cyan'
      | 'grass'
      | 'green'
      | 'jade'
      | 'lime'
      | 'mint'
      | 'orange'
      | 'sky'
      | 'teal'
      | 'yellow'
      | null;
    label?: string;
    viewportRef?: React.Ref<HTMLDivElement>;
    contentClassName?: string;
    maxBlockSize?: string | number;
    focusable?: boolean;
    fitContent?: boolean;
  }

Specification: DESIGN-SYSTEM.md §10.19 (scroll area) and D207 (native scrollbars).