Toggle

An on/off switch that flips when its command is heard: “dark mode”.

Speaking the command toggles the switch — the same trigger pattern as a button, applied to a boolean. Clicking and keyboard toggling work as on any switch, speech or no speech.

Basic toggle

Loading the React kit…

Hold anywhere and say:“dark mode”

Props

  • default Leading
  • default command
  • default false
React
Updates as you tick props
import { ListensToggle } from "@listenssoft/speechui-react";import { useState } from "react";
function Demo() {  const [enabled, setEnabled] = useState(false);  return (    <ListensToggle      label="Dark mode"      command="dark mode"      checked={enabled}      onChange={setEnabled}    />  );}

Bare mode (React)

React-only: bare renders just the underlying checkbox input so a parent supplies the visual switch — for Tailwind switches and design systems. className, id, and name forward to the input.

Loading the React kit…

Hold anywhere and say:“autopilot”

React
import { ListensToggle } from "@listenssoft/speechui-react";import { useState } from "react";
// bare mode: only the hidden checkbox is rendered — the parent supplies// the visual switch (here: a plain CSS pill driven by :checked).function Demo() {  const [on, setOn] = useState(false);  return (    <label style={{ display: "inline-flex", gap: 10, alignItems: "center" }}>      <ListensToggle        bare        command="autopilot"        label="Autopilot"        checked={on}        onChange={setOn}      />      <span>Autopilot is {on ? "on" : "off"}</span>    </label>  );}

What you can say

SayEffect
“dark mode”Toggles the switch once.
“…turn on dark mode please…”Also toggles — matching is contains. (The words “on/off” are not parsed; each match flips the current state.)
“dark mode … (again within ~1s)”Ignored by the per-command cooldown; repeat after a brief pause to flip back.

The toggle flips on each match rather than parsing an on/off argument — say it again to flip back. Pair it with listeningContent to show the current effect (“say: dark mode to turn off”).

API reference

React props for @listenssoft/speechui-react.

Props

PropTypeDefaultDescription
positionHorizontalPositionLeadingWhether the switch leads (left) or trails (right) the label. Import the HorizontalPosition enum.
listeningContentReactNodecommandContent shown beside the switch while the mic is open — a place for a hint like “say: volume to seventy”.
disabledbooleanfalseDisables the switch.

Extra props

PropTypeDefaultDescription
labelstring—Label text beside the switch; the spoken command fallback.
commandstringlabelThe spoken command that toggles the switch.
checkedbooleanfalseControlled checked state. Pair with onChange.
onChange(checked: boolean) => void—Called with the next state — click, keyboard, or speech.
barebooleanfalseRender only the underlying checkbox input — no label wrapper, track, or thumb — so a parent supplies the visual switch. className, id, and name forward to the input.
id / name / style / aria-labelstring · CSSProperties—Forwarded to the input element (style in bare mode) — pair with a parent <label htmlFor>.
classNamestring—Extra class name(s) on the root (the input in bare mode).
classNamesListensToggleClassNames—Per-part class overrides (input, track, thumb, label, listeningLabel). Each is appended after the component's own classes, so your rules win without extra specificity.

Styling hooks

classNames parts and CSS classes

HookTypeDefaultDescription
classNames.track / .listens-toggle-trackclass—The switch track.
classNames.thumb / .listens-toggle-thumbclass—The switch thumb.
classNames.input / .listens-toggle-inputclass—The visually-hidden checkbox input (the focus target).
classNames.label / .listens-toggle-labelclass—The label text; listeningLabel joins it while the mic is open.
--listens-success / --listens-track / --listens-toggle-thumbtoken—On color, off track color, and thumb color.

Behavior notes

  • React: bare mode is React-only; the equivalent elsewhere is composing your own switch with the command primitive.

Was this page helpful?