form fields
<tc-switch>
Toggle switch — a styled, form-associated boolean control with keyboard and ARIA support.
import
"@ra9/tan-compose-kit/switch"
Props
| Name | Type | Default | Description |
|---|---|---|---|
checked | boolean | false | Whether the switch is on. Reflects to the host. |
name | string | "" | Field name for form submission. |
value | string | "on" | Value submitted under `name` when the switch is on. |
label | string | "" | Text rendered next to the switch. |
helper | string | "" | Small helper text below the row. |
error | string | "" | Error message; the switch's `aria-invalid` flips to true. |
disabled | boolean | false | Disables the control; reflects to the host. |
Events
| Event | Detail | When |
|---|---|---|
tc-change | { checked: boolean } | Fires when the user toggles the switch (click, Space, or Enter). |
CSS variables
| Variable | Default | Description |
|---|---|---|
--tc-switch-track-off | var(--tc-color-rule-strong, #d9cfb8) | Track color when off. |
--tc-switch-track-on | var(--tc-color-accent, #a16939) | Track color when on. |
--tc-switch-thumb | var(--tc-color-surface, #ffffff) | Color of the thumb. |
--tc-switch-fg | var(--tc-color-ink, #14171f) | Label color. |
--tc-switch-helper | var(--tc-color-ink-muted, #6b7280) | Helper text color. |
--tc-switch-error | var(--tc-color-danger, #b3261e) | Error message color. |
--tc-switch-font | var(--tc-font-sans, …) | Font family. |
Examples
Basic usage
States
With helper
Keyboard
Space and Enter both toggle the switch when it has focus. Click also works. The internal control is a <button role="switch"> so it's reachable via Tab order.
In a form
The switch is form-associated. It submits value under name only when on, matching native checkbox conventions.
Theming
Accessibility
- Built on a
<button role="switch">witharia-checkedreflecting state. - Keyboard activation via Space and Enter; the
:focus-visiblering is visible on keyboard focus. aria-invalidflips whenerroris set.- The label is associated with the switch via a wrapping
<label>— clicking the text also toggles.