A button with the disabled behaviour a native <button> cannot express: staying focusable while inert, and behaving like a button on elements that aren't one.
- A button that disables itself mid-interaction — while a form submits, while a request is in flight. Use
focusableWhenDisabledso focus is not dropped to the body and the user keeps their place on the page. - Rendering a button as a link or a
<span>. PassnativeButton={false}so the role, tab order, and Enter/Space activation are applied. - A plain always-enabled button needs neither prop, and a bare
<button>is fine.
import { Button } from '@/primitives/button';
<Button onClick={save}>Save</Button>;<Button
type='submit'
disabled={submitting}
focusableWhenDisabled
>
Save
</Button>The button keeps its place in the tab order, is marked aria-disabled, and ignores clicks and keyboard activation. Focus is not pulled off its current element by a pointer press either.
Suppression is the consumer's handler plus the event's default action, not propagation. Events still bubble, so an enclosing dialog or menu keeps seeing them. Every key but Tab has its default prevented — Tab is exempt so focus can still move off the button, which is the point of keeping it focusable.
<Button
nativeButton={false}
render={<a href='/settings' />}
>
Settings
</Button>| Prop | Type | Default | Description |
|---|---|---|---|
disabled |
boolean |
false |
Makes the button inert |
focusableWhenDisabled |
boolean |
false |
Keeps a disabled button in the tab order |
nativeButton |
boolean |
true |
Whether the rendered element is a real <button> |
render |
RenderPropOrElement |
— | Renders a different element (see the shared render escape hatch) |
Standard <button> attributes pass through. type defaults to "button" on a native button and is overridable.
| Attribute | Description |
|---|---|
data-disabled |
Present when disabled |
- Native + disabled: the
disabledattribute. - Native +
disabled+focusableWhenDisabled:aria-disabled="true", nodisabledattribute. nativeButton={false}:role="button",tabIndex={0}(-1when disabled withoutfocusableWhenDisabled, since an<a href>is tabbable on its own and dropping the attribute would leave it in the tab order),aria-disabledwhen disabled.EnterandSpaceactivate it;Enteron a link is left to the browser so it does not fire twice.