Primitive
Button
Runs an action when pressed: save, post, download, confirm.
When to use
Use it for actions. Render it as a link with render={<a href />} only when a navigation needs a button's weight, such as a page's main call to action. A link inside text stays a link.
States
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "primary" | "secondary" | "ghost" | "danger" | Default "secondary" | primary marks the one main action in a view. ghost is for toolbars and actions beside content. danger is for an action that destroys data, and its label names what is lost. |
| size | "sm" | "md" | "lg" | Default "md" | sm (28px) for toolbars and table rows, md (32px) for most places, lg (40px) for a form's submit. |
| iconOnly | true | Default – | A square that holds one icon. It requires a name: aria-label, which names the action ("Delete journal", not "Trash"), or aria-labelledby, the id of visible text that names it. One of the two. |
| loading | boolean | Default false | Shows a spinner over the label, keeps the width and keeps focus. Presses do nothing: onClick and formAction are held back and a submit button stops submitting. Not allowed with render. |
| disabled | boolean | Default false | The native disabled attribute: the Button leaves the tab order and ignores presses. Not allowed with render. |
| render | ReactElement | Default – | Renders this element with the Button's look, such as <a href="/ledger" />. Its own props win over the Button's. |
| type | "button" | "submit" | "reset" | Default "button" | Set "submit" for a form's submit button. Ignored with render. |
| ...button props | ComponentProps<"button"> | Default – | Passed to the element, ref and aria-* included. className places the Button and never restyles it. |