Skip to content

Button

Expressive

Five variants and five sizes for text actions, with a toggle form and a press morph.

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

Props

By name or description, across the 28 props below

Button 28 props

  • childrentype string | number | bigint | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...>Required

    The visible label. Required: buttons without text are IconButtons.

  • varianttype "text" | "filled" | "elevated" | "tonal" | "outlined"default "filled"

    The M3 style: filled, tonal, outlined, elevated or text.

  • sizetype "xs" | "sm" | "md" | "lg" | "xl"default "sm"

    Height, padding and label size, from extra small to extra large.

  • shapetype "round" | "square"default "round"

    Fully round corners, or square ones (still rounded, but less).

  • leadingIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Icon before the label, e.g. a Material Symbols SVG. Decorative; the label names the button. M3 allows one icon, on the leading side ("Don't use two icons in the same button"), so there's no trailing icon.

  • pendingtype booleandefault false

    Shows a loading indicator in place of the content while an action runs, and blocks presses. The button keeps its width, its colours and keyboard focus; its accessible name gains labels.pending, and a focused button announces it. The indicator appears after 200ms, so a quick action doesn't flash. Use it for actions that take a moment, not for every button in a list. A submit button doesn't submit again while pending.

  • pendingIndicatortype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the loading indicator shown while pending, e.g. a CircularProgressIndicator for a wait that may pass five seconds. It's centred over the content and takes the content colour; a progress indicator also loses its track, as M3 asks inside a button.

  • reftype Ref<HTMLButtonElement> | Ref<HTMLAnchorElement>

    Ref to the root element: the <button>, or the <a> with href.

  • disabledtype booleandefault false

    Disables the element: it can't be pressed or focused, and shows the disabled style.

  • valuetype string | number | readonly string[]

    The value a submit button sends with its form, under its name. On a toggle (toggle) it's a string naming the button in a selection group instead, required to take part in the group's selection.

  • draggedtype booleandefault false

    The element is being dragged (e.g. a card picked up to move it): sets data-dragged for the dragged state layer. A consumer's own data-dragged attribute counts too.

  • preventFocusOnPresstype booleandefault false

    Don't move focus to the element on press (set by menu triggers).

  • astype "button"default "button"

    The element rendered: a native <button>.

  • hreftype string

    Renders a link. Navigation goes through React Aria's RouterProvider when one is set.

  • toggletype booleandefault false

    Makes the button a toggle (aria-pressed) with selected and onSelectedChange.

  • selectedLeadingIcontype ReactElement<unknown, string | JSXElementConstructor<any>>default leadingIcon

    Leading icon shown while selected, e.g. the filled form of leadingIcon (M3: "use an outlined icon when unselected, and a filled version of the icon when selected").

  • selectedtype boolean

    Controlled selection. Ignored inside a selection group.

  • defaultSelectedtype boolean

    Initial selection when uncontrolled.

Events

  • onSelectedChangetype ((selected: boolean) => void)

    Called with the new selection when the user toggles the button.

Text

  • labelstype Partial<ButtonLabels>

    Words the button announces. A LabelsProvider sets them for the whole app.

Also accepts every <a> or <button> attribute.

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.

