Introducing PrimeReact v11-alpha 🎉Discover Now

ToggleButtonGroup

ToggleButtonGroup component is used to create a group of toggle buttons.

preview

Installation#

npx shadcn@latest add @primereact/ui/togglebuttongroup

Usage#

import { ToggleButtonGroup } from '@/components/ui/togglebuttongroup';
<ToggleButtonGroup>
    <ToggleButton value="option1">Option 1</ToggleButton>
    <ToggleButton value="option2">Option 2</ToggleButton>
</ToggleButtonGroup>

Examples#

Basic#

basic-demo

Controlled#

Use value and onValueChange properties to control the state of the ToggleButtonGroup.

controlled-demo

Multiple#

ToggleButtonGroup allows selecting only one item by default and setting multiple option enables choosing more than one item. In multiple case, model property should be an array.

multiple-demo

Sizes#

ToggleButtonGroup provides small and large sizes as alternatives to the base by using the size property.

sizes-demo

Invalid#

Invalid state is displayed using the invalid prop to indicate a failed validation. This style is useful when integrating with form validation libraries.

invalid-demo

Disabled#

When disabled is present, the element cannot be edited and focused entirely. Certain options can also be disabled using their disabled properties.

disabled-demo