Skip to content

OSwitch ​

OSwitch renders a native boolean checkbox with a switch presentation.

Usage ​

Step by step ​

  1. Import OSwitch from the ooko-ui/switch public subpath.
  2. Bind its boolean state with v-model and provide the required label.
  3. Add native checkbox attributes, guidance, or validation state as needed.

Example ​

The rendered example and its source come from the same Vue single-file component.

Interactive playground ​

Change the value, label, guidance, size, and switch states. The preview updates immediately.

You can change this later.

Props ​

PropTypeDefaultDescription
modelValuebooleanfalseCurrent controlled boolean state of the switch.
sizeOokoFormControlSizeundefinedControls the choice control's form-control scale.
labelstringundefinedVisible or visually hidden accessible label.
idstringundefinedNative input identifier. A hydration-safe identifier is generated when omitted.
namestringundefinedNative form field name and OForm validation key.
hintstringundefinedPersistent guidance displayed below the choice control.
errorstringundefinedControlled validation error displayed below the choice control.
validationOokoValidationBindingundefinedValidation binding created by useOokoValidation.
hideLabelbooleanfalseVisually hides the label while preserving its accessible name.
requiredbooleanfalseMarks the native input as required.
disabledbooleanfalseDisables the native input.
readonlybooleanfalsePrevents changes while keeping the input focusable.

Events ​

EventPayloadDescription
update:modelValuebooleanEmits the next boolean state after a native change.

Slots ​

SlotPropsDescription
defaultnoneProvides the switch label content.
TypeDefinition
OokoFormControlSizetype OokoFormControlSize = "sm" | "md";

CSS custom properties ​

Custom propertyDefaultDescription
--o-switch-gapvar(--o-space-2)Sets the space between the switch and its label.
--o-switch-track-inline-sizevar(--o-space-10)Sets the switch track width.
--o-switch-track-block-sizevar(--o-space-5)Sets the switch track height.
--o-switch-thumb-insetvar(--o-space-0-5)Sets the switch thumb inset.
--o-switch-focus-width0.1875remSets the focus outline width.
--o-switch-focus-stylesolidSets the focus outline style.
--o-switch-focus-offset0.125remSets the distance between the switch and focus outline.
--o-switch-disabled-opacity0.5Sets the opacity of a disabled switch.

Override example ​

css
:root {
  --o-switch-track-inline-size: var(--o-space-12);
}

Accessibility ​

The component keeps native checkbox semantics and a control row that acts as its label, rather than substituting a custom ARIA switch. Clicking the track or text toggles it. Space toggles it, focus is visibly indicated, and disabled behavior uses the native attribute. readonly remains focusable and exposes aria-readonly; it does not change value. Hints and feedback are referenced by aria-describedby, while errors are announced politely. Forced-colors and reduced-motion preferences are respected.

Behavior and edge cases ​

The controlled model is always boolean and emits the next boolean state. Native attributes and listeners are forwarded to the input; consumer classes and styles apply to the component root. size accepts sm and md, and may be configured through app defaults.