Switch

PreviousNext

A control that allows the user to toggle between checked and not checked.

<script setup lang="ts">
import { Label } from '@/components/ui/label'
import { Switch } from '@/components/ui/switch'
</script>

<template>
  <div class="flex items-center space-x-2">
    <Switch id="airplane-mode" />
    <Label for="airplane-mode">Airplane Mode</Label>
  </div>
</template>

Installation

pnpm dlx shadcn-vue@latest add switch

Usage

<script setup lang="ts">
import { Switch } from '@/components/ui/switch'
</script>

<template>
  <Switch />
</template>

Checked State

Use default-value for uncontrolled switches, or v-model to control the state.

<script setup lang="ts">
import { ref } from 'vue'
import { Switch } from '@/components/ui/switch'

const checked = ref<boolean>(false)
</script>

<template>
  <Switch v-model="checked" />
</template>