A header that stays at the top as the page scrolls, and gains an edge once content passes under it.
- Add the registry
- Add scroll-header
Usage
ScrollHeader sticks to the top of the nearest scrolling container, or of the page, or of the
container given as root. It's transparent at rest, so it sits on the page like any other header.
Once the content after it scrolls beneath it, it gains a translucent surface and a hairline, and
has data-scrolled. The surface is the theme's surface color: the page's, or, inside a
Card, Dialog or Popover, that
container's.
The header takes its top corners from its parent, since browsers don't clip a blurred surface to
its container's rounded corners. In a rounded container, give any elements between the two
rounded-[inherit], as the example's scroll area has. In a Scroll Area,
turn off scrollFade, or the fade at its top edge covers the header.
It renders a <header>, which is the page's banner landmark when it isn't inside an <article>,
<aside>, <main>, <nav> or <section>. Give it render={<div />} when it heads a panel
rather than the page.
ScrollHeaderTitle repeats the page's heading, which you pass as watch. It slides up into the
header once that heading has scrolled under it. Screen readers skip it, since they already reach
the heading itself.
The header sets the container's scroll-padding-top to its own height, so a link to an anchor,
or a field that takes focus, lands below it rather than under it. Pass scrollPadding={false} to
leave the container alone.
Composition
Props
The header waits for the page's first paint before it animates, using the use-settled hook,
which installs with it. That way its background and title don't fade in when the page loads
already scrolled.
Base UI's styling (opens in a new tab) and composition (opens in a new tab) guides say more about className, style and render.