Skip to content

Switch

Toggle between two states.

Switch
Options

Basic Usage

Toggle between two states.

vue
<template>
  <bp-space>
    <bp-switch v-model="val"></bp-switch>
    <bp-switch v-model="val" disabled></bp-switch>
  </bp-space>
</template>

<script setup lang="ts">
import { ref } from "vue";
const val = ref(true);
</script>

Size

Supports small - small and mini - mini.

vue
<template>
  <bp-space>
    <bp-switch v-for="size in sizes" :size v-model="val"></bp-switch>
  </bp-space>
</template>

<script setup lang="ts">
import { ref } from "vue";

const sizes = ["small", "mini"];
const val = ref(true);
</script>

Custom Text

Customize labels with check-text and uncheck-text.

Close
vue
<template>
  <bp-switch v-model="val" check-text="On" uncheck-text="Close"></bp-switch>
</template>

<script setup lang="ts">
import { ref } from "vue";
const val = ref(false);
</script>

Async Operation

Gate toggles with on-before-ok.

vue
<template>
  <bp-switch v-model="val" :on-before-ok="onBeforeOk"></bp-switch>
</template>

<script setup lang="ts">
import { ref } from "vue";

const val = ref(false);

const onBeforeOk = async () => {
  await new Promise((resolve) => setTimeout(resolve, 2000));
  return true;
};
</script>

Switch Props

v-modelBound value
SwitchValue
--
idInput id
String
--
disabledWhether disabled
Boolean
--
sizeSize
SwitchSize
small-
check-valueValue when checked
SwitchValue
true-
uncheck-valueValue when checked
SwitchValue
false-
check-textText when checked
String
--
uncheck-textText when checked
String
--
on-before-okCallback before toggle; return boolean to control the switch
()=>void | boolean | Promise<void | boolean>
--