Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Toggle for Astro

Astro pressed-state buttons for local on/off actions.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/toggle

Usage

---
import { Toggle } from "@/components/ui/toggle"
---
<Toggle>Toggle</Toggle>

Examples

Sizes and states

API Reference

ToggleProps

PropType
defaultPressed?boolean

Initial pressed state

Typeboolean
size?"default" | "lg" | "sm" | null | undefined
Type"default" | "lg" | "sm" | null | undefined
variant?"default" | "outline" | null | undefined
Type"default" | "outline" | null | undefined

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the toggle root. The root emits the outbound events.

Outbound events

Event Detail
toggle:change { pressed: boolean }

Inbound events

Event Detail
toggle:set { value: boolean }

Read the installed source for the complete prop types.

When to use Toggle

Use Toggle for a mode or action that stays pressed, such as a formatting option. Keep the label stable so the pressed state carries the change. Use the existing size and outline variants for density and grouping.

Keyboard and behavior

The data-slot controller updates aria-pressed and handles keyboard activation. A toggle does not save application data automatically. Use Toggle Group when adjacent toggles share a selection.

Theme and layout

Pressed, hover, focus, and disabled styles use the current theme. Check an icon-only toggle with an accessible name. Color should reinforce the pressed state, not be its only indication.