Button
ExpressiveFive variants and five sizes for text actions, with a toggle form and a press morph.
import { Button } from '@windmorph/react';Props
Button 28 props
childrentypestring | number | bigint | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...>RequiredThe visible label. Required: buttons without text are
IconButtons.The M3 style: filled, tonal, outlined, elevated or text.
Height, padding and label size, from extra small to extra large.
Fully round corners, or square ones (still rounded, but less).
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.
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.Replaces the loading indicator shown while
pending, e.g. aCircularProgressIndicatorfor 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.Ref to the root element: the
<button>, or the<a>withhref.Disables the element: it can't be pressed or focused, and shows the disabled style.
The value a submit button sends with its form, under its
name. On a toggle (toggle) it's astringnaming the button in a selection group instead, required to take part in the group's selection.The element is being dragged (e.g. a card picked up to move it): sets
data-draggedfor the dragged state layer. A consumer's owndata-draggedattribute counts too.Don't move focus to the element on press (set by menu triggers).
The element rendered: a native
<button>.Renders a link. Navigation goes through React Aria's
RouterProviderwhen one is set.Makes the button a toggle (
aria-pressed) withselectedandonSelectedChange.selectedLeadingIcontypeReactElement<unknown, string | JSXElementConstructor<any>>defaultleadingIconLeading 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").Controlled selection. Ignored inside a selection group.
Initial selection when uncontrolled.
Events
Called with the new selection when the user toggles the button.
Text
Words the button announces. A
LabelsProvidersets them for the whole app.
Classes for each part.
classNames.rootis merged withclassName.The button element itself; merged with
className.Inner wrapper around the icons and label.
The label text.
The leading icon.
The slot holding the loading indicator while
pending, centred over the hidden content.
Inline styles for the root element.
Classes for the root element, merged with
classNames.root; consumer classes win.
Handler that is called when the press is released over the target.
Handler that is called when a press interaction starts.
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
Handler that is called when the press state changes.
Handler that is called when a press is released over the target, regardless of whether it started on the target or not.
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.
| Variable | Default | Paints | Compose |
|---|---|---|---|
| Filled (variant) | |||
--md-comp-button-filled-container-color | var(--md-sys-color-primary) | The container. | FilledButtonTokens.ContainerColor |
--md-comp-button-filled-label-text-color | var(--md-sys-color-on-primary) | The label and icon. | FilledButtonTokens.LabelTextColor |
--md-comp-button-filled-selected-container-color | var(--md-sys-color-primary) | The container of a selected toggle. | FilledButtonTokens.SelectedContainerColor |
--md-comp-button-filled-selected-label-text-color | var(--md-sys-color-on-primary) | The label and icon of a selected toggle. | FilledButtonTokens.SelectedLabelTextColor |
--md-comp-button-filled-unselected-container-color | var(--md-sys-color-surface-container) | The container of an unselected toggle. | FilledButtonTokens.UnselectedContainerColor |
--md-comp-button-filled-unselected-label-text-color | var(--md-sys-color-on-surface-variant) | The label and icon of an unselected toggle. | FilledButtonTokens.UnselectedLabelTextColor |
| Elevated (variant) | |||
--md-comp-button-elevated-container-color | var(--md-sys-color-surface-container-low) | The container. | ElevatedButtonTokens.ContainerColor |
--md-comp-button-elevated-label-text-color | var(--md-sys-color-primary) | The label and icon, and an unselected toggle’s. | ElevatedButtonTokens.LabelTextColor |
--md-comp-button-elevated-container-elevation | var(--md-sys-elevation-level-1) | The shadow at rest. | ElevatedButtonTokens.ContainerElevation |
--md-comp-button-elevated-selected-container-color | var(--md-sys-color-primary) | The container of a selected toggle. | ElevatedButtonTokens.SelectedContainerColor |
--md-comp-button-elevated-selected-label-text-color | var(--md-sys-color-on-primary) | The label and icon of a selected toggle. | ElevatedButtonTokens.SelectedLabelTextColor |
--md-comp-button-elevated-unselected-container-color | var(--md-sys-color-surface-container-low) | The container of an unselected toggle. | ElevatedButtonTokens.UnselectedContainerColor |
| Tonal (variant) | |||
--md-comp-button-tonal-container-color | var(--md-sys-color-secondary-container) | The container. | TonalButtonTokens.ContainerColor |
--md-comp-button-tonal-label-text-color | var(--md-sys-color-on-secondary-container) | The label and icon. | TonalButtonTokens.LabelTextColor |
--md-comp-button-tonal-selected-container-color | var(--md-sys-color-secondary) | The container of a selected toggle. | TonalButtonTokens.SelectedContainerColor |
--md-comp-button-tonal-selected-label-text-color | var(--md-sys-color-on-secondary) | The label and icon of a selected toggle. | TonalButtonTokens.SelectedLabelTextColor |
--md-comp-button-tonal-unselected-container-color | var(--md-sys-color-secondary-container) | The container of an unselected toggle. | TonalButtonTokens.UnselectedContainerColor |
--md-comp-button-tonal-unselected-label-text-color | var(--md-sys-color-on-secondary-container) | The label and icon of an unselected toggle. | TonalButtonTokens.UnselectedLabelTextColor |
| Outlined (variant) | |||
--md-comp-button-outlined-outline-color | var(--md-sys-color-outline-variant) | The outline. | OutlinedButtonTokens.OutlineColor |
--md-comp-button-outlined-label-text-color | var(--md-sys-color-on-surface-variant) | The label and icon, and an unselected toggle’s. | OutlinedButtonTokens.LabelTextColor |
--md-comp-button-outlined-selected-container-color | var(--md-sys-color-inverse-surface) | The container of a selected toggle, which has no outline. | OutlinedButtonTokens.SelectedContainerColor |
--md-comp-button-outlined-selected-label-text-color | var(--md-sys-color-inverse-on-surface) | The label and icon of a selected toggle. | OutlinedButtonTokens.SelectedLabelTextColor |
| Text (variant) | |||
--md-comp-button-text-label-text-color | var(--md-sys-color-primary) | The label and icon. | TextButtonTokens.LabelTextColor |
| Xs (size) | |||
--md-comp-button-xsmall-container-shape-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | ButtonXSmallTokens.ContainerShapeRound |
--md-comp-button-xsmall-container-shape-square | var(--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-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | ButtonSmallTokens.ContainerShapeRound |
--md-comp-button-small-container-shape-square | var(--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-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | ButtonMediumTokens.ContainerShapeRound |
--md-comp-button-medium-container-shape-square | var(--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-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | ButtonLargeTokens.ContainerShapeRound |
--md-comp-button-large-container-shape-square | var(--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-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | ButtonXLargeTokens.ContainerShapeRound |
--md-comp-button-xlarge-container-shape-square | var(--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.
| Item | Status | Details |
|---|---|---|
| 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. |
Default button
BuiltVariant · Variants
Toggle (selection)
BuiltVariant · Toggle, Toggle variants
Size: XS, S, M, L, XL
BuiltConfiguration · Sizes
Color: elevated, filled, tonal, outlined, text
BuiltConfiguration · Variants, Toggle variants
Small button padding: 16dp
BuiltConfiguration · Sizes
A link that looks like a button
BuiltUse case · Link
Loading indicator in a button
BuiltUse case · Pending, Pending indicator
Text button colour
DiffersText buttons use
primary, as Compose's code does; the token file'son-surface-variantis flagged by a Compose TODO as a mistake.Links
Extensionhrefrenders an<a>that routes through React Aria’sRouterProvider, so a link can look like a button.
ExtensionpendingM3 guidance with no button prop or token: the core
LoadingIndicatorreplaces the content after 200ms in the content colour, the button keeps its width and focus, and presses are blocked.24dp small button padding
Not builtThe spec marks it not recommended; small buttons use 16dp.
Trailing icon
Not builtThe 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-radiustransition. A plain button's press morph runs on the default effects spring, which never bounces, as Compose'sButtondoes; a toggle's selection morph uses the fast spatial spring, as Compose'sToggleButton. 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-surface10% and contenton-surface-variant38% 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 ofleadingIconwhile 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.
pendingcomposes M3's guidance on loading indicators in buttons, which defines no button prop or token: the indicator is theLoadingIndicatorat the icon's size (24px at least, M3's minimum), in the content colour, loaded only once a button takespending. 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.