ToggleButton

Offer a similar experience as a checkbox or radio with the appearance of a button.

Anatomy

Composed Components

A ToggleButton uses the following components:

Usage

Variants

A toggle button can use different variants.

Sizes

A toggle button can vary in size.

Disabled

A toggle button can be disabled.

Loading

A toggle button can show a loading indicator. The button text is hidden but the button maintains the width that it would have if the text were visible.

Pending

Toggle buttons can indicate that a quick progress task is taking place (e.g., saving settings on a server). After a 1 second delay, an indeterminate spinner will be displayed in place of the button label and icon.

Fluid

A toggle button can be expanded to full width to fill its parent container.

Icon Only

A toggle button can contain only an icon. An accessible name must be provided through aria-label prop. See also WCAG practices.

Icon

A toggle button can contain icons.

End Icon

Nonstandard end icons can be provided to handle special cases. However, think twice before adding end icons, start icons should be your go-to.

Props

children?

The content to display in the button.

isFluid?

Whether or not the toggle button takes up the width of its container.

isLoading?

A toggle button can show a loading indicator.

size?

A toggle button can vary in size.

Defaults to md.
spinnerProps?

The props for the Spinner.

variant?

The visual style of the toggle button.

Defaults to primary.
id?

The id of the toggle button.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

type?

The behavior of the button when used in an HTML form.

Defaults to 'button'.
isSelected?

Whether the element should be selected (controlled).

defaultSelected?

Whether the element should be selected (uncontrolled).

isDisabled?

Whether the button is disabled.

autoFocus?

Whether the element should receive focus on render.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

Migration Notes

Coming from Orbiter, you should be aware of the following changes:

  • fluid has been renamed isFluid.
  • disabled has been renamed isDisabled.
  • checked has been renamed isSelected.
  • defaultChecked has been renamed defaultSelected.
  • inherit has been removed.
  • loading has been renamed isLoading.
  • onChange signature has been changed (no event is passed).
  • value has been removed, use the id instead.