Switch
Turns one setting on or off. A track and a thumb in three sizes, with its own label and description, or alone where a title names it.
<Switch defaultChecked description="Runs can be started by hand, besides the triggers.">Manual runs</Switch>Installation
import { Switch, SwitchGroup } from "@dome-systems/ds-dashboard/components";Usage
import { Switch, SwitchGroup } from "@dome-systems/ds-dashboard/components";<Switch checked={enabled} onCheckedChange={setEnabled}>Manual runs</Switch>Anatomy
- 1 — Track. A pill with a 1px ring inside it: 20 × 12, 24 × 14 or 32 × 18. Off, the secondary text color at 40%; on, the brand color. Hover darkens it a step. It is what you press.
- 2 — Thumb. Wider than tall (10 × 8, 12 × 10 or 18 × 14), 2px inside the track. Off, a small secondary button; on, white. It slides to the right in 250ms, and a press stretches it toward the side it is leaving.
- 3 — Label. The setting's name, 8px after the track (sm: 6px), medium or regular. An info icon and a badge can follow it on its line.
- 4 — Description. A line of help under the label, in the secondary text. The track stays on the label's first line.
Sizes
Three sizes. One size sets the track and its text: sm is 20 × 12 with 12px text, and md, the default, is 24 × 14 with 13px text. lg is 32 × 18 and has no text of its own: it is the control at the end of a horizontal Field, whose title names it. Asked for lg, a switch with text draws md.
<Switch size="sm" defaultChecked>Retry failed runs</Switch><Switch size="md" defaultChecked>Retry failed runs</Switch><Switch size="lg" defaultChecked aria-label="Retry failed runs" />Off, on, and who owns the state
Off, the thumb sits at the left: a small secondary button on a gray track. On, it sits at the right: white on the brand color. defaultChecked sets where the switch starts, and the switch keeps its own state after that. checked with onCheckedChange gives the state to the screen. Every dashboard switch is controlled.
const [on, setOn] = useState(true);
<Switch>Weekly summary</Switch><Switch defaultChecked>Daily summary</Switch><Switch checked={on} onCheckedChange={setOn}>Manual runs</Switch><Button size="xs" onClick={() => setOn(!on)}>Flip it from outside</Button>Disabled, read-only and invalid
disabled dims the track to half strength, off or on. It answers no press and no hover, and Tab skips it. It still shows its state, and its label keeps its color. readOnly is Base UI's: the switch stays in the tab order and a press does nothing. It has no look of its own, and no dashboard switch uses it. aria-invalid draws the Input's 1px red edge round the track, and its red band while focused. Inside a Field, the Field's error says what is wrong.
<Switch disabled>Pause on quota</Switch><Switch disabled defaultChecked>Pause on quota</Switch><Switch readOnly defaultChecked>Audit every call</Switch><Switch aria-invalid>Sign in with a password</Switch>Its text, and a SwitchGroup
The text after the track is children. The switch and its text are one label, so a press on the text flips the switch. description is a line of help under the label, and the track stays on the label's first line. weight is medium (the default) or regular, for a long list or a switch among other text, as in the guard chain's toolbar (components/guards/guard-chain-toolbar.tsx). badge takes a Badge on the label's line: md beside 13px text, sm beside 12px. iconTooltip draws an info icon that explains the setting on hover or focus. A press on it does not flip the switch. SwitchGroup stacks two switches or more 8px apart, each its own setting, md unless it names its size. It is a role="group" and nothing names it for you: give it an aria-label. A Field does not name a SwitchGroup as it names a CheckboxGroup or a RadioGroup; inside a Field each switch is still read with the Field's description and error.
<SwitchGroup aria-label="Run settings"> <Switch defaultChecked description="Runs can be started by hand, besides the triggers.">Manual runs</Switch> <Switch defaultChecked weight="regular">Show detailed guard steps</Switch> <Switch badge={<Badge color="info" size="md">Preview</Badge>}>Weekly summary</Switch> <Switch defaultChecked iconTooltip="A failed run is tried again, up to three times.">Retry failed runs</Switch></SwitchGroup>Without text
With no children it is the switch alone, for a place that names it already. A horizontal Field, a FieldGroup's switch and a card title's switch name it for you. Anywhere else, give it an aria-label. On a switch with text, an aria-label names it instead of the text, for a list where every row shows the same word. The text stays on screen and still flips the switch.
<Switch defaultChecked aria-label="Allow manual runs" /><Switch defaultChecked weight="regular" aria-label="Let people on example.com join automatically">Auto-join</Switch>In a card's row
A horizontal Field puts its title and description on the left and the switch at the row's end, as the Run now row does (components/agents/manual-runs-strip.tsx). There the switch is lg without being asked, the Field's title names it and its description describes it, and the row pads the card inset, 16px, on all four sides. That bare switch is the one exception: stacked, a Field holds a full Switch with its own label under the Field's description, whether it holds one or several. A switch with no Field over it at all, the Switch alone with its own label and description in a row that pads the same (SettingSwitchRow, as on a quota's Enabled, components/models/quota-form.tsx), is still an open question.
<Card className="w-full"> <FieldGroup orientation="horizontal" title="Runs"> <Field title="Run now" description="Can be started by hand."> <Switch defaultChecked /> </Field> <Field title="Retry failed runs" description="A failed run is tried again, up to three times."> <Switch /> </Field> </FieldGroup></Card>A group's or a card title's switch
FieldGroup takes a switch: the Switch's props, drawn as an md switch before the title and named by it. It turns the group's Fields on or off: off, they dim and can't be used, or hide (off="hide", as in components/agents/agent-form.tsx). CardTitle takes the same switch, and the card's description then lines up with the title's text.
<Card className="w-full"> <FieldGroup orientation="horizontal" title="Restrict who can act as this agent" switch={{ defaultChecked: true }}> <Field title="Allowed emails"> <Input placeholder="name@example.com" /> </Field> </FieldGroup></Card>In a menu row
A DropdownMenuItem with indicator="switch" draws an sm switch at the row's end, for a setting of the menu itself: the table's Columns menu has one (ds/components/table/toolbar.tsx). The row is the control: it flips on a press and keeps the menu open. The switch is drawn only, hidden from screen readers, which get the row as a menuitemcheckbox.
const [responsive, setResponsive] = useState(true);
<DropdownMenu> <DropdownMenuTrigger render={<Button iconStart={Sliders} />}>Columns</DropdownMenuTrigger> <DropdownMenuContent> <DropdownMenuItem iconStart={ArrowsLeftRight} indicator="switch" checked={responsive} onCheckedChange={setResponsive}> Responsive </DropdownMenuItem> </DropdownMenuContent></DropdownMenu>In a form
Base UI keeps a hidden checkbox beside the track, so a switch can be sent with a form: name names it, value is what is sent when on (on by default) and uncheckedValue when off (nothing by default). required and form pass through too. Whether a switch belongs in a form that has a Save is an open question.
<Switch name="notify" value="yes" uncheckedValue="no" defaultChecked>Email the owner when a run fails</Switch>In the dashboard
The dashboard draws 31 switches in 25 files, and 5 more through a FieldGroup's switch. 20 are the switch alone, beside a title that names it. 11 carry their own text, 5 of those with a description. None sets size: the place picks it. Each card below is a copy of a real use and names its file.
A row in a table
One md switch per row, named for its row: "nightly-sync fires this agent". Without the permission it is disabled, and still shows its state.
components/agents/agent-triggers-card.tsx
A switch that asks first
Turning audit streaming on or off opens a dialog. The switch moves only once the dialog is accepted.
components/audit/siem-stream-card.tsx
With On or Off before it
Two organization settings print the state as a word before the switch (the other is org-mcp-sign-in-card.tsx). See the open question.
components/settings/org-previews-card.tsx
API Reference
Switch
The Switch is Base UI's Switch.Root with its Switch.Thumb drawn for you, plus the text props it shares with the Checkbox and the Radio. Besides these, it takes every prop of a <span> (title, data-testid…), which lands on the track. The dashboard's own components/ui/switch.tsx renders this switch and passes every prop through.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | "lg" | "md" | The track, and the text with it. Left out, it is lg as a horizontal Field's control and md anywhere else. With its own text, lg draws md. |
children | ReactNode | — | The label, after the track. None for a switch that something else names. |
weight | "medium" | "regular" | "medium" | The label's weight. |
description | ReactNode | — | A line of help under the label. It describes the switch to a screen reader. |
badge | ReactNode | — | After the label, on its line: a Badge, md beside an md label and sm beside an sm one. |
iconTooltip | string | TooltipSettings | — | An info icon after the label: the tooltip's text, or the text with the tooltip's settings. |
checked | boolean | — | Whether it is on, when the screen owns the state. Pair it with onCheckedChange. |
defaultChecked | boolean | false | Whether it starts on, when the switch owns its state. |
onCheckedChange | (checked: boolean, eventDetails: Switch.Root.ChangeEventDetails) => void | — | Called on each flip, with the new state. |
disabled | boolean | false | Dims the track, and it answers nothing. It still shows its state. |
readOnly | boolean | false | It can be focused and read, and a press does not flip it. No look of its own. |
required | boolean | false | It must be on before its form is sent. |
aria-label | string | — | Names a switch with no text. On a switch with text, it names the switch instead of the text. |
aria-invalid | boolean | — | The Input's 1px red edge round the track, and its red band while focused. |
name | string | — | The field's name when a form is sent. |
value | string | "on" | What the form sends while it is on. |
uncheckedValue | string | — | What the form sends while it is off. By default, nothing. |
form | string | — | The id of the form that owns it, for a switch drawn outside that form. |
id | string | — | The id of the hidden input, which a <label htmlFor> points at. |
inputRef | Ref<HTMLInputElement> | — | A ref to the hidden input. |
render | ReactElement | ((props, state) => ReactElement) | — | Base UI's: draws the track as another element. No dashboard switch uses it. |
nativeButton | boolean | false | Base UI's: says the element given to render is a real button. |
className | string | — | On the track, for where the switch sits. Not for its size or its colors. |
SwitchGroup
A <div role="group"> that stacks its switches 8px apart and keeps each at md, even as a horizontal Field's control. Besides these, it takes every prop of a <div>.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Two switches or more, each with its own label. |
aria-label | string | — | Names the group for screen readers, when no Field title does. |
className | string | — | On the group, for where it sits. |
Rules
Open questions
What does a switch look like while its write is in flight?
OpenThe Switch has no pending look. Screens disable it from the press until the answer comes, so a second press can't race the first, and it shows what the server last said. A wait is the Loader everywhere else, never a spinning circle. Nothing says where it goes on a switch.
Atlassian draws a spinner inside the toggle (isLoading), on a toggle whose state the caller holds. Primer has a loading state, with a label for it that is held back two seconds by default (loadingLabelDelay). shadcn/ui, Base UI and Polaris have none.
A switch in a form that has a Save
OpenOn a settings page a switch writes at once. A create form and some drawers hold switches in a draft that Save sends: a quota's Enabled, a trigger's Enabled, a subscription's Active, the agent form's group switches.
Atlassian: a toggle never needs a button to apply, its toggle does not work inside its form component by default, and a setting that needs a button is a checkbox. Polaris: don't pair a switch with a save button. Primer: a toggle saves at once, a checkbox waits for a save. shadcn/ui shows an invalid switch and no form.
One switch with no Field over it: does it stay a row of its own?
OpenSettingSwitchRow is the Switch alone in a card's row, with its own label and description and the switch first. What was decided covers a switch in a Field (the rules under In a Field); whether this row stays as it is, or becomes a Field, was not decided.
Primer's default is one row, the switch across from its label and description, and it allows a stacked layout. shadcn/ui's examples show both: the switch before a plain label, and after a label with a description. Polaris puts the label next to the control. Atlassian's pages don't say where it sits.
On or Off printed beside the switch
OpenTwo organization cards print the state as a word before the switch: Preview features and MCP sign-in. No other switch does, and the Switch has no prop for it.
Primer prints On or Off beside the track, and lets you rename the two words and move them (buttonLabelOn, buttonLabelOff, statusLabelPosition). shadcn/ui, Base UI, Atlassian and Polaris have no prop for it.
Switch or checkbox
A switch for what changes at once, a checkbox for what waits for a button
Use a switch when the setting changes the moment it is flipped. Use a checkbox when the choice waits for a form's button, and to pick rows from a list.
A switch has two states and no "some": a parent of mixed children is a checkbox. Two switches that must never both be on are one choice among several: a RadioGroup or a Select.
From Atlassian (a toggle applies with no button to press, and a setting that needs a button is a checkbox), Primer (a toggle saves at once, a checkbox waits for a save, and a toggle never replaces a checkbox) and Polaris (a switch for a setting that needs no save, a checkbox for a choice that is submitted). Atlassian also points to radio buttons or a dropdown menu to pick one option from several. Not decided for the dashboard, which also holds switches in forms that have a Save: see the open question.
Labels
The label names the setting, not the state
Name what is being turned on, as a noun or a short phrase: Manual runs, Auto-join, Email the owner when a run fails. The label stays the same when the switch flips. The switch already says its state, on screen and to a screen reader.
From Atlassian (the same label whether it is on or off), Primer (a short label that does not describe the state) and Polaris (a label that makes clear what the switch controls).
Every switch has a name
A switch with text is named by its text. A switch alone sits beside a visible title: a horizontal Field, a FieldGroup's switch and a card title's switch wire the name for you, and anywhere else it takes an aria-label. In a list where every row shows the same word, name each switch for its row.
From Base UI (a form control must have an accessible name), Atlassian (a visible label first, its hidden label only where none fits) and Primer (a visible label, always).
Say what turning it on does
When the label alone leaves a doubt, the description says what on means, or what off costs. Nobody should have to flip a switch to find out what it does.
From Polaris (explain what flipping it changes, most of all when it touches data) and Atlassian (a tooltip that says what will happen).
Failing and disabled
If the write fails, it goes back and says why
The switch shows the saved state again, and a toast from mutationFailureToast says what happened and what to do next. It does not stay on a state the server refused.
From ui/dashboard/CLAUDE.md (every failed mutation reports through mutationFailureToast) and what the dashboard does today.
A disabled switch says why
A switch is disabled when the viewer lacks the permission, when something else must happen first, or while it saves. For the first two, say which: in the description, in a line beside it, or in a tooltip on the switch. It still shows its state, so someone who can't change a setting can still read it.
From Atlassian (say why the option is not available) and Polaris (say why, and what would give access).
In a Field
One switch beside its title is a bare toggle at the far edge
In a horizontal Field one switch is the exception. It is a bare toggle alone at the far edge, named by the Field's title, with no label or options of its own.
From Decided by the designer.
Stacked, one switch is a full Switch under the description
Stacked, one switch and several are the same element. The Field's title and description come first, then under them a full Switch with its own label (and its description, info icon and badge), once or more. A stacked switch is never beside the Field's title.
From Decided by the designer.
Padding and size
A row that holds a switch pads 16px around it
A Field that is a card's row finds the switch and pads itself. A row built by hand uses p-card-inset.
From the dashboard's hard rules, rule 10: a row pads 12px around text alone and 16px around a control, and a switch counts.
The place picks the size, and one size sets the track and its text
lg is the bare switch at the end of a horizontal Field, and the Field picks it. md is every switch with its own text, a group's switch and a card title's. sm is a menu row, and a place with 12px text. No dashboard switch sets size today. Don't give the track one size and the text another, or make a size with a class.
From ds/components/switch.tsx, and the Switch and Checkbox rows of ds/README.md.
Accessibility
Role. The track is a role="switch" with aria-checked, Base UI's. A hidden checkbox beside it carries the value in a form: it is aria-hidden and out of the tab order. In a menu row, the row is a menuitemcheckbox with aria-checked, and the drawn switch is aria-hidden.
Keyboard. Tab reaches it. Space and Enter flip it, and focus stays on it. Focus draws the Button's 3px ring round the track. A disabled switch is aria-disabled and Tab skips it. A read-only one is aria-readonly: Tab reaches it and it does not flip.
Name. With text, the label names the switch (aria-labelledby) and the description describes it (aria-describedby). The pair is one <label>, so a press on the text flips it. With no text, the name is an aria-label or the title of the Field, FieldGroup or card that holds it. A horizontal Field's description describes it too. An aria-label on a switch with text replaces the text as its name.
What a screen reader says. From knowledge, not tested with one: the name, the role and the state ("Manual runs, switch, on"), then the description.
Not color alone. The state is the thumb's place: left is off, right is on. The track's color repeats it. An invalid switch has its red edge and, in a Field, the Field's error text.
Target. The press target is larger than the track: 12px past each side and 8px above and below, so an md switch answers on 48 × 30px. With text, the whole label is the target.
Motion. The thumb slides in 250ms and stretches under a press. With reduced motion asked for, it changes place with no transition.
What others expose
Read on 2026-11-14, each on its own site or in its own repository: shadcn/ui's Switch, Base UI's Switch (the primitive ours sits on), Atlassian's Toggle, Primer's ToggleSwitch, and Polaris's Switch. For Polaris that is the s-switch web component on shopify.dev: Polaris React has no switch, only a deprecated Setting toggle. Going the other way, ours carries its label, description, badge and info icon itself, and picks its size from its place. Of the five, only Polaris builds the label and the help text in.
| What | Who has it | Ours, and the verdict |
|---|---|---|
| A loading state | Atlassian (isLoading), Primer (loading, loadingLabel, loadingLabelDelay) | None. A screen disables the switch while it saves. Ask: the first open question. |
| On / Off text beside the track | Primer (buttonLabelOn, buttonLabelOff, statusLabelPosition) | None. Two screens print it by hand. Ask: the fourth open question. |
| Where the label sits | Primer (across from the switch, or stacked), shadcn/ui (a Field around it, the switch on either side) | Text after the track; or no text, in a horizontal Field with the title on the left. Ask: the third open question. |
| A hidden label | Atlassian (label), Polaris (accessibilityLabel, labelAccessibilityVisibility) |
Nothing missing: the standard attribute does it. |
| An error message of its own | Polaris (error); shadcn/ui marks its Field invalid |
Nothing missing: the Field owns the message for every control. |
| A choice card: the whole card flips the switch | shadcn/ui | None. The target is the track and its text. Not built. |
| A read-only look | Base UI (data-readonly, to style) |
Not built. No dashboard switch is read-only: one the viewer may not change is disabled. |
| Right to left | shadcn/ui | The thumb travels with a physical offset, left to right. Not built. |