- Prop
checked- Type
boolean | undefined- Default
- —
- Requirement
- optional
- Description
- —
Docs Components Forms
Switch
React example follows below.
Vue example follows below.
Angular example follows below.
Svelte example follows below.
Solid example follows below.
- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
import { Switch } from "@grassroot/ui-react";import * as React from "react";const switchFixture = { id: "switch", label: "Deploy on merge", description: "Ship prod when CI passes on main", checked: true,} satisfies { id: string; label: string; description: string; checked: boolean;}; export default function SwitchDemo() { const [on, setOn] = React.useState<boolean>(switchFixture.checked); return ( <div> <Switch label={switchFixture.label} description={switchFixture.description} checked={on} onChange={(e) => setOn(e.target.checked)} /> </div> );}- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
<script setup lang="ts">import { ref } from "vue";import { Switch } from "@grassroot/ui-vue";const switchFixture = { id: "switch", label: "Deploy on merge", description: "Ship prod when CI passes on main", checked: true,} satisfies { id: string; label: string; description: string; checked: boolean;}; const on = ref(switchFixture.checked);function onChange(event: Event) { on.value = (event.target as HTMLInputElement).checked;}</script> <template> <Switch :checked="on" @change="onChange"> <template #label>{{ switchFixture.label }}</template> <template #description>{{ switchFixture.description }}</template> </Switch></template>- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
import { Component, signal } from "@angular/core";import { GrassrootSwitch } from "@grassroot/ui-angular";const switchFixture = { id: "switch", label: "Deploy on merge", description: "Ship prod when CI passes on main", checked: true,} satisfies { id: string; label: string; description: string; checked: boolean;}; @Component({ selector: "app-switch-demo", standalone: true, imports: [GrassrootSwitch], template: ` <grassroot-switch [checked]="on()" [label]="fixture.label" [description]="fixture.description" (checkedChange)="on.set($event.checked)" /> `,})export class SwitchDemoComponent { protected readonly fixture = switchFixture; protected readonly on = signal<boolean>(switchFixture.checked);} export default SwitchDemoComponent;- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
<script lang="ts"> import { Switch } from "@grassroot/ui-svelte"; const switchFixture = { id: "switch", label: "Deploy on merge", description: "Ship prod when CI passes on main", checked: true, } satisfies { id: string; label: string; description: string; checked: boolean; }; let on = $state(switchFixture.checked); function onChange(event: Event) { on = (event.target as HTMLInputElement).checked; }</script> <Switch label={switchFixture.label} description={switchFixture.description} checked={on} {onChange}/>- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
/** @jsxImportSource solid-js */import { createSignal } from "solid-js";import { Switch } from "@grassroot/ui-solid";const switchFixture = { id: "switch", label: "Deploy on merge", description: "Ship prod when CI passes on main", checked: true,} satisfies { id: string; label: string; description: string; checked: boolean;}; export default function SwitchDemo() { const [on, setOn] = createSignal<boolean>(switchFixture.checked); return ( <> <Switch label={switchFixture.label} description={switchFixture.description} checked={on()} onChange={(e) => setOn((e.target as HTMLInputElement).checked)} /> </> );}Installation
API Reference
Import
import { Switch } from "@grassroot/ui-react";
import * as React from "react";
Props
Prop
Type
Default
Requirement
Description
checkedboolean | undefined—
optional
—
defaultCheckedboolean | undefined—
optional
—
disabledboolean | undefined—
optional
—
readOnlyboolean | undefined—
optional
—
namestring | undefined—
optional
—
valuestring | undefined—
optional
—
requiredboolean | undefined—
optional
—
idstring | undefined—
optional
Seeds the part scope, so the hidden input/label/description ids are all deterministic from it [baseline #10].
toneTone | undefined"accent"optional
Brand colour of the "on" track.
onCheckedChange((detail: SwitchChangeDetail) => void) | undefined—
optional
—
onChangeReact.ChangeEventHandler<HTMLInputElement, Element> | undefined—
optional
—
"aria-label"string | undefined—
optional
Accessible name when neither `label` nor `description` is rendered.
classNamestring | undefined—
optional
—
- Prop
defaultChecked- Type
boolean | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
disabled- Type
boolean | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
readOnly- Type
boolean | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
name- Type
string | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
value- Type
string | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
required- Type
boolean | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
id- Type
string | undefined- Default
- —
- Requirement
- optional
- Description
- Seeds the part scope, so the hidden input/label/description ids are all deterministic from it [baseline #10].
- Prop
tone- Type
Tone | undefined- Default
"accent"- Requirement
- optional
- Description
- Brand colour of the "on" track.
- Prop
onCheckedChange- Type
((detail: SwitchChangeDetail) => void) | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
onChange- Type
React.ChangeEventHandler<HTMLInputElement, Element> | undefined- Default
- —
- Requirement
- optional
- Description
- —
- Prop
"aria-label"- Type
string | undefined- Default
- —
- Requirement
- optional
- Description
- Accessible name when neither `label` nor `description` is rendered.
- Prop
className- Type
string | undefined- Default
- —
- Requirement
- optional
- Description
- —
Events
| Event | Payload |
|---|---|
onCheckedChange | ((detail: SwitchChangeDetail) => void) | undefined |
Content regions
childrendescriptionlabel
Native attributes
Standard DOM and ARIA attributes not listed above spread onto the root element.
Import
import { ref } from "vue";
import { Switch } from "@grassroot/ui-vue";
Props
Prop
Type
Default
Requirement
checkedboolean | undefinedundefinedoptional
defaultCheckedboolean | undefinedundefinedoptional
disabledboolean | undefinedundefinedoptional
readOnlyboolean | undefinedundefinedoptional
namestring | undefinedundefinedoptional
valuestring | undefinedundefinedoptional
requiredboolean | undefinedundefinedoptional
idstring | undefinedundefinedoptional
toneTone"accent"optional
- Prop
checked- Type
boolean | undefined- Default
undefined- Requirement
- optional
- Prop
defaultChecked- Type
boolean | undefined- Default
undefined- Requirement
- optional
- Prop
disabled- Type
boolean | undefined- Default
undefined- Requirement
- optional
- Prop
readOnly- Type
boolean | undefined- Default
undefined- Requirement
- optional
- Prop
name- Type
string | undefined- Default
undefined- Requirement
- optional
- Prop
value- Type
string | undefined- Default
undefined- Requirement
- optional
- Prop
required- Type
boolean | undefined- Default
undefined- Requirement
- optional
- Prop
id- Type
string | undefined- Default
undefined- Requirement
- optional
- Prop
tone- Type
Tone- Default
"accent"- Requirement
- optional
Events
| Event | Payload |
|---|---|
checked-change | (_detail: SwitchChangeDetail) => true |
change | (_event: Event) => true |
Content regions
defaultdescriptionlabel
Import
import { Component, signal } from "@angular/core";
import { GrassrootSwitch } from "@grassroot/ui-angular";
Props
Prop
Type
Default
Requirement
checkedboolean—
optional
defaultCheckedboolean—
optional
disabledboolean—
optional
readOnlyboolean—
optional
namestring—
optional
valuestring—
optional
requiredboolean—
optional
idstring—
optional
labelstring—
optional
descriptionstring—
optional
toneTone"accent"optional
- Prop
checked- Type
boolean- Default
- —
- Requirement
- optional
- Prop
defaultChecked- Type
boolean- Default
- —
- Requirement
- optional
- Prop
disabled- Type
boolean- Default
- —
- Requirement
- optional
- Prop
readOnly- Type
boolean- Default
- —
- Requirement
- optional
- Prop
name- Type
string- Default
- —
- Requirement
- optional
- Prop
value- Type
string- Default
- —
- Requirement
- optional
- Prop
required- Type
boolean- Default
- —
- Requirement
- optional
- Prop
id- Type
string- Default
- —
- Requirement
- optional
- Prop
label- Type
string- Default
- —
- Requirement
- optional
- Prop
description- Type
string- Default
- —
- Requirement
- optional
- Prop
tone- Type
Tone- Default
"accent"- Requirement
- optional
Events
| Event | Payload |
|---|---|
checkedChange | SwitchChangeDetail |
change | Event |
Content regions
defaultdescriptionlabel
Import
import { Switch } from "@grassroot/ui-svelte";
Props
Prop
Type
Default
Requirement
checkedboolean—
optional
defaultCheckedboolean—
optional
disabledboolean—
optional
readOnlyboolean—
optional
namestring—
optional
valuestring—
optional
requiredboolean—
optional
idstring—
optional
toneTone"accent"optional
classNamestring—
optional
onCheckedChange(detail: SwitchChangeDetail) => void—
optional
onChange(event: Event) => void—
optional
- Prop
checked- Type
boolean- Default
- —
- Requirement
- optional
- Prop
defaultChecked- Type
boolean- Default
- —
- Requirement
- optional
- Prop
disabled- Type
boolean- Default
- —
- Requirement
- optional
- Prop
readOnly- Type
boolean- Default
- —
- Requirement
- optional
- Prop
name- Type
string- Default
- —
- Requirement
- optional
- Prop
value- Type
string- Default
- —
- Requirement
- optional
- Prop
required- Type
boolean- Default
- —
- Requirement
- optional
- Prop
id- Type
string- Default
- —
- Requirement
- optional
- Prop
tone- Type
Tone- Default
"accent"- Requirement
- optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
- Prop
onCheckedChange- Type
(detail: SwitchChangeDetail) => void- Default
- —
- Requirement
- optional
- Prop
onChange- Type
(event: Event) => void- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onCheckedChange | (detail: SwitchChangeDetail) => void |
onChange | (event: Event) => void |
Content regions
childrendescriptionlabel
Import
import { createSignal } from "solid-js";
import { Switch } from "@grassroot/ui-solid";
Props
Prop
Type
Default
Requirement
checkedboolean—
optional
defaultCheckedboolean—
optional
disabledboolean—
optional
readOnlyboolean—
optional
namestring—
optional
valuestring—
optional
requiredboolean—
optional
idstring—
optional
toneTone"accent"optional
onCheckedChange(detail: SwitchChangeDetail) => void—
optional
onChange(event: Event) => void—
optional
classNamestring—
optional
- Prop
checked- Type
boolean- Default
- —
- Requirement
- optional
- Prop
defaultChecked- Type
boolean- Default
- —
- Requirement
- optional
- Prop
disabled- Type
boolean- Default
- —
- Requirement
- optional
- Prop
readOnly- Type
boolean- Default
- —
- Requirement
- optional
- Prop
name- Type
string- Default
- —
- Requirement
- optional
- Prop
value- Type
string- Default
- —
- Requirement
- optional
- Prop
required- Type
boolean- Default
- —
- Requirement
- optional
- Prop
id- Type
string- Default
- —
- Requirement
- optional
- Prop
tone- Type
Tone- Default
"accent"- Requirement
- optional
- Prop
onCheckedChange- Type
(detail: SwitchChangeDetail) => void- Default
- —
- Requirement
- optional
- Prop
onChange- Type
(event: Event) => void- Default
- —
- Requirement
- optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onCheckedChange | (detail: SwitchChangeDetail) => void |
onChange | (event: Event) => void |
Content regions
childrendescriptionlabel