Button

A button component that can be rendered as another tag or focusable when disabled.

View as Markdown

Anatomy

Import the component:

Anatomy

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}.

Custom tag button

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.

API reference

focusableWhenDisabledbooleanfalse
Description

Whether the button should be focusable when disabled.

Type
boolean | undefined
Default
false
nativeButtonboolean
Type
boolean | undefined
disabledboolean
Description

Whether the button should ignore user interaction.

Type
boolean | undefined
classNamestring | function
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
| string
| ((state: Button.State) => string | undefined)
styleReact.CSSProperties | function
Name
Type
| React.CSSProperties
| ((state: Button.State) => CSSProperties | undefined)
| undefined
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 ReactElement or a function that returns the element to render.

Type
| ReactElement
| ((props: HTMLProps, state: Button.State) => ReactElement)
data-disabled
Present when the button is disabled.