Button
Buttons allow users to take actions, and make choices, with a single click. They are typically found in forms, dialog, and toolbars. Some buttons are specialized for particular tasks, such as navigation or presenting menus.
Props
Usage guidelines
- Communicating an action that will occur.
- Triggering or enabling an action, such as submitting requested information.
- Progressing or regressing a user through a step in a flow.
- Directing users to a new page or different part within the same page. Instead, use Link.
- Limited space available. Consider using an IconButton instead.
Types & Roles
Size
Color
Color: transparent and semiTransparentWhite


Width
Icons
Selected state
ref
Accessibility: label
Accessibility: controls, expanded, & popup
Variants
This example illustrates two custom navigation implementations to externally control the link navigation behavior of Button: setting a default logic with OnLinkNavigationProvider and a custom component logic with the onClick
prop.
If onNavigation
prop is passed to OnLinkNavigationProvider, it's passed down to all children links and sets a custom default link navigation behavior. onLinkNavigation
is a higher-order function: it takes named arguments (href
and target
) and returns an event handler function. In the component's onClick
event handler, the onClick
prop gets called first, followed by the function passed down by the OnLinkNavigationProvider.
Button's onClick
prop is an event handler function. This callback takes 2 named parameters: 'event', the 'onClick' event, and disableOnNavigation
, a callback function that disables any default custom navigation logic set by OnLinkNavigationProvider. disableOnNavigation
is only accessible in OnLinkNavigationProvider's children components with link behavior.
In this example, Button has a parent OnLinkNavigationProvider setting a default custom navigation logic. We can compare three navigation behaviors: (a) the default Button behavior (by disabling the OnLinkNavigationProvider's inherited logic), (b) the default custom behavior set by OnLinkNavigationProvider and (c) a custom behavior set on Button.
onClick
is used to disable the default custom logic set in OnLinkNavigationProvider and implement custom behavior at the component level. disableOnNavigation
and customOnNavigation
are both called first during the 'onClick' event.
If onNavigation
is a custom hook function, it can contain complex logic, including React hooks, to perform side effects.
In this example, both onNavigation
and customOnNavigation
functions execute the following actions:
- Disable the default link behavior
- Show an alert message
- Open a different URL in a new window
Both onNavigationClick
, inside onNavigation
, and onClick
have event access to preventDefault(). It could also be used to stopPropagation().
Related
OnLinkNavigationProvider
OnLinkNavigationProvider allows external link navigation control across all children components with link behavior.
See custom navigation variant for examples.