Skip to content

<sessions-switch>

An on/off toggle with a label.

Preact & React<Switch>GroupFormsDrawn asSwitch

Preview

Drawn by the same renderers Sessions uses for your extension, from the DOM example beside it, without its event handlers.

When to use it

Controlled: keep checked in your state and flip it in the change handler.

In Preact and React, import the component of the same name from @sessions/apps/preact or @sessions/apps/react. Attributes become camelCase props, a boolean attribute is a boolean prop, and an event is an on prop that receives the event’s detail.

Attributes

Attribute
label
The switch label.Prop label
checkedboolean
On.Prop checked
help-text
A line under the label.Prop helpText
disabledboolean
Non-interactive.Prop disabled

Events

changedetail: boolean — the new state
The switch was flipped.Prop onChange
Example
import {Switch} from '@sessions/apps/preact';

<Switch
  label="Show to buyers"
  checked={visible.value}
  onChange={(checked) => (visible.value = checked)}
/>

In the same group