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
| Guidance | Practice |
|---|---|
| Do | Pass focusableWhenDisabled when the button disables itself while work runs, such as a submit. |
| Do | Pass nativeButton={false} whenever render returns an element that is not a <button>. |
| Do | For 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.
| Prop | Type | Description |
|---|---|---|
disabled | boolean | Makes the button inert.Default: false |
focusableWhenDisabled | boolean | Keeps a disabled button in the tab order, marked aria-disabled instead of disabled.Default: false |
nativeButton | boolean | Set 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
<Button type='submit' disabled={submitting} focusableWhenDisabled>
Save
</Button>Button semantics on a link
<Button nativeButton={false} render={<a href='/settings' />}>
Settings
</Button>