Top app bar
A header with the screen title and actions, in three sizes, with scroll behaviour.
import { TopAppBar } from '@windmorph/react';Props
TopAppBar 14 props
The title, e.g. the screen's name. Wrap it in a heading element if it names the page.
smallis a 64px single row;mediumandlargeare Compose's flexible two-row bars (112 / 120px, 136 / 152px with a subtitle) that collapse to 64px.A second line under the title, e.g. the current section.
Align the title (and subtitle) to the start, or centre it.
Trailing controls, usually
IconButtons.Respond to content scrolling under the bar: it sticks to the top, turns
surface-container, and (forenter-always/exit-until-collapsed) collapses. Leave it out for a static bar positioned by the consumer.The scroll container the bar responds to. Defaults to the window.
An accessory row below the title rows, such as a row of filter chips or tabs (M3: app bars "can animate on and off screen with another bar of controls, like a row of chips"). It's part of the bar: it takes the bar's colour, stays below the collapsed top row of a medium or large bar, and hides and comes back with the bar under
enter-alwaysand a small bar'sexit-until-collapsed. Give it its own padding.The container's colour once content scrolls under the bar.
containerfills it withsurface-container(M3's default);transparentlets the content show through (M3: "consider setting the app bar container to be transparent on scroll"); give the icon buttons a container fill then (e.g.variant="tonal"), so they stay legible over the content.Ref to the root element.
Classes for each part, by slot.
The
<header>container, merged withclassName.The 64px top row.
The top row's title block.
The top row's title text.
The top row's subtitle text.
The trailing slot holding
actions.The expanded title row of medium and large bars.
The expanded row's title text.
The expanded row's subtitle text.
The accessory row below the title rows (
bottom).
Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
--md-comp-app-bar-title-color | var(--md-sys-color-on-surface) | The title. | AppBarTokens.TitleColor |
--md-comp-app-bar-subtitle-color | var(--md-sys-color-on-surface-variant) | The subtitle. | AppBarTokens.SubtitleColor |
--md-comp-app-bar-leading-icon-color | var(--md-sys-color-on-surface) | The navigation icon. | AppBarTokens.LeadingIconColor |
--md-comp-app-bar-trailing-icon-color | var(--md-sys-color-on-surface-variant) | The actions. | AppBarTokens.TrailingIconColor |
--md-comp-app-bar-container-color | var(--md-sys-color-surface) | The bar, with nothing scrolled under it. | AppBarTokens.ContainerColor |
--md-comp-app-bar-on-scroll-container-color | var(--md-sys-color-surface-container) | The bar once content scrolls under it. | AppBarTokens.OnScrollContainerColor |
Spec status
Built to the M3 Expressive top app bar spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Search app bar | Built | Variant · App bar |
| Small | Built | Variant · Variants |
| Medium flexible | Built | Variant · Variants, Flexible |
| Large flexible | Built | Variant · Variants, Flexible |
| Text alignment: leading edge | Built | Configuration · Variants |
| Text alignment: centred | Built | Configuration · Variants, Flexible |
| Subtitle and a filled icon button | Built | Use case · Flexible |
| Collapsing on scroll | Built | Use case · Scrolling |
| A row of chips below the title | Built | Use case · Chips |
| Transparent on scroll | Built | Use case · Transparent |
| Scrolling | Differs | The bar is sticky and slides up by its offset rather than shrinking its layout height, so the content moves exactly with the scroll; there is no fling snap. |
| Center-aligned app bar | Not built | Merged into the small bar in M3 Expressive: use titleAlign="center". |
| Medium and large (baseline) | Not built | Not recommended in M3 Expressive; the medium and large flexible bars replace them. |
Search app bar
BuiltVariant · App bar
Small
BuiltVariant · Variants
Text alignment: leading edge
BuiltConfiguration · Variants
Subtitle and a filled icon button
BuiltUse case · Flexible
Collapsing on scroll
BuiltUse case · Scrolling
A row of chips below the title
BuiltUse case · Chips
Transparent on scroll
BuiltUse case · Transparent
Scrolling
DiffersThe bar is
stickyand slides up by its offset rather than shrinking its layout height, so the content moves exactly with the scroll; there is no fling snap.Center-aligned app bar
Not builtMerged into the small bar in M3 Expressive: use
titleAlign="center".Medium and large (baseline)
Not builtNot recommended in M3 Expressive; the medium and large flexible bars replace them.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
TopAppBar: 9.9 kB
M3 Expressive specs
- Variants
small, medium, large
Differences from Compose
- These are Compose's flexible bars; the non-flexible medium / large bars and the centre-aligned bar are superseded by
titleAlign. - Compose shrinks the bar's height through nested scrolling. On the web the bar is
stickyand keeps its layout height, sliding up via atopoffset so the content moves exactly with the scroll. The offset differs per behaviour:pinnedstays,exit-until-collapsedcollapses and expands again only near the top, andenter-alwayscomes back on any scroll up. A medium or largeenter-alwaysbar comes back small and expands only at the top of the page, as M3 asks. - A long expanded title wraps to two lines at most (M3).
- There is no fling settle or snap, and you cannot drag the bar itself. Scroll offsets and colours are written as custom properties from a scroll handler, so scrolling causes no React renders.