Skip to content
Velkin LogoVelkin Logo
Velkin
VELKIN/UI

Modern UI components for product teams and their AI agents. Lit core, typed wrappers, live MCP.

sales@velkinui.com

Product

  • Docs
  • Components
  • Studio
  • Pricing

Resources

  • Quick start
  • Blog
  • Changelog
  • Roadmap
  • Status

Project

  • About
  • Contact
  • License
  • Privacy
  • Terms

© 2026 Velkin. MIT core · Pro licenses available.

VELKIN

Switch

A toggle switch component with label, hint, and validation.

vu-switch · @velkin/react/switch

Copy page

Import

React
npm i @velkin/react

import { VuSwitch } from "@velkin/react/switch";

Examples

API

Props

PropTypeDefaultDescription
namestring—Form field name for submit (`name` attr).
defaultvaluestring—Value restored on `<form reset>` (`defaultvalue` attr).
formidstring—External `<form>` id (`formid` attr).
disabledboolean—Non-interactive; blocks toggle (`disabled` attr).
readonlyboolean—Focusable but cannot change checked state (`readonly` attr).
requiredboolean—Blocks valid submit when unchecked (`required` attr).
requiredmessagestring—Custom `valueMissing` message (`requiredmessage` attr).
labelstring""Plain-text label; slotted `label` wins when assigned.
hintstring""Helper text; `hint` slot wins when assigned.
idstring""Host id forwarded to the internal input.
valuestring""Form submit token when checked (`value` attr).
colorVuSwitchColor"primary"Intent palette token for the checked accent. Default: `"primary"`.
toneVuSwitchTone"normal"Neutral idle-track weight (`subtle`/`normal`/`strong`). Default: `"normal"`.
sizeVuSwitchSize"md"Track, gap, and label scale. Default: `"md"`.
variantVuSwitchVariant"default"Track paint recipe. Default: `"default"`.
arialabelstring—Accessible name when no visible label.
compactbooleanfalseTighter hint/error spacing (`compact` attr). Default: `false`.
defaultcheckedboolean—Restored by `reset()` / form reset (`defaultchecked` attr). Default: `false`.
showerrorsboolean—Shows validation after first blur when `required` (`showerrors` attr). Default: `false`.
validationactiveboolean—Drives invalid styling after activation (`validationactive` attr). Default: `false`.
invalidbooleanfalseTrue when last validation found errors (`invalid` attr). Default: `false`.
checkedboolean—Checked state (`checked` attr). Default: `false`.
ariaLabelstring""Inner input accessible name when no string or slotted label (icon-only).
defaultCheckedbooleanfalseTarget checked state for `reset()` and `<form>.reset()`; reflects as `defaultchecked`.
showErrorsbooleanfalseWhen true with `required`, shows `requiredMessage` after first blur if unchecked; reflects as `showerrors`.
validationActivebooleanfalseAfter first blur with `showerrors`, drives invalid styling and error text.

Events

EventDetailDescription
vu-changeVuSwitchChangeDetailUser toggle; `detail.checked` boolean; `detail.value` submit token or boolean.
vu-invalidVuSwitchValidationErrorDetailWhen validation messages are recomputed while `validationActive`.
vu-clearVuSwitchValueClearedDetailAfter `reset()` syncs state from `defaultChecked`.

Slots

SlotDescription
labelRich label markup; takes precedence over string `label` when assigned.
hintOptional helper copy (HTML); overrides string `hint` when assigned.
errorReplaces default validation message list when assigned.

CSS parts

PartDescription
fieldColumn that stacks the control row, optional hint, and optional error.
wrapperRow wrapper around the input and label.
inputThe native checkbox input used as the switch control (`role="switch"`).
labelThe label element for the switch row.
trackThe rounded track behind the thumb.
thumbThe sliding thumb on the track.
hintNeutral helper text under the label (string `hint` or `hint` slot).
error-messageRegion for `slot="error"` or stacked default validation lines.
error-lineOne default validation string when `slot="error"` is empty.
textString `label` text when the `label` slot is empty.

Methods

MethodDescription
check- Sets checked to true.
uncheck- Sets checked to false.
toggle- Flips checked state.
validateInput- Runs `required` validation; `vu-form` calls this when aggregating field errors.
reset- Resets to `defaultChecked`, clears validation UI, and dispatches `vu-clear`.

Types

NameDefinition
VuSwitchChangeDetail
{
  checked: boolean;
  value: string | boolean | undefined;
}
VuSwitchColor
"default" | "primary" | "success" | "warning" | "danger"
VuSwitchSize
"sm" | "md" | "lg"
VuSwitchTone
"subtle" | "normal" | "strong"
VuSwitchValidationErrorDetail
{ errors: string[]; }
VuSwitchValueClearedDetail
{ value: string; checked: boolean; }
VuSwitchVariant
"outline" | "default" | "soft"

Related

Inputs

  • Advanced FilterAn advanced filter component with expression input and visual builder.
  • ButtonA clickable button component with multiple variants and states.
  • Button GroupA button group component with shared styling and optional selection.
  • CheckboxA checkbox component with label, hint, and validation.
  • Checkbox GroupA checkbox group component with shared label and validation.
  • Color AreaA two-dimensional color picker component for saturation and brightness.

Guides

  • FormsFormData, VuForm, and validation
  • EventsonVu* / v-model / e.detail
  • Appearancevariant, color, tone, size

Browse

  • Previous: SliderEarlier in the sidebar
  • Next: Text EditorLater in the sidebar
  • All componentsBrowse the full index