Buttons can be used in forms, modals, cards, toolbars, or in other locations on a page to communicate that a one-click action is available.
Buttons should:
Buttons should not:
Be used in place of a more semantic element.
EzLink
. A button does something. A link goes somewhere. Ex. breadcrumbs, redirects, "forgot password", and "learn more" all go somewhere rather than do something, so should be links.EzChip
. Chips are reactive and contextual, whereas buttons are static and predetermined. Ex. a delivery status of "confirmed" is contextual and not a static action, so should be a status chip.EzButton supports filled
(default), outlined
, text
, and inline
variants.
filled
buttons are high-emphasis and contain actions that are primary. There should not be more than one primary button in a section of a page.
outlined
buttons are medium-emphasis and contain actions that are secondary, which are important but aren't the primary action. A page or section should not have more than two secondary buttons.
text
buttons are typically used for less-pronounced actions than primary or secondary actions. They may also be used when space is a constraint or when content is repeated many times on a page.
inline
buttons are text
buttons that align with surrounding text.
Buttons accept an onClick
prop for performing actions on click and onKeyDown
for performing actions on a key down.
For destructive actions, set the button's color
to destructive
.
EzButton supports theme palette properties (primary
, secondary
, error
, warning
, info
, and success
) as well as all supported theme colors (ex. common.neutral160
). Text and background colors should have high enough contrast for accessibility.
If you want to specify a button size, use the size
property. We currently support small
, medium
(default), and large
.
If you want to specify a font size, use the fontSize
property, which uses theme supported font sizes. We currently support small
, medium
(default), large
, and inherit
.
You can add an icon to the beginning or the end of a button by passing an EzIcon
to the optional startIcon
or endIcon
property.
Icon sizes will default to the font size of the text. If you need a different icon size, use size="inherit"
on the EzIcon
and wrap it in an element with the desired size.
Disabled buttons can be used to prevent users from doing an invalid or unavailable action.
In general, you should consider removing options that are not available or not applicable, but in some cases showing a disabled button may be necessary. In these cases, be sure to provide context for why the action is unavailable either with a message, or tooltip.
A button can be made disabled by adding the optional disabled
prop. Disabled buttons do not respond to user input and therefore will not trigger onClick
behavior.
A button can also display a loading spinner by adding the optional loading
prop. A loading button will always be disabled.
EzButton can be used with other Recipe components to create more complex buttons.
To aid users in migrating to Recipe's current version, a temporarily supported legacy implementation for EzButton is available. To use Recipe's deprecated button style, add the legacy
prop.
Supported styles should be used, but if you need to overwrite styles for the background, text, icon, or border, you can do so using provided class names (EzButton
, EzButton-[variant]
, EzButton-startIcon
, EzButton-endIcon
, and EzButton-disabled
).
See WAI-ARIA accessibility guidelines for buttons.
All buttons have an accessible label. By default, the accessible name is computed from any text content inside the button element. However, it can also be provided with ariaLabel
.
If you need to hide a button from all accessibility APIs, for example to avoid confusion when using a call-to-action button inside an interactive card, add the ariaHidden
prop to the button.
EzButton is very explicit about the properties it accepts, which makes providing arbitrary data attributes not possible. Instead, EzButton accept a data prop, allowing a single collection of data attributes to be provided.
Name | Type | Default | Description |
---|---|---|---|
children* | node | The content that the button wraps. | |
ariaHidden | boolean | false | If true, the component is hidden from accessibility APIs. |
ariaLabel | string | The aria-label of the element. | |
color | EzThemeColors | destructive | primary | The color of the component. Supports theme palette properties and colors. |
data | object | The data attributes to be applied to the component. | |
destructive | boolean | false | **Deprecated** If true, the color of the button is red. |
disabled | boolean | false | If true, the component is disabled. |
disabledMessage | string | **Deprecated** The tooltip message for a disabled button. | |
endIcon | element | End icon element. | |
fontSize | small | medium | large | inherit | medium | The font size of the component. |
icon | element | **Deprecated** Icon element. | |
legacy | boolean | false | **Deprecated** If true, the component is a legacy button. |
loading | boolean | false | If true, the button displays a spinning loading icon in place of its label. |
onClick | func | Callback fired when the button is clicked. | |
onKeyDown | func | Callback fired when the button is focused and an event key is pressed. | |
size | small | medium | large | medium | The size of the component. |
startIcon | element | Start icon element. | |
type | button | submit | reset | button | The type of the button. |
use | primary | secondary | tertiary | secondary | **Deprecated** The use of the component. |
variant | filled | outlined | text | inline | filled | The variant of the component. |