rule 17 — platform defaults

A scroll container is a positioning context

A class list with overflow-auto, overflow-x-auto, overflow-y-auto or overflow-scroll also carries relative (or absolute, fixed, sticky), so an absolutely positioned descendant — the hidden input inside every Checkbox, Radio and Switch — is laid out inside the box that scrolls, not inside a frame above it.

warnlintposition-scroll-containers

platform defaults

The platform will do it for you. That is not the same as your app doing it.

what this catches

An agent makes a panel scroll by writing `overflow-y-auto` and stops there, because the panel scrolls and nothing on screen says otherwise. The visually hidden input inside a toggle is `position: absolute`, so its containing block is whatever positioned ancestor sits above the panel — and when a click focuses that input, the browser scrolls that ancestor to reveal it, even when it is `overflow-hidden`. The frame slides up and leaves a blank band, on the first click, in a component nobody touched.

why

Focusing an element scrolls every scrollable ancestor until the element is in view, and `overflow: hidden` is scrollable — it hides the scrollbar, not the scroll position, so `scrollTop` moves when the browser asks it to. A hidden input that is laid out against a clipping frame instead of against the scroll box it visually sits in is, from the browser's point of view, an element below the frame's fold; focusing it scrolls the frame, and the frame has no scrollbar to scroll it back with.

react-aria's Checkbox, Radio and Switch each render their real `<input>` visually hidden, with `position: absolute`, so that it is focusable and announced without being seen. An absolutely positioned element is laid out against its nearest positioned ancestor. ui-lib's controls are positioned at their root, so inside the library the input stays where the control is — but a scroll container you write yourself, with a custom row or a third-party widget in it, is only safe if the container is positioned too, because then nothing inside it can be laid out against anything above it.

`relative` on a box that is not otherwise positioned changes nothing you can see: it moves nothing, and it only changes where absolutely positioned descendants measure from — which, for a box that scrolls, is the box they should have been measuring from anyway. The other three position values already establish the context, so a class list carrying any of them passes.

This is a warning rather than an error for the one case where adding `relative` is not free: an absolutely positioned descendant that was deliberately anchored to an ancestor outside the scroll box — a badge pinned to the corner of the card around it, say — moves when the scroll box becomes its containing block. That is worth a look before the class goes in, which is a judgement the linter cannot make for you.

wrong / right

The dialog body that scrolled its own frame

Was real code in src/components/dialog.tsx (DialogBody), until it was fixed

don't

const DialogBody = ({ className, ...props }) => (
  <div
    data-slot="dialog-body"
    className={cn("isolate flex min-h-0 flex-1 flex-col overflow-auto px-(--gutter) py-1", className)}
    {...props}
  />
)

do

const DialogBody = ({ className, ...props }) => (
  <div
    data-slot="dialog-body"
    className={cn("relative isolate flex min-h-0 flex-1 flex-col overflow-auto px-(--gutter) py-1", className)}
    {...props}
  />
)

The modal frame around this body was `relative overflow-hidden`, so it was the nearest positioned ancestor of every hidden input in the body. Clicking the last checkbox in a tall dialog scrolled the frame rather than the body. ui-lib now positions both the body and the control root, and clips its frames with `overflow-clip`, which cannot be scrolled at all — this rule is the half that a scroll box of your own still needs.

A settings list that scrolls inside a card

don't

<Card>
  <div className="max-h-80 overflow-y-auto">
    {settings.map((s) => (
      <Switch key={s.id} defaultSelected={s.on}>{s.label}</Switch>
    ))}
  </div>
</Card>

do

<Card>
  <div className="relative max-h-80 overflow-y-auto">
    {settings.map((s) => (
      <Switch key={s.id} defaultSelected={s.on}>{s.label}</Switch>
    ))}
  </div>
</Card>

One class. With it, anything absolutely positioned inside the list — a control's hidden input, a row's drag handle, a third-party widget's own visually hidden field — is laid out inside the box that scrolls.

how to check this

Add one of these to your project and the rule holds without anyone having to remember it — including the agent writing half the JSX. The exceptions below are already applied, so a documented carve-out will not be reported.

What it will and will not catch: The check reads one string literal at a time, so the position class has to be in the same string as the overflow class: `cn("fixed", "overflow-y-auto")` is reported even though the element is positioned. Repeat the position class in the second string — cn() merges the duplicate away. A class list built from a template literal slips past it, like every class-string check here. The grep finds every scroll container, positioned or not, so read its hits rather than counting them.

Biome — GritQL plugin

biome

Biome has no built-in rule for this one, so it ships as a GritQL plugin. Save it as ui-lib-rules/position-scroll-containers.grit and load it from an `overrides` entry — the one in the file's own header, which lists the paths the rule applies to (app/**/*.{tsx,jsx}, src/**/*.{tsx,jsx}) and the paths its documented exceptions carve back out. Not from the top-level `plugins`: a plugin listed there runs against every file you lint, and an override can add one but cannot take one away. If your project keeps its components somewhere else, edit the `includes` to match.

// A scroll container is a positioning context
// AUTO-GENERATED from https://ui-lib.quebi.de/api/rules/position-scroll-containers.json — do not edit by hand.
//
// https://ui-lib.quebi.de/rules/position-scroll-containers
//
// This file says what the rule is, not where it applies. A plugin listed in
// the top-level `plugins` runs against every file Biome lints, so scope it
// with an `overrides` entry — Biome resolves `includes` against the project
// root, which is the one thing a $filename regex in here could not do:
//
//   {
//     "overrides": [
//       {
//         "includes": [
//           "app/**/*.{tsx,jsx}",
//           "src/**/*.{tsx,jsx}"
//         ],
//         "plugins": [
//           "./ui-lib-rules/position-scroll-containers.grit"
//         ]
//       }
//     ]
//   }

language js;

or { string(), JsxString() } as $classes where {
  $classes <: includes "overflow-",
  $classes <: r".*(?:^|[^\w-])overflow-(?:[xy]-)?(?:auto|scroll)(?:$|[^\w-]).*",
  $classes <: not r".*(?:^|[^\w-])(?:relative|absolute|fixed|sticky)(?:$|[^\w-]).*",
  register_diagnostic(
    span = $classes,
    message = "A scroll container without a position class. The hidden input inside a Checkbox, Radio or Switch is position: absolute, so it is laid out against the nearest positioned ancestor above this box; focusing it makes the browser scroll that ancestor, even an overflow-hidden frame, and the frame slides out from under the content. Add relative to the same class string (absolute, fixed or sticky also count). See https://ui-lib.quebi.de/rules/position-scroll-containers",
    severity = "warn"
  )
}

ripgrep — no setup at all

ripgrep

Finds candidates for review in any repo, linter or not. Coarser than the Biome check: it reads lines, not syntax, so expect false positives and treat a clean run as weaker evidence than a clean lint run.

# position-scroll-containers — candidates for review
rg -n -g '*.{jsx,tsx}' \
  "overflow-(x-|y-)?(auto|scroll)\\b"

Enforcing more than this one rule? Take the whole config instead of collecting snippets.

exceptions

Carve-outs are part of the rule, not a way around it. Each one is already an ignore glob in the checks above, so the cases listed here need no disable comment — and a case that is not listed is one to argue for, not to silence.

None
Every case this rule covers has a replacement that is an import, so there is nothing here that a documented carve-out would be honest about. A case it gets wrong is one to argue for on the record, not to silence with a suppression comment.

scope and enforcement

Applies to
  • app/**/*.{tsx,jsx}
  • src/**/*.{tsx,jsx}
Enforced by
lint