Forms

Switch

An on/off control for settings that take effect immediately. The thumb glides; while pressed, it stretches slightly, as if held.

Copy
<script setup lang="ts">
const enabled = ref(true)
</script>

<template>
  <JSwitch v-model="enabled" label="Email notifications" />
</template>

Installation #

With the Nuxt module, every component is auto-imported — there is nothing to add. In a plain Vue project, import what you use:

Copy
import { JSwitch } from '@juxtui/ui'

Usage #

Copy
<JSwitch v-model="enabled" label="Email notifications" />

Use a switch when the change applies immediately. When it only applies after submitting a form, use a checkbox.

Variants & examples #

Settings list#

Build every pull request.
Collect anonymous usage metrics.
Try features before they ship.

Sizes and states#

Copy
<script setup lang="ts">
const a = ref(true)
const b = ref(true)
</script>

<template>
  <div class="flex flex-col gap-4">
    <JSwitch v-model="a" size="sm" label="Small" />
    <JSwitch v-model="b" label="Medium" />
    <JSwitch :model-value="true" label="Disabled, on" disabled />
    <JSwitch label="Disabled, off" disabled />
  </div>
</template>

API #

Props

PropTypeDefault Description
modelValuebooleanfalseBound with v-model.
labelstring—Label text.
descriptionstring—Supporting text.
size'sm' | 'md''md'Track size.
disabledbooleanfalseDisables the switch.
namestring—When set, submits value under this name while on.
valuestring'on'Submitted value.

Events

EventPayload Description
update:modelValuebooleanEmitted when toggled.

Slots

SlotProps Description
default—Custom label content.
description—Custom description content.

Accessibility #

  • A <button role="switch"> with aria-checked, labelled by its visible label.
  • Clicking the label toggles the switch.

Keyboard #

Key Action
SpaceToggles the switch.
EnterToggles the switch.