Button
A button component that can be rendered as another tag or focusable when disabled.
Usage guidelines
- Submit buttons: Unlike the native button element,
type="submit"must be specified on Button for it to act as a submit button. - Links: The Button component enforces button semantics (
role="button", keyboard interaction, disabled state). It should not be used for links. See Rendering links as buttons below. - Async work: Use
clickActioninstead ofonClickfor async work so React manages pending state. See Async.
Anatomy
Import the component:
Examples
Rendering as another tag
The button can remain keyboard accessible while being rendered as another tag, such as a <div>, by specifying nativeButton={false}.
Rendering links as buttons
The Button component enforces button semantics. nativeButton={false} signals that the rendered tag is not a <button>, but it must still be a tag that can receive button semantics (role="button", keyboard interaction handlers). Links (<a>) have their own semantics and should not be rendered as buttons through the render prop.
If a link needs to look like a button visually, style the <a> element directly with CSS rather than using the Button component.
Loading states
For buttons that enter a loading state after being clicked, specify the focusableWhenDisabled prop to ensure focus remains on the button when it becomes disabled. This prevents focus from being lost and maintains the tab order.
Async
Use the clickAction prop for click handlers that perform async work. Base UI runs the action in a React transition and ignores repeated activations while the returned promise is pending.
See the Async Actions guide for details.
No changes saved
API reference
clickActionfunction—
- Name
- Description
Event handler called when the button is activated. The action is run in a React transition when supported.
- Type
focusableWhenDisabledbooleanfalse
- Description
Whether the button should be focusable when disabled.
- Type
- Default
false
nativeButtonbooleantrue
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (for example,<div>).- Type
- Default
true
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the button is disabled.
| Attribute | Description | |
|---|---|---|
data-disabled | Present when the button is disabled. | |