Button
Buttons are used to for clearly indicating discrete clickable actions that can be communicated with a simple label or icon.
Default
Buttons are ButtonType.Primary
by default, and should contain a text label. For buttons with only an icon and no text, see . The button's children
are rendered inside it, allowing for labels, icons, or other elements.
Editable example
Best practices
- Stick to one primary button per view. The exception to this rule is contextual overlays that may appear within a view.
- Use short and clear labels. Avoid using more than three words, long complex words, and waffling sentences. For example, prefer
Create page
toCreate a new page
. - Use labels that communicate the effect of their action. Never use
Click here
.
Types
Button types are used to form a hierarchy of actions. To draw focus to a particular action, ButtonSize.Primary
can be used. Try to stick to a maximum of one primary action per context, and use ButtonType.Secondary
for less important actions. ButtonType.Tertiary
is useful for many densely grouped actions or to de-emphasize less important actions.
Editable example
Disabled
Disable a button to indicate that an action exists but is currently not possible, but will become available later. Disabling a button prevents all user interaction, and can cause issues with tooltips in certain browsers. Avoid disabling buttons in forms — it's often clearer to allow submission to be attempted but directly indicate errors with contextual error states on inputs.
Editable example
Sizes
Size should be used to match a button's size to other controls around it. For example, a button placed in context with inputs that are InputSize.Small
should use ButtonSize.Small
so that it looks proportional and related as part of the same UI.
Editable example
Width
By default, the button will fit the contents of itself plus a bit of padding. You can use the width
prop to either fill the container ("full"
) or half the width of the container ("half"
).
Editable example
Dark theme
Whenever a button is used on a dark background or within the context of other dark themed elements, use the ButtonTheme.Dark
theme
. By default, buttons use ButtonTheme.Light
. Even for primary and secondary buttons that are still visible on dark backgrounds using the light theme there are minor tweaks for better styling against dark backgrounds using the dark theme.
Editable example
Icons
Use an icon component as a child to add icons to a button.
Editable example
Decorators
Use the decorator
prop for common icon presets like arrows and chevrons. ButtonDecorator.Arrow
should be used to emphasize that an action will navigate the user to another route or context. ButtonDecorator.Dropdown
is used for buttons that trigger a menu or popover overlay.
Editable example
Async actions
A Button will automatically handle transitioning between loading states when onClick
returns a promise. A custom success message can be added with the successMessage
prop.
Editable example
States
Instead of automatically applying the waiting and success states, the button's state can be manually controlled by using the buttonState
prop.
Editable example
Destructive actions
For buttons that perform destructive actions such as deletion or removal, use the isDestructive
prop. It's also important to provide an icon or label that clearly indicates that the button will perform a destructive action such as "Delete" and not something vague like "Confirm".
Editable example
Link buttons
Setting an href
on a button will transform the underlying html element to an <a>
tag. Note that href
must be a function that returns the link. By default, links will open in a new tab. This can be changed by setting the openInSameTab
prop to true
.
Editable example