Scroll Auto Hide

Component that hides and reveals fixed areas based on scroll direction

ScrollAutoHide hides a fixed area when scrolling down. When scrolling up, it reveals it again by the same distance. It's suitable for areas where you want more content space, like filters, tabs, and secondary headers.

Installation

Dependency:

npm install @radix-ui/react-compose-refs @radix-ui/react-slot

Snippet:

npx @seed-design/cli@latest add breeze:scroll-auto-hide

Usage

Pass the ref of the element where scrolling occurs to scrollContainerRef. Since the component applies position: sticky and top: 0, it must be placed inside the scroll container.

const scrollContainerRef = useRef<HTMLDivElement>(null);

return (
  <div ref={scrollContainerRef} style={{ height: 480, overflowY: "auto" }}>
    <ScrollAutoHide scrollContainerRef={scrollContainerRef}>
      <nav>Filters</nav>
    </ScrollAutoHide>
    <main>{/* Content to scroll */}</main>
  </div>
);

Using a Different Element as Root

Use asChild to use the child element as the root without an unnecessary wrapper. The child must be a single React element.

<ScrollAutoHide scrollContainerRef={scrollContainerRef} asChild>
  <header>Filters</header>
</ScrollAutoHide>

Behavior and Style

  • While scrolling, it follows the movement distance exactly. Once scrolling ends, it fully hides or reveals based on the 50% point.
  • Snapping uses cubic-bezier(0, 0, 0.15, 1), Crispy's enter timing function, for 200ms.
  • In reduced motion settings, auto-hiding is disabled to avoid position changes.
  • If keyboard focus moves into the hidden area, content is immediately revealed.
  • The component uses translate3d() to compose well in wide webview versions. In browsers supporting ScrollTimeline, the browser directly connects scrolling and movement; in other environments, the same behavior is handled via scroll events.
  • The root element's transform is used for internal movement. If additional transform is needed, apply it to child elements.
  • Background color and z-index are specified directly for your use case. Without a background color, content underneath may show through while hiding.

Props

Prop

Type

asChild?boolean | undefined
children?React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | React.ReactNode

Table of contents