---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Toggle button

A button that stays pressed until it is pressed again, for React and Tailwind CSS. Free, MIT.

Free. Its export: `ToggleButton`.

## Try it

Press it to hold it down, press again to let it up; switch every look and size, words or icon, and disable it.

No notes are filtered: the line under it only says the state.

## When to use

- A button that stays pressed until it is pressed again.
- Also called: toggle.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Toggle button on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing.

```sh
npx shadcn@4.23.1 add @goop/meadow-toggle-button
```

```text
Add the Goop Toggle button to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { ToggleButton, ToggleButtonIcon } from '@/components/ui/goop/toggle-button';

function NotesViewToggle({ grouped, onGrouped }: { grouped: boolean; onGrouped: (next: boolean) => void }) {
  return (
    <div className="flex items-center gap-1">
      <ToggleButton aria-label="Group into lists" pressed={grouped} onPressedChange={onGrouped}>
        <ToggleButtonIcon icon="text-align-justify" />
      </ToggleButton>
      <ToggleButton variant="muted" aria-label="Starred notes only" defaultPressed>
        <ToggleButtonIcon icon="star" />
      </ToggleButton>
      <ToggleButton variant="chip">Due date</ToggleButton>
    </div>
  );
}
```

- Fits: record, chat: toolbar.
- Also known as: Toggle.
- height, width, padding, gap, corner, background, shadow, text, motion: add no class for these.

## API reference

### Options

- `variant: default | muted | chip | outline = default`
- `size: md | lg = md`
- `shape: pill | circle = pill`
- `asChild?: boolean`
- `pressed?: boolean`
- `defaultPressed?: boolean = false`
- `onPressedChange?: (pressed: boolean) => void`
- `disabled?: boolean`

- State: pressed (pressed / defaultPressed / onPressedChange)

### Parts

- `ToggleButtonIcon` — The toggle's icon; icon: IconName — A pack icon name; pressedIcon?: IconName — The pack icon drawn instead while the toggle is pressed; none by default

- Class recipes (cva): toggleButtonVariants (ToggleButton)
- data-slot values (to select a part by): toggle-button, toggle-button-icon

## Keyboard

- Enter: toggle
- Space: toggle

## Accessibility

- The behaviour layer under the part answers keys, focus and dismissal: never write your own.
- hover, active, focus, focus-visible: the browser's own (:hover, :active, :focus, :focus-visible): write nothing
- pressed: the attribute aria-pressed
- disabled: the prop disabled

## Motion

- The part sets its own motion: add no transition or animation of your own.

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Toggle group](/themes/meadow/components/toggle-group): A row of toggle buttons that act together, one or several pressed, such as a list's filters or a view switch.
- [Link](/themes/meadow/components/link): A text link to another page or place.
- [Copy button](/themes/meadow/components/copy-button): A button that copies a value such as a link, a key or a command to the clipboard and says it was copied in place.
- [Menu button](/themes/meadow/components/menu-button): The button a menu opens from, shown as words, a workspace's tile or an icon.
