---
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/"
---

# Switch

An on/off control for a setting that takes effect at once, for React and Tailwind CSS. Free, MIT.

Free. Its export: `Switch`.

## Try it

Press the switch (or Space on it) to turn the digest on and off; switch its size and disable it from the panel.

Nothing is saved: the switch only says its state.

## When to use

- An on/off control for a setting that takes effect at once.
- Also called: toggle.

## When not to use

- For a choice saved with a form use Checkbox.

## 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 Switch 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-switch
```

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

## Usage

```tsx
import { Switch } from '@/components/ui/goop/switch';

function NotificationSettings({ digest, onDigest }: { digest: boolean; onDigest: (on: boolean) => void }) {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex items-center justify-between gap-4">
        <label htmlFor="weekly-digest" className="text-base">
          Weekly digest of the Fieldwork notes
        </label>
        <Switch id="weekly-digest" checked={digest} onCheckedChange={onDigest} />
      </div>
      <div className="flex items-center justify-between gap-4">
        <label htmlFor="visit-reminders" className="text-base">
          Remind me the day before a site visit
        </label>
        <Switch id="visit-reminders" name="reminders" defaultChecked />
      </div>
    </div>
  );
}
```

- Fits: flow, settings (their recipes).
- height, width, corner, background, shadow, motion: add no class for these.

## API reference

### Options

- `size: md | sm | xs = md`
- `onCheckedChange?: (checked: boolean) => void` — Called after `onChange` with the switch's new state.
- `checked?: boolean`
- `defaultChecked?: boolean`
- `onChange?: (event: ChangeEvent<HTMLInputElement>) => void`
- `value?: string`
- `name?: string`
- `required?: boolean`
- `disabled?: boolean`
- `form?: string`

- State: checked (checked / defaultChecked / onCheckedChange)

## Keyboard

- Space: toggle

## Accessibility

- The native element answers the keyboard.
- hover, active, focus-visible, checked: the browser's own (:hover, :active, :focus-visible, :checked): write nothing
- 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

- [Checkbox](/themes/meadow/components/checkbox): A round box a person ticks to mark one thing done or chosen.
- [Select](/themes/meadow/components/select): One option from a short closed list.
- [Combobox](/themes/meadow/components/combobox): Pick one value from a list by typing.
- [Multi select](/themes/meadow/components/multi-select): A field holding several values picked from a fixed list.
