Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Toggle

A two-state button that stays pressed until it is pressed again. Built on the @zag-js/toggle machine, which manages aria-pressed, keyboard interactions, and the data-state attribute used for styling.

React Togglelive
import { Toggle } from "@/components/ui/toggle";
<Toggle label="Show filters" />
<Toggle label="Show filters" defaultPressed />
Terminal window
npx @glaceon/cli add toggle --framework react # or svelte, solid
Element Data Attribute Value Description
root data-state "on" | "off" Applied based on the current pressed state.
root data-pressed "" Present when the toggle is pressed.
root data-disabled "" Present when the toggle is disabled.
Prop Type Default Description
label string "Toggle" Visible button text.
defaultPressed boolean false Uncontrolled initial pressed state.
disabled boolean false Prevents user interaction when true.
Key Description
Space / Enter Toggles the pressed state when focused.