Icon button
ExpressiveA compact icon-only action; requires an accessible name.
import { IconButton } from '@windmorph/react';Props
IconButton 33 props
The icon, e.g. a Material Symbols SVG. Hidden from assistive tech;
aria-labelnames the button.Colour style. Filled is the M3 default; toolbars and app bars default their icon buttons to
standardthroughButtonContext.Container and icon size, from extra small to extra large.
Container width: narrow, default or wide, at the same height.
Fully round corners, or square ones (still rounded, but less).
Web density,
0to-3: each step takes 4px off the container's height and width (an S button: 40px at 0, 28px at -3), never below the icon plus 4px; the touch target stays 48 × 48px. Left out, the button takes the density of the nearestThemeProviderorThemeScope; icon buttons in a field's icon slots, and in app bars, toolbars, search bars, a navigation rail's header and dialog and sheet headers, keep their size. M3 asks for density to be the reader's choice rather than a default, so prefer setting it there.Shows the
aria-labelin a plain tooltip on hover and keyboard focus, as M3 asks of icon buttons on the web. The tooltip only repeats the name, so it isn't linked as a description (no double announcement). It steps aside when the button is already inside aTooltipTriggerorRichTooltipTrigger, and when it's named byaria-labelledby.Shows a loading indicator in place of the icon while an action runs, and blocks presses. The button keeps its size, its colours and keyboard focus; its accessible name gains
labels.pending(the tooltip keeps showing only thearia-label), 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.Replaces the loading indicator shown while
pending, e.g. aCircularProgressIndicatorfor a wait that may pass five seconds. It's centred over the icon 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.Controlled selection. Ignored inside a selection group.
Initial selection when uncontrolled.
Icon shown while selected, e.g. the filled form of
icon.How
iconhands over toselectedIcon:swapchanges it at once,rotateturns and crossfades the two (counter-clockwise as it selects, in LTR).rotateis an extension beyond the M3 spec, matching Google's Expressive showcase, like the FAB menu's. Reduced motion keeps only the crossfade. NeedsselectedIcon.
Events
Called with the new selection when the user toggles the button.
Text
Words the button announces. A
LabelsProvidersets them for the whole app.The button's accessible name, also shown in its tooltip. Required without
aria-labelledby.The id of an element that names the button, instead of
aria-label.
Classes for each part.
classNames.rootis merged withclassName.The button element itself; merged with
className.Inner wrapper around the icon.
The icon.
The built-in plain tooltip that shows the label (
tooltip).The slot holding the loading indicator while
pending, centred over the hidden icon.
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 |
|---|---|---|---|
| Standard (variant) | |||
--md-comp-icon-button-standard-icon-color | var(--md-comp-icon-button-icon-color, var(--md-sys-color-on-surface-variant)) | The icon, and an unselected toggle’s. Falls back to `--md-comp-icon-button-icon-color`. | StandardIconButtonTokens.Color |
--md-comp-icon-button-standard-selected-icon-color | var(--md-sys-color-primary) | The icon of a selected toggle. | StandardIconButtonTokens.SelectedColor |
| Filled (variant) | |||
--md-comp-icon-button-filled-container-color | var(--md-sys-color-primary) | The container. | FilledIconButtonTokens.ContainerColor |
--md-comp-icon-button-filled-icon-color | var(--md-sys-color-on-primary) | The icon. | FilledIconButtonTokens.Color |
--md-comp-icon-button-filled-selected-container-color | var(--md-sys-color-primary) | The container of a selected toggle. | FilledIconButtonTokens.SelectedContainerColor |
--md-comp-icon-button-filled-selected-icon-color | var(--md-sys-color-on-primary) | The icon of a selected toggle. | FilledIconButtonTokens.ToggleSelectedColor |
--md-comp-icon-button-filled-unselected-container-color | var(--md-sys-color-surface-container) | The container of an unselected toggle. | FilledIconButtonTokens.UnselectedContainerColor |
--md-comp-icon-button-filled-unselected-icon-color | var(--md-sys-color-on-surface-variant) | The icon of an unselected toggle. | FilledIconButtonTokens.ToggleUnselectedColor |
| Tonal (variant) | |||
--md-comp-icon-button-tonal-container-color | var(--md-sys-color-secondary-container) | The container. | FilledTonalIconButtonTokens.ContainerColor |
--md-comp-icon-button-tonal-icon-color | var(--md-sys-color-on-secondary-container) | The icon. | FilledTonalIconButtonTokens.Color |
--md-comp-icon-button-tonal-selected-container-color | var(--md-sys-color-secondary) | The container of a selected toggle. | FilledTonalIconButtonTokens.SelectedContainerColor |
--md-comp-icon-button-tonal-selected-icon-color | var(--md-sys-color-on-secondary) | The icon of a selected toggle. | FilledTonalIconButtonTokens.ToggleSelectedColor |
--md-comp-icon-button-tonal-unselected-container-color | var(--md-sys-color-secondary-container) | The container of an unselected toggle. | FilledTonalIconButtonTokens.UnselectedContainerColor |
--md-comp-icon-button-tonal-unselected-icon-color | var(--md-sys-color-on-secondary-container) | The icon of an unselected toggle. | FilledTonalIconButtonTokens.ToggleUnselectedColor |
| Outlined (variant) | |||
--md-comp-icon-button-outlined-outline-color | var(--md-sys-color-outline-variant) | The outline. | OutlinedIconButtonTokens.OutlineColor |
--md-comp-icon-button-outlined-icon-color | var(--md-comp-icon-button-icon-color, var(--md-sys-color-on-surface-variant)) | The icon, and an unselected toggle’s. Falls back to `--md-comp-icon-button-icon-color`. | OutlinedIconButtonTokens.Color |
--md-comp-icon-button-outlined-selected-container-color | var(--md-sys-color-inverse-surface) | The container of a selected toggle, which has no outline. | OutlinedIconButtonTokens.SelectedContainerColor |
--md-comp-icon-button-outlined-selected-icon-color | var(--md-sys-color-inverse-on-surface) | The icon of a selected toggle. | OutlinedIconButtonTokens.SelectedColor |
| Xs (size) | |||
--md-comp-icon-button-xsmall-container-shape-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | XSmallIconButtonTokens.ContainerShapeRound |
--md-comp-icon-button-xsmall-container-shape-square | var(--md-sys-shape-corner-medium) | The square shape, which a selected round toggle also takes. | XSmallIconButtonTokens.ContainerShapeSquare |
| Sm (size) | |||
--md-comp-icon-button-small-container-shape-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | SmallIconButtonTokens.ContainerShapeRound |
--md-comp-icon-button-small-container-shape-square | var(--md-sys-shape-corner-medium) | The square shape, which a selected round toggle also takes. | SmallIconButtonTokens.ContainerShapeSquare |
| Md (size) | |||
--md-comp-icon-button-medium-container-shape-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | MediumIconButtonTokens.ContainerShapeRound |
--md-comp-icon-button-medium-container-shape-square | var(--md-sys-shape-corner-large) | The square shape, which a selected round toggle also takes. | MediumIconButtonTokens.ContainerShapeSquare |
| Lg (size) | |||
--md-comp-icon-button-large-container-shape-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | LargeIconButtonTokens.ContainerShapeRound |
--md-comp-icon-button-large-container-shape-square | var(--md-sys-shape-corner-extra-large) | The square shape, which a selected round toggle also takes. | LargeIconButtonTokens.ContainerShapeSquare |
| Xl (size) | |||
--md-comp-icon-button-xlarge-container-shape-round | var(--md-sys-shape-corner-full) | The round shape: full corners, at most half the height. | XLargeIconButtonTokens.ContainerShapeRound |
--md-comp-icon-button-xlarge-container-shape-square | var(--md-sys-shape-corner-extra-large) | The square shape, which a selected round toggle also takes. | XLargeIconButtonTokens.ContainerShapeSquare |
Spec status
Built to the M3 Expressive icon 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 icon 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 |
| Color: filled, tonal, outlined, standard | Built | Configuration · Variants, Toggle variants |
| Width: narrow, default, wide | Built | Configuration · Sizes |
| Density (web, chosen by the reader) | Built | Use case · Density |
| Loading indicator in a button | Built | Use case · Pending |
| Links | Extension | href renders an <a> that routes through React Aria’s RouterProvider. |
iconTransition="rotate" | Extension | Not in the M3 spec, which swaps icon for selectedIcon: the icon turns and crossfades into the other, counter-clockwise as it selects (mirrored in RTL). Matches Google's Expressive showcase motion; reduced motion keeps only the crossfade. |
pending | Extension | M3 guidance with no icon button prop or token: the core LoadingIndicator takes the icon’s place after 200ms, at least 24px, and the button keeps its size and focus. |
| Content colour token | Extension | A container can set --md-comp-icon-button-icon-color for its standard and outlined icon buttons, as the vibrant toolbar and the app bars do. |
Default icon button
BuiltVariant · Variants
Toggle (selection)
BuiltVariant · Toggle, Toggle variants
Size: XS, S, M, L, XL
BuiltConfiguration · Sizes
Shape: round and square
BuiltConfiguration · Shapes
Color: filled, tonal, outlined, standard
BuiltConfiguration · Variants, Toggle variants
Width: narrow, default, wide
BuiltConfiguration · Sizes
Density (web, chosen by the reader)
BuiltUse case · Density
Loading indicator in a button
BuiltUse case · Pending
Links
Extensionhrefrenders an<a>that routes through React Aria’sRouterProvider.
ExtensioniconTransition="rotate"Not in the M3 spec, which swaps
iconforselectedIcon: the icon turns and crossfades into the other, counter-clockwise as it selects (mirrored in RTL). Matches Google's Expressive showcase motion; reduced motion keeps only the crossfade.
ExtensionpendingM3 guidance with no icon button prop or token: the core
LoadingIndicatortakes the icon’s place after 200ms, at least 24px, and the button keeps its size and focus.Content colour token
ExtensionA container can set
--md-comp-icon-button-icon-colorfor its standard and outlined icon buttons, as the vibrant toolbar and the app bars do.
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.
IconButton: 26.1 kB
M3 Expressive specs
- Sizes
xs, sm, md, lg, xl- Shape
rounded-corner-full- Variants
standard, filled, tonal, outlined
Differences from Compose
- Variants are
filled | tonal | outlined | standard— no elevated or text. Filled is the default, as in the M3 Expressive specs (Compose's plainIconButtonis standard). Toolbars and app bars make their icon buttons standard by default throughButtonContext. A dialog, menu or sheet opened from one isn't part of it: its icon buttons are filled again unless they say otherwise. width(narrow / default / wide) is the icon size plus leading and trailing space; Compose'sUniformoption is the default width.- Standard icons are
on-surface-variant, and outlined ones are too, inside anoutline-variantoutline (the spec's colour table). A container that needs its own content colour, like a vibrant toolbar, sets--md-comp-icon-button-icon-color(tocurrentColorto inherit it), which the standard and outlined icon colour tokens fall back to. - Selected toggles: standard turns
primary, filledprimary/on-primary, tonalsecondary/on-secondary, outlined inverse-surface with no border, disabled or not; shape swaps round ↔ square. - A disabled outlined icon button's outline dims to
outline-variantat 10%, the same as a disabled outlined button (Compose's code draws it at 38% of the content colour). - Reads
size/shape/disabledand its defaulticonButtonVariantfromButtonContext, but not the Buttonvariant, because the variant sets differ. pendingfollows M3's guidance on loading indicators in buttons (no Compose parameter): theLoadingIndicatorat the icon's size, 24px at least, in the icon's colour. The name gains “Loading” (labels.pending); the tooltip keeps showing thearia-label.