Actions
Toggle
A button that stays pressed until it is pressed again, such as Bold in a text toolbar. It keeps one name (label) and reports its state with aria-pressed; a pressed toggle gets the primary tint. Pass icon with hideLabel for an icon-only toggle; it has a 44px touch target on phones.
In Spoonjoy
Spoonjoy, a recipe app, is built with Ouro HX (how).
In its source: app/routes/recipes.$id.tsx
Install
Once per app, with Tailwind CSS v4 and an @/* path alias (Ouro HX is built on Base UI, so --base base; skip -t in an existing app):
npx shadcn@latest init --base base --preset nova --yes --no-monoreponpx shadcn@latest add ourostack/ouro-ui/ouro-base#v1.2.13Then the component. From v0.8.0 it installs only the helpers it imports and never touches your stylesheet (Installing):
npx shadcn@latest add ourostack/ouro-ui/toggle#v1.2.13Or, with the @ouro namespace set up:
npx shadcn@latest add @ouro/ouro-base @ouro/toggleIts tests, stories and Playwright spec are optional. They need Vitest 4.1.11 or later, and from v0.8.0 never change a version your app has (Testing):
npx shadcn@latest add ourostack/ouro-ui/toggle#v1.2.13 ourostack/ouro-ui/toggle-tests#v1.2.13import { Toggle } from "@/components/ouro/toggle/toggle";Paths use shadcn's default @/ alias; the CLI rewrites them to yours.
Example
<Toggle label="Bold" icon={BoldIcon} hideLabel pressed={bold} onPressedChange={setBold} />
<Toggle label="Show completed" variant="outline" defaultPressed />Use instead when
- Use
ToggleGroupinstead for a row of related toggles with arrow-key focus. - Use
Switchinstead for a setting that takes effect at once, andCheckboxfor a form value.
Props
Type: ToggleProps.
className- Type:
string - Layout only: margins, grid placement (
mt-4). Appearance classes warn in development; usevariantandsizeinstead. defaultPressed- Type:
boolean - Default:
false - Whether the toggle starts on, when it keeps its own state.
disabled- Type:
boolean - Keeps the toggle from being pressed, and fades it.
hideLabel- Type:
boolean - Shows only the icon; the label stays the toggle's name for screen readers. Pass
iconwith it. icon- Type:
ToggleIcon - Icon before the label, or alone with
hideLabel. Pass the component, not an element:icon={BoldIcon}. label(required)- Type:
string - What the toggle turns on, such as "Bold". It is the button's name and stays the same while pressed:
aria-pressedsays whether it is on. Required: every toggle needs a name. onPressedChange- Type:
((pressed: boolean) => void) - Called with the new state when the person presses the toggle.
pressed- Type:
boolean - Whether the toggle is on, when you control it. Pair it with
onPressedChange. ref- Type:
Ref<HTMLButtonElement> - The button element.
size- Type:
"sm" | "md" | "lg" - Default:
"md" - Control size, as Button's: each is taller on phones and steps down to desktop density from the
smbreakpoint with a fine pointer. shadcn'sdefaultismd. variant- Type:
"outline" | "plain" - Default:
"plain" plainhas no border until pressed;outlinealways has one. Either way a pressed toggle gets the primary tint. shadcn'sdefaultisplain.
Native attributes
Also accepts the attributes in React's ButtonHTMLAttributes and HTMLAttributes (id, aria-*, event handlers), passed to the rendered element, except those named on this page.
Don't use
These are not props. Passing one fails the type check with the fix in the error, and in development a console message names the fix.
active: Not a prop. Ouro UI usespressed:<Toggle pressed>.checked: Not a prop. A toggle is pressed, not checked:<Toggle pressed>. For a setting, useSwitch.children: Not a prop. The label is a prop, so the toggle always has a name:<Toggle label="Bold">.defaultChecked: Not a prop. A toggle is pressed, not checked:<Toggle defaultPressed>.isPressed: Not a prop. Ouro UI usespressed:<Toggle pressed>.isSelected: Not a prop. Ouro UI usespressed:<Toggle pressed>.onChange: Not a prop: a button's change event never fires. UseonPressedChange:<Toggle onPressedChange={(pressed) => ...}>.onCheckedChange: Not a prop. Ouro UI usesonPressedChange:<Toggle onPressedChange={(pressed) => ...}>.selected: Not a prop. Ouro UI usespressed:<Toggle pressed>.startIcon: Not a prop. Ouro UI usesicon:<Toggle icon={BoldIcon}>.tone: Not a prop. A pressed toggle uses the primary tint;variant="outline"adds a border.
className is for layout only
Pass margins, width and grid placement (mt-4, w-full, col-span-2). Your classes always win over Ouro UI's: Toggle merges className last with cn (tailwind-merge), so a class that conflicts with its own replaces it.layout-classes
Appearance comes from props, not classes. In development, a class that sets appearance logs one warning per component instance, naming the prop to use instead. A class sets appearance when, after its variants (hover:, sm:) and any ! are removed, it starts with bg-, text-, border-, rounded-, shadow-, font-, ring-, from-, via-, to-, fill- or stroke-, or is border, rounded, shadow or ring, or has a dark: variant. Text wrapping, overflow and table layout classes (text-wrap, text-ellipsis, border-collapse) are layout and do not warn.
Alignment classes (text-center) warn too: set alignment on a parent element.
Claim sources
- layout-classes: test:registry/ouro/components/ouro/toggle/toggle.test.tsx::Toggle > lets app layout classes win
verify:testExists(registry/ouro/components/ouro/toggle/toggle.test.tsx::Toggle > lets app layout classes win)