ToggleButton

A toggle button component for selecting one or multiple options from a button group

Installation

Terminal
pnpm add @choice-ui/toggle-button

Import

Component.tsx
import { ToggleButton, type ToggleButtonProps, ToggleGroup, type ToggleGroupProps } from "@choice-ui/toggle-button"

Basic

- The `aria-label` prop is required. - This is a controlled component that requires `value` and `onChange` props to control its state.

Variants

The `variant` prop is used to set the variant of the toggle button.
- `default`: default variant - `secondary`: secondary variant - `highlight`: highlight variant
activedisabledfocusedrest

Tooltip

The `tooltip` prop is used to show a tooltip when the toggle button is hovered.
- The `aria-label` will be used as the tooltip's content if the content type is string.

Group

Group: Demonstrates the ToggleGroup component for managing related toggle buttons.
Features:
- Single selection mode (multiple=false): Only one button can be pressed at a time - Multiple selection mode (multiple=true): Multiple buttons can be pressed simultaneously - Automatic state management across the group - Keyboard navigation with arrow keys - Support for controlled and uncontrolled modes
Usage Guidelines:
- Use ToggleGroup for related toggle buttons that share state - Use single selection mode for mutually exclusive options - Use multiple selection mode for independent options - Provide aria-label for each ToggleGroup.Item
Only one button can be pressed at a time. Current value:
none
Multiple buttons can be pressed simultaneously. Current values:
none

Group Orientation

GroupOrientation: Demonstrates ToggleGroup with different orientations.
Features:
- Horizontal orientation (default): Buttons arranged in a row - Vertical orientation: Buttons arranged in a column - Keyboard navigation adapts to orientation (arrow keys)

Group Controlled

GroupControlled: Demonstrates controlled and uncontrolled ToggleGroup.
Features:
- Controlled mode: Use `value` and `onChange` props - Uncontrolled mode: Use `defaultValue` prop - Both modes support the same features
Current value:
1

Group Disabled

GroupDisabled: Demonstrates ToggleGroup with disabled state.
Features:
- Group-level disabled: All buttons in the group are disabled - Individual disabled: Specific buttons can be disabled while others remain enabled

API reference

ToggleButtonPropsTypeDefault
value
boolean -
onChange
((value: boolean) => void)
|
undefined
-
size
undefined
|
"default"
|
"large"
-
disabled
boolean
|
undefined
-
readOnly
boolean
|
undefined
-
className
string
|
undefined
-
active
boolean
|
undefined
-
event
undefined
|
"click"
|
"mousedown"
-
focused
boolean
|
undefined
-
tooltip
TooltipProps
|
undefined
-
variant
undefined
|
"default"
|
"secondary"
|
"highlight"
|
"reset"
-
ToggleGroupPropsTypeDefault
defaultValue
string[]
|
undefined
-
disabled
boolean
|
undefined
-
loopFocus
boolean
|
undefined
-
multiple
boolean
|
undefined
-
onChange
((value: string[]) => void)
|
undefined
-
orientation
undefined
|
"horizontal"
|
"vertical"
-
readOnly
boolean
|
undefined
-
value
string[]
|
undefined
-