Button
Render actions and links with loading, icons, and semantic roots.
Anatomy#
Usage#
Use Button for commands and explicit navigation. Render a native button for an action on this page.
Use as="a" with href for a destination. Use ToggleButton when the
control stays pressed.
Variant, tone, and size#
variant: selects the surface (solidby default,soft,outline,ghost, orlink).tone: sets the color (primaryby default, or shared tones such asneutral,danger, andsuccess).size: runs fromxstoxl(defaultmd).
Inside a ButtonGroup, a button inherits the group’s size, variant,
and tone unless it sets its own.
Press motion#
pressEffect controls the press motion. The default move-down shifts the button down by one pixel.
zoom-in scales it down slightly. Both skip the motion when the button has aria-haspopup, so overlay
triggers stay still. Use none to disable the motion, or pass a function that receives the rendered
element and returns a class string.
Loading#
Use loading when application state owns the pending operation. autoLoading is opt-in: when
onClick returns a promise, the button loads until the promise settles. A handler that calls
event.preventDefault() does not start loading.
While loading, the button sets aria-busy and ignores clicks and keyboard activation, but does not
apply native disabled, so a focused button keeps its keyboard position. An explicit disabled
still uses native disabled semantics where available.
The loading icon replaces leading, or trailing when only trailing is set. With no icons, it is
added before the label. Set loadingIcon to change it. children can also be a function that
receives { loading }; declare its parameter even when unused.
Icons and polymorphism#
leading and trailing accept icon names, elements, or components. Icon-only buttons use the
square sizes icon-xs to icon-xl and need an aria-label or another accessible name.
Polymorphic roots without native link semantics receive the button role and keyboard activation;
anchors with href keep native link behavior. When disabled is set on a non-native root, it gets
aria-disabled and leaves the tab order. When a custom component forwards its root ref, Moraine
resolves native button semantics from the rendered DOM element.
Examples#
Icon-only#
Keep an icon-only control labeled. Pair it with a tooltip when the action is otherwise unnamed.
Loading#
Drive loading from local state when the request is owned by the page. Use autoLoading when the
click handler returns a promise.
Project header actions#
Mix a command with a leading icon, a destination rendered with as="a", and an icon-only settings
button that keeps an aria-label.
API Reference#
Attributes#
data-disableddata-loadingProps#
Props for the Button component. Renders a <button> element by default.