---name: fix-scrolldescription: Find and fix the 6 scroll and overlay bugs that make web apps feel broken: overflow:hidden containers scrolling crooked on Tab focus, ancestors silently killing position:sticky, modal scroll locks shifting the navbar 15px sideways, scroll chaining bleeding behind modals and sidebars, showModal() auto-focus jerking sheets open, and clipped popovers. Works on any React, Next.js, Vue, Svelte, Astro, or plain CSS/Tailwind app.license: MITmetadata: author: Hairline UI url: https://hairlineui.com/skills/fix-scroll version: "1.0.0"---# /fix-scrollFind and fix the six scroll and overlay defects hiding inside almost every web app: `overflow: hidden` panels silently scrolling themselves crooked when a user presses `Tab`, ancestors killing `position: sticky`, modals deleting the scrollbar and jolting the navbar 15px sideways, scroll chaining bleeding through sidebars/drawers onto the page behind them, `showModal()` jerking sheets open, and dropdowns sliced in half by cards.This skill is **zero-redesign and zero-lock-in**. It leaves your visual design, layout, and component library untouched and verifies every fix in real Chromium.## Guardrails (never break these)- **Never replace a real scroll container (`overflow: auto` / `overflow: scroll`) with `overflow: clip`.** Only replace `overflow: hidden` where the intent is visual clipping (cards, modals, accordions, animated stages, page wrappers), never where the user is supposed to scroll.- **Never lock background scroll by toggling `overflow: hidden` on `<html>` or `<body>`.** That shifts the layout by the scrollbar width on Windows/Linux and triggers heavy full-DOM restyles. Use static `scrollbar-gutter: stable` + overlay scroll interception instead.- **Keep keyboard accessibility intact.** Moving initial dialog focus to the panel itself (`tabIndex={-1}`) preserves Escape and Tab trapping without yanking off-screen controls into view.- **Never add external libraries.** Every fix is standard CSS, HTML, and DOM events.- **Never report a fix you did not verify in Chromium.**---## Step 1 — Measure the baseline (browser + source scan)### 1A. Run the Chromium scroll & overlay verifier (recommended)With your local dev server running, fetch and run the standalone verifier across your main routes:```bashcurl -sL https://hairlineui.com/skills/fix-scroll-check.mjs -o /tmp/fix-scroll-check.mjsnode /tmp/fix-scroll-check.mjs http://localhost:3000 --routes /,/dashboard,/settings```*(On Windows PowerShell: `curl.exe -sL https://hairlineui.com/skills/fix-scroll-check.mjs -o $env:TEMP\fix-scroll-check.mjs` then `node $env:TEMP\fix-scroll-check.mjs http://localhost:3000`.)*Save the baseline counts: `overflow: hidden` Tab-focus scrolls, broken `position: sticky` elements, missing `scrollbar-gutter: stable` / modal navbar shifts, scroll-chaining containers missing `overscroll-behavior: contain`, and `<dialog>` roots using `overflow: hidden`.### 1B. Static source scan```bashG='-g *.{tsx,jsx,ts,js,vue,svelte,astro,html,css} -g !node_modules -g !.next -g !dist'# 1. overflow: hidden on page wrappers, dialogs, cards, and animated panels (check if overflow-clip fits)rg -n '\b(overflow-hidden|overflow-x-hidden|overflow-y-hidden)\b|overflow(-x|-y)?:\s*hidden' $G .# 2. Sticky elements (check every ancestor above them for overflow-hidden / overflow-x-hidden / overflow-auto)rg -n '\bsticky\b|position:\s*sticky' $G .# 3. Scrollable drawers, sidebars, modals, and panels potentially missing overscroll-containrg -n '\b(overflow-y-auto|overflow-auto|overflow-y-scroll)\b' $G . | rg -v 'overscroll-contain'# 4. Modal scroll locks mutating html/body overflow (causes 15px scrollbar jump + restyle stall)rg -n '(documentElement|body)\.style\.(overflow|overflowY|paddingRight)\s*=' $G .# 5. Check whether scrollbar-gutter: stable is declared in global CSSrg -n 'scrollbar-gutter\s*:\s*stable' -g '*.css' -g '!node_modules' -g '!.next' -g '!dist' .```---## Step 2 — Fix each class of bug cleanly### 2.1 `overflow: hidden` silently scrolling crooked on Tab focusMost developers do not realize `overflow: hidden` is still a **programmatically scrollable** container. If an input, button, or animated child sits near or past the edge of an `overflow: hidden` card, sheet, or fold, pressing `Tab` (or calling `.focus()`) causes the browser to scroll that container to reveal it — leaving the card permanently offset with no scrollbar to get back.- **Fix:** Replace `overflow: hidden` (`overflow-hidden`) with **`overflow: clip`** (`overflow-clip`) on: - Cards, panels, and rounded frames - Collapsible accordions and grid-row folds (`grid-template-rows: 0fr -> 1fr`, paired with `inert` when closed so Tab skips hidden controls completely) - `<dialog>` and drawer/sheet roots - Page wrappers (`overflow-x-clip`)- `overflow: clip` forbids all scrolling — user **and** programmatic — so focusing can never displace the content.### 2.2 Ancestors silently breaking `position: sticky`Any ancestor between a `position: sticky` element and the viewport that has `overflow: hidden`, `overflow: auto`, or `overflow: scroll` (even only on `overflow-x: hidden`!) creates a new scroll container and stops `position: sticky` from sticking to the window.- **Fix:** Replace `overflow-x: hidden` (`overflow-x-hidden`) on `<main>`, layout shells, and page wrappers with **`overflow-x: clip`** (`overflow-x-clip`). Unlike `hidden`, `clip` does not create a scroll container, so every sticky header, sidebar, and table header works as expected.### 2.3 Scrollbar disappear shifting the navbar 15px sidewaysOn Windows, Linux, and macOS with scrollbars enabled, switching between a short route and a long route — or opening a modal that hides the page scrollbar — widens the viewport by ~15px and jolts the entire header and centered layout sideways.- **Fix (2 parts):** 1. Reserve the gutter once in global CSS: ```css html { scrollbar-gutter: stable; } ``` 2. Stop toggling `document.documentElement.style.overflow = 'hidden'` when opening dialogs or drawers. Instead, put `overscroll-behavior: contain` on the scrollable overlay content and prevent `wheel` / `touchmove` on the backdrop so the background page stays locked with zero layout reflow and zero horizontal jump.### 2.4 Scroll chaining bleeding behind modals, sidebars, and chat drawersWhen a visitor scrolls to the top or bottom of a scrollable modal, sidebar, dropdown list, or chat transcript, the browser chains the remaining wheel/touch momentum straight into the main page behind it.- **Fix:** Add **`overscroll-behavior: contain`** (`overscroll-contain`) to every independent scrollable container (`overflow-y-auto`, drawers, dialogs, sidebars, command palettes, code viewers, dropdown menus).### 2.5 `showModal()` jerking off-screen sheets & popping mobile keyboardsCalling `dialog.showModal()` automatically focuses the first focusable control inside the dialog. If the sheet slides in from off-screen inside an `overflow: hidden` root, the browser scrolls the container to that control mid-entrance (jerking the sheet) and pops the software keyboard on phones.- **Fix:** - Use `overflow: clip` (`overflow-clip`) on the dialog/sheet root. - Put `tabIndex={-1}` on the dialog panel itself and focus the panel on open (`panelRef.current?.focus({ preventScroll: true })`) instead of auto-focusing the first `<input>`. - Restore focus cleanly to the trigger button when closing via `Escape` or backdrop click.### 2.6 Clipped dropdowns/popovers & fighting auto-scroll- **Clipped dropdowns:** Render popovers, tooltips, and select listboxes in a portal (or outside `overflow: hidden` / `overflow: clip` cards) with viewport collision padding so menus are never sliced in half by a parent card.- **Auto-scroll fighting the user (chat / log streams):** Only pin to bottom while the user is already near the bottom, and disengage auto-scroll as soon as a recent user `wheel`, `touchmove`, `keydown`, or scrollbar interaction scrolls upward (never treat content height shrinking as a user scroll-up).---## Step 3 — Verify every fix in Chromium1. Run your project's typecheck and build.2. Re-run the verifier across the same routes: ```bash node /tmp/fix-scroll-check.mjs http://localhost:3000 --routes /,/dashboard,/settings ```3. Confirm: - `0` `overflow: hidden` containers that scroll on Tab/focus. - `0` `position: sticky` elements killed by an `overflow: hidden` ancestor. - `0px` navbar/viewport shift when opening modals or switching routes. - `0` independent scroll regions missing `overscroll-behavior: contain`.---## Step 4 — Report (keep it tight)```text/fix-scroll — verified in Chromium overflow:hidden Tab-focus traps: 4 → 0 (switched to overflow-clip + inert) Broken position:sticky elements: 2 → 0 (wrapper overflow-x-hidden → overflow-x-clip) Modal scrollbar navbar shift: 15px → 0px (scrollbar-gutter: stable + overlay lock) Scroll-chaining containers: 7 → 0 (added overscroll-contain) Dialog roots with overflow:hidden: 2 → 0 (overflow-clip + panel focus)Files changed:- src/app/globals.css — added html { scrollbar-gutter: stable }- src/app/layout.tsx — replaced overflow-x-hidden with overflow-x-clip- src/components/Accordion.tsx — overflow-clip + inert on collapsed content- src/components/Sidebar.tsx — added overscroll-contain on scrollable navNot checked:- Authenticated admin routes behind /admin```