Overview

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.

Best Practices

Buttons should:

  • Be clearly labeled and explicitly state what they do.
  • Be labeled with actionable verbs, following the Verb + Noun format except in the case of common actions like Save, Edit, Close, or Cancel.
  • Be positioned in consistent locations and in a sensible order.
  • Use spacing to separate them from other interactive content.
  • Not wrap text. For maximum legibility, a label should remain on a single line.

Buttons should not:

  • Be used in place of a more semantic element.

    • For navigation or actions that do not affect the state of the app, use 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.
    • For status chips, use 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.
  • Provide too many options at once with too many buttons.

Examples

Basic Buttons

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.

Code example
Playroom
This button is between text.

Button Actions

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.

Code example
Playroom

Button Colors

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.

info-icon
Note
Only a select handful of available colors are shown below. All theme properties and colors are supported.
Code example
Playroom

Button and Font Sizes

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.

Code example
Playroom

Button Icons

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.

Code example
Playroom

Disabled and Loading Buttons

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.

Code example
Playroom

Complex Buttons

EzButton can be used with other Recipe components to create more complex buttons.

Code example
Playroom

Legacy Buttons (Deprecated)

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.

warning-icon
Legacy buttons are deprecated as of v17 and will be removed in v18.
Code example
Playroom
Primary:
Secondary:
Tertiary:
Tertiary with icon:
Destructive:
Disabled:
Disabled with tooltip:
Loading:

Custom Styles

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

Accessibility

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.

Data Attributes

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.

Code example
Playroom

Props

NameTypeDefaultDescription
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.
*
 required