Toggle

@sushindustries/ui

A button that stays down, and the single-select group of them - aria-pressed is the whole contract.

5 min read
View as MarkdownEdit on GitHub

Props

PropTypeDefaultDoes
childrenReactNode-What pressing it means.
pressedboolean-Drives aria-pressed and data-active. The state is the caller's - nothing moves on its own.
onPressedChange(pressed: boolean) => void-Handed the opposite of pressed, never the event.

ToggleGroupProps

PropTypeDefaultDoes
optionsreadonly { value: string; label: ReactNode }[]-The choices, keyed by value.
valuestring-The pressed option. One matching nothing leaves every button up.
onChange(value: string) => void-Handed the chosen value. Pressing the option already down fires it again.
labelstring-Announced name of the group.

Notes

ToggleToggleA button that stays down, and the single-select group of them - aria-pressed is the whole contract.@sushindustries/ui · content and ToggleGroup share no state between them - a standalone ToggleToggleA button that stays down, and the single-select group of them - aria-pressed is the whole contract.@sushindustries/ui · content is not aware of any ToggleGroup on the same page, so faking a single-select group out of several ToggleToggleA button that stays down, and the single-select group of them - aria-pressed is the whole contract.@sushindustries/ui · contents means enforcing mutual exclusivity by hand. ToggleGroup exists so that bookkeeping does not have to be reinvented per page; reach for it instead of composing ToggleToggleA button that stays down, and the single-select group of them - aria-pressed is the whole contract.@sushindustries/ui · contents the moment two options are meant to be exclusive.