Introducing PrimeReact v11-alpha 🎉Discover Now

ToggleButton

ToggleButton component is used to create a button that can be toggled on or off.

Migrating to PrimeReact v11: What Changed and Why
A hands-on guide to the new compound component API, headless hooks, and Tailwind-first theming in PrimeReact v11.
May 12
preview

Installation#

npx shadcn@latest add @primereact/ui/togglebutton

Usage#

import { ToggleButton } from '@/components/ui/togglebutton';
<ToggleButton>Toggle</ToggleButton>

Examples#

Basic#

basic-demo

Render Props#

This is called the render prop pattern. It allows using a function to customize what the component displays based on its internal state.

render-props-demo

Controlled#

Use pressed and onPressedChange properties to control the state of the ToggleButton.

controlled-demo

Size#

ToggleButton 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.

disabled-demo