Starts an action: saving a form, sending a message, opening a dialog.
A Button tells the reader what will happen when they press it, and does it on this page. It comes in three variants that set how much it stands out, so a view can have one clear main action with quieter ones beside it, and two sizes that match the height of the fields and controls it sits with. It renders a native button element, so the keyboard and assistive technology work with no extra wiring. Use a Link instead when pressing it takes the reader somewhere else.
Installation#
npx halyard-ui add buttonOr add it by hand, if the package is already in your app:
- 1
Install the package
Once per app, with your package manager.
- 2
Import the stylesheet
Once, in your root layout, before your own CSS.
- 3
Import the Button
From halyard-ui, wherever you need it.
npm install halyard-uiUsage#
Give each button a verb that says what it does, and one primary per view for the main action.
Variants#
variant sets how much the button stands out. Use primary for the one main action, secondary for an alternative to it, and tertiary for a quiet action such as Cancel.
Writing labels#
Start with a verb, and name the outcome rather than the gesture.
Accessibility#
Button renders a native button element, so it is in the tab order and pressed from the keyboard with no extra wiring.
| Key | Action |
|---|---|
Tab | Moves focus to the button. |
Enter | Presses the button. |
Space | Presses the button. |
An icon alone needs a name
A button that shows only an icon has no visible text, so give it a label that screen readers announce and a tooltip shows.
API reference#
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'secondary' | 'tertiary' | 'primary' | How much the button stands out. |
size | 'default' | 'compact' | 'default' | The control height, matching the fields beside it. |
onClick | (event: MouseEvent) => void | – | Runs when the button is pressed. |
disabled | boolean | false | Holds the button still. |
loading New | boolean | false | Shows a spinner and holds the button still while an action runs. |