Next Chapter Begins 🚀Read the full story

ToggleButtonGroup

An unstyled container that groups multiple toggle buttons with single or multiple selection.

Coordinate multiple ToggleButton controls under a shared value with single or multiple selection and complete control over layout and styling.

Features#

  • Manages a shared value across multiple ToggleButton.Root items
  • multiple for multi-selection, allowEmpty to permit an empty selection
  • Works with the compound ToggleButton API (Root, Indicator)

Usage#

import { ToggleButton } from 'primereact/togglebutton';
import { ToggleButtonGroup } from 'primereact/togglebuttongroup';
<ToggleButtonGroup allowEmpty={false} multiple={false}>
    <ToggleButton.Root value="left">
        <ToggleButton.Indicator>
            <i className="pi pi-align-left" />
        </ToggleButton.Indicator>
    </ToggleButton.Root>
    <ToggleButton.Root value="center">
        <ToggleButton.Indicator>
            <i className="pi pi-align-center" />
        </ToggleButton.Indicator>
    </ToggleButton.Root>
</ToggleButtonGroup>

API#

ToggleButtonGroup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ToggleButtonGroupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ToggleButtonGroupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceToggleButtonGroupInstance—
The instance to pass to the component.
ptSafeRecord<ToggleButtonGroupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ToggleButtonGroupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valueunknown—
Value of the ToggleButtonGroup.
defaultValueunknown—
The default value of the ToggleButtonGroup.
multiplebooleanfalse
When present, it specifies that the ToggleButton group allows multiple selections.
allowEmptybooleantrue
When present, it specifies that the ToggleButton group allows empty selection.
size"small" | "large" | "normal"—
Defines the size of the ToggleButton components.
disabledbooleanfalse
When present, it specifies that the ToggleButton group should be disabled.
invalidbooleanfalse
When present, it specifies that the ToggleButton group is invalid.
fluidboolean—
Spans 100% width of the container when enabled.
onValueChange(event: ToggleButtonGroupValueChangeEvent) => void—
Callback function that is called when the ToggleButton group value changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"togglebuttongroup"
data-part"root"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-multiplePresent when multiple selection active
data-allow-emptyPresent when empty selection allowed

Accessibility#

Screen Reader#

ToggleButtonGroup uses role="group" and should have an aria-label describing the group's purpose. Each ToggleButton.Root uses aria-pressed to indicate its toggle state.

Keyboard Support#

KeyFunction
tabMoves focus to the next button.
spaceToggles the focused button.