DS0
Components

Sticky

A wrapper that uses position:sticky with stuck-state detection via IntersectionObserver.

Overview

Sticky wraps content and applies position: sticky with automatic stuck-state detection. Provides a data-stuck attribute and callback when the element becomes stuck or unstuck, enabling visual changes on stick.

Usage

<Sticky offset={64}>
  <header className="data-[stuck]:shadow-lg data-[stuck]:border-b">
    <nav>Navigation</nav>
  </header>
</Sticky>

With Callback

<Sticky
  offset={0}
  onStuckChange={(stuck) => setIsStuck(stuck)}
>
  <Toolbar />
</Sticky>

API Reference

PropTypeDefaultDescription
offsetnumber0Top offset in pixels
onStuckChange(stuck: boolean) => voidStuck state callback
childrenReactNodeSticky content
zIndexnumber10z-index when stuck
ComponentWhen to Use Instead
BackToTopScroll-to-top button
BannerFixed announcement bar

On this page