Button tokens (md-comp-button)
VariableDefaultPaintsCompose
Filled (variant)
--md-comp-button-filled-container-colorvar(--md-sys-color-primary)The container.FilledButtonTokens.ContainerColor
--md-comp-button-filled-label-text-colorvar(--md-sys-color-on-primary)The label and icon.FilledButtonTokens.LabelTextColor
--md-comp-button-filled-selected-container-colorvar(--md-sys-color-primary)The container of a selected toggle.FilledButtonTokens.SelectedContainerColor
--md-comp-button-filled-selected-label-text-colorvar(--md-sys-color-on-primary)The label and icon of a selected toggle.FilledButtonTokens.SelectedLabelTextColor
--md-comp-button-filled-unselected-container-colorvar(--md-sys-color-surface-container)The container of an unselected toggle.FilledButtonTokens.UnselectedContainerColor
--md-comp-button-filled-unselected-label-text-colorvar(--md-sys-color-on-surface-variant)The label and icon of an unselected toggle.FilledButtonTokens.UnselectedLabelTextColor
Elevated (variant)
--md-comp-button-elevated-container-colorvar(--md-sys-color-surface-container-low)The container.ElevatedButtonTokens.ContainerColor
--md-comp-button-elevated-label-text-colorvar(--md-sys-color-primary)The label and icon, and an unselected toggle’s.ElevatedButtonTokens.LabelTextColor
--md-comp-button-elevated-container-elevationvar(--md-sys-elevation-level-1)The shadow at rest.ElevatedButtonTokens.ContainerElevation
--md-comp-button-elevated-selected-container-colorvar(--md-sys-color-primary)The container of a selected toggle.ElevatedButtonTokens.SelectedContainerColor
--md-comp-button-elevated-selected-label-text-colorvar(--md-sys-color-on-primary)The label and icon of a selected toggle.ElevatedButtonTokens.SelectedLabelTextColor
--md-comp-button-elevated-unselected-container-colorvar(--md-sys-color-surface-container-low)The container of an unselected toggle.ElevatedButtonTokens.UnselectedContainerColor
Tonal (variant)
--md-comp-button-tonal-container-colorvar(--md-sys-color-secondary-container)The container.TonalButtonTokens.ContainerColor
--md-comp-button-tonal-label-text-colorvar(--md-sys-color-on-secondary-container)The label and icon.TonalButtonTokens.LabelTextColor
--md-comp-button-tonal-selected-container-colorvar(--md-sys-color-secondary)The container of a selected toggle.TonalButtonTokens.SelectedContainerColor
--md-comp-button-tonal-selected-label-text-colorvar(--md-sys-color-on-secondary)The label and icon of a selected toggle.TonalButtonTokens.SelectedLabelTextColor
--md-comp-button-tonal-unselected-container-colorvar(--md-sys-color-secondary-container)The container of an unselected toggle.TonalButtonTokens.UnselectedContainerColor
--md-comp-button-tonal-unselected-label-text-colorvar(--md-sys-color-on-secondary-container)The label and icon of an unselected toggle.TonalButtonTokens.UnselectedLabelTextColor
Outlined (variant)
--md-comp-button-outlined-outline-colorvar(--md-sys-color-outline-variant)The outline.OutlinedButtonTokens.OutlineColor
--md-comp-button-outlined-label-text-colorvar(--md-sys-color-on-surface-variant)The label and icon, and an unselected toggle’s.OutlinedButtonTokens.LabelTextColor
--md-comp-button-outlined-selected-container-colorvar(--md-sys-color-inverse-surface)The container of a selected toggle, which has no outline.OutlinedButtonTokens.SelectedContainerColor
--md-comp-button-outlined-selected-label-text-colorvar(--md-sys-color-inverse-on-surface)The label and icon of a selected toggle.OutlinedButtonTokens.SelectedLabelTextColor
Text (variant)
--md-comp-button-text-label-text-colorvar(--md-sys-color-primary)The label and icon.TextButtonTokens.LabelTextColor
Xs (size)
--md-comp-button-xsmall-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.ButtonXSmallTokens.ContainerShapeRound
--md-comp-button-xsmall-container-shape-squarevar(--md-sys-shape-corner-medium)The square shape, which a selected round toggle also takes.ButtonXSmallTokens.ContainerShapeSquare
Sm (size)
--md-comp-button-small-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.ButtonSmallTokens.ContainerShapeRound
--md-comp-button-small-container-shape-squarevar(--md-sys-shape-corner-medium)The square shape, which a selected round toggle also takes.ButtonSmallTokens.ContainerShapeSquare
Md (size)
--md-comp-button-medium-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.ButtonMediumTokens.ContainerShapeRound
--md-comp-button-medium-container-shape-squarevar(--md-sys-shape-corner-large)The square shape, which a selected round toggle also takes.ButtonMediumTokens.ContainerShapeSquare
Lg (size)
--md-comp-button-large-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.ButtonLargeTokens.ContainerShapeRound
--md-comp-button-large-container-shape-squarevar(--md-sys-shape-corner-extra-large)The square shape, which a selected round toggle also takes.ButtonLargeTokens.ContainerShapeSquare
Xl (size)
--md-comp-button-xlarge-container-shape-roundvar(--md-sys-shape-corner-full)The round shape: full corners, at most half the height.ButtonXLargeTokens.ContainerShapeRound
--md-comp-button-xlarge-container-shape-squarevar(--md-sys-shape-corner-extra-large)The square shape, which a selected round toggle also takes.ButtonXLargeTokens.ContainerShapeSquare

