# SwitchField

> A Switch with its label beside it, on the left or the right. A click on the words flips it too.

| | |
|---|---|
| Kind | pattern |
| Contract | `review` · [switch-field.contract.yaml](https://github.com/Runceanu/rost/blob/master/contracts/switch-field.contract.yaml) |
| Guidance | `agreed` |
| Source | [Figma 545:57](https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=545-57) · read 2026-10-31 · frozen 2026-10-31 |
| Implemented in | nowhere yet |

## Install

It lands in `src/rost/switch-field/`, with what it needs and its contract:

```sh
npx github:Runceanu/rost add switch-field
```

Then import `src/rost/fonts.css` and `src/rost/tokens.css` once, at the root of the app. More on this in [Install](https://rost.build/docs/install.md).

## Props

| Prop | Type | Values | Default |
|---|---|---|---|
| `label` | slot |  |  |
| `side` | enum | `Left` `Right` | `Right` |
| `switch` | node |  |  |
| `disabled` | boolean |  | `false` |

## Anatomy

- `root`: A row: the switch and its label, centred on each other.
- `switch`: A Switch, as it is. Its own states do the work: hover, press and focus are the switch's.
- `label`: A `<label for>` the switch. Paragraph type, in the colour a secondary action's label has. It doesn't change with on and off: the track says that.

## When to use

- **A setting with its name.** Any switch that people read before they flip: email me receipts, show cents, dark charts.
- **Label on the left.** A settings panel where the labels are long: the switches line up down the right edge, where the eye finds them.

## When not to use

- **A switch with no words.** A switch whose meaning comes from what's around it, like a row in a table. Use **Switch** with an `aria-label`.
- **A label that changes.** "On" and "Off" as the label. The track says that; the label says what it's for.

## Behaviour

The label is a `<label>` tied to the switch, so a click anywhere on the words flips it, the way a checkbox's label does. Hover, press and focus are the switch's own. Disabled fades both.

I made it when I took the label out of Switch so it could go on either side. In Figma it's on the switch page, next to Switch, with a real Switch instance inside that you can set on or off.

## Accessibility

- **Element**: A `<span>` holding the Switch's `<button role="switch">` and a `<label for>` it.
- **Name**: The label. SwitchField ties the two with an id, so you don't.
- **Keyboard**: The switch's: Tab reaches it, Space and Enter flip it.
- **Focus**: The switch's ring, around the track.

## Content

A short phrase in sentence case, saying what's on when it's on: "Email me receipts", not "Receipts: on/off".

## Tokens

Every token this component uses, across all its variants.

| Token | Resolves to |
|---|---|
| `font-family/base` | `'General Sans Variable'` |
| `opacity/gentle` | `0.24` |
| `spacing/gap/small` | `8px` |
| `switch-field/label` | `#d3d9d5` |
| `typography/paragraph/font-size` | `14px` |
| `typography/paragraph/font-weight/regular` | `400` |
| `typography/paragraph/letter-spacing` | `0px` |
| `typography/paragraph/line-height` | `20px` |

See it live, with every value of every variant: [rost.build/components/switch/#switch-field](https://rost.build/components/switch/#switch-field)
