Skip to content

Switch

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

Basic Usage

Example

Disabled State

Set the disabled prop to disable the switch.

Example

Loading State

Set the loading prop to show a loading state. The switch is disabled while loading.

Example

With Label

Use BrLabel to associate a label with the switch.

Example

Sizes

Use the size prop to control the size of the switch.

xs
sm
md (default)
lg
xl
2xl
Example

Custom Thumb Content

You can customize the content inside the switch thumb using the thumb slot, such as adding icons or text.

Example

Theming

Global Customization (BrConfigProvider)

You can override default CSS variables via the theme prop of BrConfigProvider.

ConfigProvider Theme

Emerald Primary

Tailwind Class Override

Blue Override
Example

Local Customization (TailwindCSS)

You can directly override styles using TailwindCSS utility classes.

vue
<template>
  <BrSwitch class="data-[state=checked]:bg-indigo-500" />
</template>

API

Props

NameTypeDefaultDescription
modelValuebooleanfalseThe checked state of the switch
defaultCheckedbooleanfalseThe default checked state when using uncontrolled mode
disabledbooleanfalseWhether the switch is disabled
loadingbooleanfalseWhether to show loading state
size'sm' | 'md' | 'lg''md'The size of the switch
namestring-The name of the switch
idstring-The id of the switch
requiredbooleanfalseWhether the switch is required
valuestring'on'The value of the switch
checkedTextstring-Text to display when checked
uncheckedTextstring-Text to display when unchecked
errorbooleanfalseWhether the switch has validation error

Emits

NameDescriptionParameters
update:modelValueEvent emitted when the checked state changes(value: boolean)
update:checkedEvent emitted when the checked state changes (Radix compatibility)(value: boolean)

Slots

NameDescription
thumbCustom content for the switch thumb