useToggleButton

Provides the behavior and accessibility implementation for a toggle button component. ToggleButtons allow users to toggle a selection on or off, for example switching between two states or modes.

Example
ToggleButton.tsx
ToggleButton.css
import {ToggleButton} from './ToggleButton';

<ToggleButton>Pin</ToggleButton>

API

useToggleState(props: ): useToggleButton( props: <ElementType>, state: , ref: RefObject<any> ): <HTMLAttributes<any>>

ToggleState

Properties

NameType
isSelectedboolean

Whether the toggle is selected.

defaultSelectedboolean

Whether the toggle is selected by default.

Methods

setSelected(isSelected: boolean): void
Updates selection state.
toggle(): void
Toggle the selection state.

AriaToggleButtonProps

NameTypeDefault
isSelectedbooleanDefault:

Whether the element should be selected (controlled).

defaultSelectedbooleanDefault:

Whether the element should be selected (uncontrolled).

isDisabledbooleanDefault:

Whether the button is disabled.

childrenReactNodeDefault:

The content to display in the button.

elementTypeElementTypeJSXElementConstructor<any>Default: 'button'

The HTML element or React element used to render the button, e.g. 'div', 'a', or RouterLink.

onChange(isSelected: boolean) => voidDefault:

Handler that is called when the element's selection state changes.