Top App Bar
The bar at the head of a screen: navigation, title and actions. Four sizes, and four ways to respond to scrolling, including the headline that shrinks into the bar as you move down the list. Every demo below scrolls inside its own frame, so scroll the frame, not the page.
Install
npx shadcn@latest add @nelumbo/app-barVariants
Small is 64px with the title inline. Center centers it. Medium (112px) and large (152px) move the title below the icons as a headline.
Small
Center
Medium, collapse
Large, collapse
Scroll behavior
elevate fills the bar with surface-container and lifts it as content scrolls under it. hide slides it away scrolling down and brings it back scrolling up (or when focus moves into it). collapse is driven by scroll position: the headline scales down and cross-fades into the inline title, and if you stop part way it springs to the nearest end.
Elevate
Hide on scroll
Search in the bar
Put a SearchBar in the bar instead of a title. The leading slot takes the navigation button, the avatar sits at the far end.
Search bar
<TopAppBar scrollBehavior="elevate" scrollTarget={scroller}> <TopAppBarSearch label="Search mail" leading={<IconButton label="Open navigation" icon="menu" />} avatar={<Avatar name="Maya Kowalski" size="sm" color="auto" />} /></TopAppBar>Landmarks and headings
The bar renders a header element, which is the page banner when it is a direct child of body; give it role=banner otherwise, or render a div with as=div (as in these demos, which sit inside the page's main). The title is an h1 by default; pick the level that fits with as. In medium and large the headline is the only real heading, and the small inline copy that fades in is aria-hidden.
<TopAppBar variant="large" role="banner" aria-label="Mail"> <TopAppBarNavigation /> <TopAppBarTitle as="h1">Inbox</TopAppBarTitle></TopAppBar>Usage
The bar is position: sticky, so put it inside the scroller. Without scrollTarget it follows the window.
import { TopAppBar, TopAppBarNavigation, TopAppBarTitle, TopAppBarActions, TopAppBarAction } from "@/components/ui/app-bar"const scroller = useRef<HTMLDivElement>(null)<div ref={scroller} className="h-dvh overflow-y-auto"> <TopAppBar variant="large" scrollBehavior="collapse" scrollTarget={scroller}> <TopAppBarNavigation icon="arrow_back" label="Back" onClick={back} /> <TopAppBarTitle subtitle="12 unread">Inbox</TopAppBarTitle> <TopAppBarActions> <TopAppBarAction icon="search" label="Search" /> <TopAppBarAction icon="more_vert" label="More options" /> </TopAppBarActions> </TopAppBar> <Messages /></div>Props
| Prop | Type | Default | Notes |
|---|---|---|---|
TopAppBar variant | "small" | "center" | "medium" | "large" | "small" | 64, 64, 112 and 152px |
scrollBehavior | "none" | "elevate" | "collapse" | "hide" | "none" | Collapse is for medium and large; on others it elevates |
scrollTarget | RefObject | HTMLElement | window | The scrolling container the bar sits in |
settle | boolean | true | Spring a half-collapsed bar to its nearest end |
as | "header" | "div" | "header" | Landmark element |
TopAppBarNavigation | IconButton props | menu | Leading button; icon, label, onClick, or children |
TopAppBarTitle subtitle | ReactNode | A quieter second line | |
TopAppBarTitle as | "h1" | "h2" | "h3" | "p" | "div" | "h1" | Heading element |
TopAppBarActions | children | Up to three TopAppBarAction, then an overflow | |
TopAppBarAction | IconButton props | 48px button with a tooltip; label required | |
TopAppBarSearch | SearchBar props | Search in the bar | |
--bar-p | CSS variable | Collapse progress 0 to 1, for your own effects |