InputsReact
A button that can render as another tag or stay focusable while disabled.
Rendered by React 19.3.1
43Tests passing in React · 0 failing
3.8 KiBSize
Not measured yetMemory
Not measured yetSpeed
productdevbook and 7 upstream authors8 commits · last
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<Button />Examples
Loading
focusableWhenDisabled keeps focus on the button while it is disabled during a loading state.
API reference
2 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.
ButtonButton
A button component that can be used to trigger actions. Renders a <button>.
| Prop | Type | Default |
|---|---|---|
focusableWhenDisabledWhether the button should be focusable when disabled. | boolean | false |
nativeButtonWhether the component renders a native <button> element when replacing it | boolean | true |
| Data attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
| Keys | Does | Part |
|---|---|---|
| EnterSpace | Activates the button with a real click, also when it renders an element other than <button> | Button |
| Space | On an element rendered as a link, activates it without scrolling the page | Button |
Accessibility
| Part | Sets | So that |
|---|---|---|
| Button | role="button" and tabindex="0" when nativeButton is off | another element is still read and reached as a button |
| Button | disabled, or aria-disabled="true" when it is not a native button or focusableWhenDisabled is on | a screen reader says it is unavailable |
| Button | keeps focus when disabled with focusableWhenDisabled | focus does not jump away while a button shows a loading state |
Focus order
- Button is one tab stop. Disabled, it leaves the tab order unless
focusableWhenDisabledis on.