ToggleButton
ToggleButton is a button that stays pressed (aria-pressed), shown as a filled button. On its own, use selected and onChange. Put several in a ToggleButtonGroup and give each a value: by default any number can be pressed (value is an array), and with exclusive at most one (value is a string, or null when none is). Controlled with value + onChange, or uncontrolled with defaultValue.
The group takes the same layout props as ButtonGroup.
bold; aligned left
Props
ToggleButton
valuestringIdentifies the button inside a ToggleButtonGroup.
selectedbooleanDefault:falsePressed state when used on its own.
onChange(selected: boolean) => voidReceives the new pressed state when used on its own.
onClick(event) => voidClick handler.
childrenReactNodeContent.
...restAny other props are passed to the underlying element.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Identifies the button inside a ToggleButtonGroup. |
selected | boolean | false | Pressed state when used on its own. |
onChange | (selected: boolean) => void | – | Receives the new pressed state when used on its own. |
onClick | (event) => void | – | Click handler. |
children | ReactNode | – | Content. |
...rest | – | Any other props are passed to the underlying element. |
ToggleButtonGroup
valuestring | string[] | nullPressed value(s): a string or null with
exclusive, an array otherwise.defaultValuestring | string[] | nullInitial value when uncontrolled.
onChange(value) => voidReceives the new value (a string or null with
exclusive, an array otherwise).exclusivebooleanDefault:falseAllow at most one pressed button.
orientation'horizontal' | 'vertical'Default:'horizontal'Row or column (from ButtonGroup).
...ButtonGroupattached, fullWidth, aria-label and the other ButtonGroup props.
childrenReactNodeContent.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | string[] | null | – | Pressed value(s): a string or null with exclusive, an array otherwise. |
defaultValue | string | string[] | null | – | Initial value when uncontrolled. |
onChange | (value) => void | – | Receives the new value (a string or null with exclusive, an array otherwise). |
exclusive | boolean | false | Allow at most one pressed button. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Row or column (from ButtonGroup). |
...ButtonGroup | – | attached, fullWidth, aria-label and the other ButtonGroup props. | |
children | ReactNode | – | Content. |