Skip to content

Top app bar

A header with the screen title and actions, in three sizes, with scroll behaviour.

import { TopAppBar } from '@windmorph/react';

Props

By name or description, across the 14 props below

TopAppBar 14 props

  • titletype ReactNodeRequired

    The title, e.g. the screen's name. Wrap it in a heading element if it names the page.

  • varianttype "small" | "medium" | "large"default "small"

    small is a 64px single row; medium and large are Compose's flexible two-row bars (112 / 120px, 136 / 152px with a subtitle) that collapse to 64px.

  • subtitletype ReactNode

    A second line under the title, e.g. the current section.

  • titleAligntype "center" | "start"default "start"

    Align the title (and subtitle) to the start, or centre it.

  • navigationIcontype ReactNode

    A leading control, usually a back or menu IconButton.

  • actionstype ReactNode

    Trailing controls, usually IconButtons.

  • scrollBehaviortype "pinned" | "enter-always" | "exit-until-collapsed"

    Respond to content scrolling under the bar: it sticks to the top, turns surface-container, and (for enter-always / exit-until-collapsed) collapses. Leave it out for a static bar positioned by the consumer.

  • scrollReftype RefObject<HTMLElement | null>

    The scroll container the bar responds to. Defaults to the window.

  • bottomtype ReactNode

    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-always and a small bar's exit-until-collapsed. Give it its own padding.

  • scrolledColortype "container" | "transparent"default "container"

    The container's colour once content scrolls under the bar. container fills it with surface-container (M3's default); transparent lets 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.

  • reftype Ref<HTMLElement>

    Ref to the root element.

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.

Top app bar tokens (md-comp-app-bar)
VariableDefaultPaintsCompose
--md-comp-app-bar-title-colorvar(--md-sys-color-on-surface)The title.AppBarTokens.TitleColor
--md-comp-app-bar-subtitle-colorvar(--md-sys-color-on-surface-variant)The subtitle.AppBarTokens.SubtitleColor
--md-comp-app-bar-leading-icon-colorvar(--md-sys-color-on-surface)The navigation icon.AppBarTokens.LeadingIconColor
--md-comp-app-bar-trailing-icon-colorvar(--md-sys-color-on-surface-variant)The actions.AppBarTokens.TrailingIconColor
--md-comp-app-bar-container-colorvar(--md-sys-color-surface)The bar, with nothing scrolled under it.AppBarTokens.ContainerColor
--md-comp-app-bar-on-scroll-container-colorvar(--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.

  • 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.

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 sticky and keeps its layout height, sliding up via a top offset so the content moves exactly with the scroll. The offset differs per behaviour: pinned stays, exit-until-collapsed collapses and expands again only near the top, and enter-always comes back on any scroll up. A medium or large enter-always bar 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.