Toggle

A two-state button that can be either on or off.

Overview

The Toggle component provides a pressable button that switches between active and inactive states, commonly used for toolbar actions, formatting options, or feature toggles. Built on Base UI primitives, it features customizable variants, sizes, and smooth transitions.

Usage

import { Toggle } from "@tilt-legal/cubitt-components/primitives";
<Toggle aria-label="Toggle bold">
  <TextBold />
</Toggle>


Examples

Default

Basic toggle button with default styling.

Outline Variant

Toggle with outlined styling.

With Text

Toggle buttons can include both icons and text labels.

Sizes

Toggles in different sizes.

URL State

Sync toggle state with the URL. Try toggling and refreshing the page.


API Reference

Toggle

A pressable button that maintains pressed/unpressed state.

PropTypeDefaultDescription
pressedbooleanThe controlled pressed state of the toggle.
defaultPressedbooleanfalseThe default pressed state when uncontrolled.
onPressedChange(pressed: boolean) => voidCallback fired when the pressed state changes.
disabledbooleanfalseWhether the toggle is disabled.
variant"default" | "outline""default"Visual style variant of the toggle.
size"sm" | "md" | "lg""md"Size of the toggle button.
classNamestringAdditional CSS classes for the toggle.
aria-labelstringAccessible label for the toggle (required for icon-only).

URL State Props

When provided with a paramName, the toggle will sync its state with URL parameters via TanStack Router search params.

PropTypeDefaultDescription
paramNamestringURL parameter name for syncing state with URL. Enables URL state management.
paramValuebooleanControlled value for the URL parameter.
onUrlValueChange(pressed: boolean) => voidCallback when URL parameter value changes.
paramClearOnDefaultbooleantrueRemove URL param when value equals default.
paramThrottlenumberThrottle URL updates in milliseconds.
paramDebouncenumberDebounce URL updates in milliseconds.

Notes

  • Accessibility: Always provide aria-label for icon-only toggles to ensure screen reader users understand the button's purpose
  • State management: Use pressed and onPressedChange for controlled mode, or defaultPressed for uncontrolled mode
  • Multiple toggles: For related toggle buttons, consider using the ToggleGroup component which provides better keyboard navigation and state management
  • The component uses Base UI primitives with smooth transitions for state changes

On this page