Skip to content
Mosaic
On this page

Button

Headless, unstyled button that can stay focusable while disabled, and gives button semantics to an element that is not a <button>. Sets data-disabled while disabled.

Use for

  • a button that disables itself mid-interaction without dropping focus
  • button semantics on a link or a span
  • the base for a styled button component

Practices

GuidancePractice
DoPass focusableWhenDisabled when the button disables itself while work runs, such as a submit.
DoPass nativeButton={false} whenever render returns an element that is not a <button>.
DoFor a styled action, use Button or SubmitButton from src/components/button instead.

API reference

Button

Renders a button, or the render element, and forwards its ref. A native button gets type="button" unless you pass type. While disabled, clicks, pointer presses and keys other than Tab do nothing and the caller's handlers do not run.

PropTypeDescription
disabledbooleanMakes the button inert.Default: false
focusableWhenDisabledbooleanKeeps a disabled button in the tab order, marked aria-disabled instead of disabled.Default: false
nativeButtonbooleanSet false when render is not a <button>, to add role="button", a tab stop, and Enter and Space activation.Default: true

Examples

Focus survives a submit

TSX
<Button type='submit' disabled={submitting} focusableWhenDisabled>
  Save
</Button>

Button semantics on a link

TSX
<Button nativeButton={false} render={<a href='/settings' />}>
  Settings
</Button>