# Switch

An on/off setting with a label.

- **Use it for**: A setting that applies as soon as it is flipped.
- **Not for**: Choices that only apply when a form is submitted. Try [Checkbox](https://unseenui.com/components/checkbox/).

## Installation

```bash
npm install @stackunseen/ui
```

## Usage

```tsx
import { Switch } from '@stackunseen/ui';
import { Field } from '@stackunseen/ui';
import '@stackunseen/ui/styles.css';

<Field label="Show release notes"><Switch checked={enabled} onCheckedChange={setEnabled} /></Field>
```

## Props

- `checked` (`boolean (optional)`): The controlled on/off state.
- `onCheckedChange` (`(checked: boolean) => void (optional)`): Receives the next state. Your application decides when to save the setting.
- `name` (`string (optional)`): The form-data key. The switch uses a native checkbox input.
- `disabled` (`boolean (optional)`): Prevents changes and excludes the switch from native form submission.

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `description` | `ReactNode` | Help text under the label, announced as the switch's description. |
| `label` | `ReactNode` | A visible label beside the switch. |
| `onCheckedChange` | `((checked: boolean) => void)` |  |

## Keyboard

Tab focuses the switch; Space toggles it. Disabled switches leave the tab order.

## Works with

[Field](https://unseenui.com/components/field/), [Input](https://unseenui.com/components/input/), [Textarea](https://unseenui.com/components/textarea/), [Select](https://unseenui.com/components/select/), [Checkbox](https://unseenui.com/components/checkbox/), [Alert](https://unseenui.com/components/alert/), [Button](https://unseenui.com/components/button/), [RadioGroup](https://unseenui.com/components/radio-group/), [TonePad](https://unseenui.com/components/tone-pad/), [Slider](https://unseenui.com/components/slider/), [InputGroup](https://unseenui.com/components/input-group/), [Combobox](https://unseenui.com/components/combobox/)

Page: https://unseenui.com/components/switch/