Spec status

Built to the M3 Expressive button 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.

  • Default button

    Built

    Variant · Variants

  • Toggle (selection)

    Built

    Variant · Toggle, Toggle variants

  • Size: XS, S, M, L, XL

    Built

    Configuration · Sizes

  • Shape: round and square

    Built

    Configuration · Shapes, Sizes

  • Color: elevated, filled, tonal, outlined, text

    Built

    Configuration · Variants, Toggle variants

  • Small button padding: 16dp

    Built

    Configuration · Sizes

  • A link that looks like a button

    Built

    Use case · Link

  • Loading indicator in a button

    Built

    Use case · Pending, Pending indicator

  • Text button colour

    Differs

    Text buttons use primary, as Compose's code does; the token file's on-surface-variant is flagged by a Compose TODO as a mistake.

  • Links

    Extension

    href renders an <a> that routes through React Aria’s RouterProvider, so a link can look like a button.

  • pending

    Extension

    M3 guidance with no button prop or token: the core LoadingIndicator replaces the content after 200ms in the content colour, the button keeps its width and focus, and presses are blocked.

  • 24dp small button padding

    Not built

    The spec marks it not recommended; small buttons use 16dp.

  • Trailing icon

    Not built

    The spec says not to use two icons in a button, so there is only leadingIcon.

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.

  • Button: 21.4 kB

M3 Expressive specs

Sizes
xs, sm, md, lg, xl
Shape
rounded-corner-full
Variants
elevated, filled, tonal, outlined, text

Differences from Compose

  • Values follow the M3 Expressive specs and the token files where Compose's code overrides them: XS padding is 16px with an 8px icon gap, small text buttons have the same 16px padding as the other small buttons, and toggle buttons press to the same corners as the others (8 / 8 / 12 / 16 / 16px). Text buttons use primary.
  • The press morph is a CSS border-radius transition. A plain button's press morph runs on the default effects spring, which never bounces, as Compose's Button does; a toggle's selection morph uses the fast spatial spring, as Compose's ToggleButton. A press that starts while the last morph is still settling uses the fast effects spring, the web's modified curve against rapid-click resonance.
  • Selected round toggle buttons become square and selected square ones become round (the latter follows m3.material.io; Compose ships only round toggles). Text buttons have no toggle form, enforced by the types.
  • Disabled is container on-surface 10% and content on-surface-variant 38% for every variant.
  • A pressed button shows the pressed elevation (elevated level 1, filled and tonal 0) even while the pointer is over it.
  • The leading and trailing space is measured from the container's edge, so the outlined style's outline comes out of its padding and an outlined button is the same size as a filled one. Change the outline width with --m3-button-border, which sets the border and the padding together.
  • XS and S buttons are at least 32 and 40px tall and grow with a large browser font size, as Compose's buttons do; a stretching flex or grid parent doesn't make them taller. The XS and S split button halves do the same.
  • A disabled outlined button dims its outline to 10%; a selected outlined toggle has no outline, disabled or not.
  • Toggles take selectedLeadingIcon, shown instead of leadingIcon while selected (the filled form of the outlined icon), so an uncontrolled toggle can swap its icon too.
  • Under reduced motion the press and selection morphs snap to their new corners; colours and elevation still fade.
  • pending composes M3's guidance on loading indicators in buttons, which defines no button prop or token: the indicator is the LoadingIndicator at the icon's size (24px at least, M3's minimum), in the content colour, loaded only once a button takes pending. Toggle buttons have no pending state.
  • XS and S buttons get a 48px touch target inside the library-owned inner wrapper; the layout height stays 32 / 40px.