Skip to content

Switch ​

Turns one setting on or off, and the change applies at once.

vue
<script setup lang="ts">
import { FsSwitch } from '@fivespark/ui'
import { ref } from 'vue'

const herinnering = ref(true)
</script>

<template>
  <FsSwitch v-model="herinnering" label="Herinnering versturen" />
</template>

Usage ​

vue
<script setup lang="ts">
import { FsSwitch } from '@fivespark/ui'
import { ref } from 'vue'

const herinnering = ref(true)
</script>

<template>
  <FsSwitch v-model="herinnering" label="Herinnering versturen" />
</template>

The label names the setting and stays the same on and off. An answer a form needs, to be sent with a Submit, is a Checkbox. A button that stays pressed is a Toggle.

Examples ​

With a description ​

One short sentence under the label.

vue
<script setup lang="ts">
import { FsSwitch } from '@fivespark/ui'
import { ref } from 'vue'

const herinnering = ref(false)
</script>

<template>
  <FsSwitch v-model="herinnering" label="Herinnering versturen" description="Drie dagen voor de vervaldatum." />
</template>

Busy ​

While the setting is being saved, busy blocks further presses and keeps focus. After a moment a spinner shows in the thumb. Say the result yourself, for example with a toast.

vue
<script setup lang="ts">
import { FsSwitch } from '@fivespark/ui'
import { ref } from 'vue'

const opslaan = ref(true)
</script>

<template>
  <FsSwitch v-model="opslaan" label="Automatisch opslaan" busy />
</template>

Disabled and read-only ​

A disabled switch is unavailable. A read-only switch keeps its value fixed but stays focusable and submitted.

vue
<script setup lang="ts">
import { FsSwitch } from '@fivespark/ui'
import { ref } from 'vue'

const aan = ref(true)
</script>

<template>
  <div class="flex flex-col gap-4">
    <FsSwitch v-model="aan" label="Orders synchroniseren" disabled />
    <FsSwitch v-model="aan" label="Planning delen met klanten" readonly />
  </div>
</template>

Keyboard ​

KeyDoes
SpaceTurns the switch on or off
EnterSubmits the form the switch is in, as the browser does; it does not toggle

API Reference ​

FsSwitch ​

PropTypeDefaultDescription
valuestring"on"Submitted when on.
labelstringThe visible name of the setting, the same on and off. Or the default slot.
descriptionstringOne short sentence under the label. Or the `description` slot.
idstringWithout a field. In a field, the switch takes the field's.
disabledbooleanUnavailable for now. In a field, the switch takes the field's.
readonlybooleanFocusable and submitted, its value fixed. Say why in the field's description.
busybooleanfalseWhile the setting saves: further presses are blocked and focus stays. Say the result yourself.
readonlyTextstringReplaces the hidden "alleen lezen" or "read-only".
modelValuebooleanfalseOn or off.
EventPayloadDescription
update:modelValue[value: boolean]Sent with the new `modelValue`, for `v-model`.
SlotPropsDescription
defaultanyThe visible name of the setting, in place of `label`.
descriptionanyOne short sentence under the label, in place of `description`.