Skip to content

Checkbox ​

Lets people turn a choice on or off, or pick any number of options from a list.

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

const voorwaarden = ref(false)
</script>

<template>
  <FsCheckbox v-model="voorwaarden" label="Ik ga akkoord met de algemene voorwaarden" />
</template>

Usage ​

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

const akkoord = ref(false)
</script>

<template>
  <FsCheckbox v-model="akkoord" label="Ik ga akkoord" />
</template>

A checkbox names itself with label. In a Field, give the field no label; it adds the description and the error. Several boxes that belong together go in a FsCheckboxGroup inside a Field. Pick exactly one option with Radio; a setting that takes effect at once is a Switch.

Examples ​

With a description ​

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

const kopie = ref(true)
</script>

<template>
  <FsCheckbox v-model="kopie" label="Stuur mij een kopie" description="We mailen de offerte ook naar jouw adres." class="max-w-sm" />
</template>

Group ​

FsCheckboxGroup holds the chosen values as an array and gives every box its name. The field supplies the question.

vue
<script setup lang="ts">
import { FsCheckbox, FsCheckboxGroup, FsField } from '@fivespark/ui'
import { ref } from 'vue'

const contact = ref(['email'])
</script>

<template>
  <FsField label="Contact via" description="Kies alles wat van toepassing is." class="max-w-sm">
    <FsCheckboxGroup v-model="contact" name="contact">
      <FsCheckbox label="E-mail" value="email" />
      <FsCheckbox label="Telefoon" value="telefoon" />
      <FsCheckbox label="Post" value="post" />
    </FsCheckboxGroup>
  </FsField>
</template>

Horizontal group ​

Horizontal is for up to three short options without descriptions. Longer lists stay vertical.

vue
<script setup lang="ts">
import { FsCheckbox, FsCheckboxGroup, FsField } from '@fivespark/ui'
import { ref } from 'vue'

const dagen = ref(['ma'])
</script>

<template>
  <FsField label="Leverdagen">
    <FsCheckboxGroup v-model="dagen" name="dagen" orientation="horizontal">
      <FsCheckbox label="Maandag" value="ma" />
      <FsCheckbox label="Woensdag" value="wo" />
      <FsCheckbox label="Vrijdag" value="vr" />
    </FsCheckboxGroup>
  </FsField>
</template>

Indeterminate ​

A parent box shows that only some of its children are checked. Pressing it checks the box and clears the dash.

vue
<script setup lang="ts">
import { FsCheckbox, FsCheckboxGroup } from '@fivespark/ui'
import { computed, ref, watch } from 'vue'

const keuzes = ['email', 'telefoon', 'post']
const contact = ref(['email'])
const partial = ref(true)
const alles = computed({
  get: () => contact.value.length === keuzes.length,
  set: (checked) => { contact.value = checked ? [...keuzes] : [] },
})

watch(contact, (value) => { partial.value = value.length > 0 && value.length < keuzes.length })
</script>

<template>
  <div class="flex flex-col gap-3">
    <FsCheckbox v-model="alles" v-model:indeterminate="partial" label="Alle kanalen" />
    <FsCheckboxGroup v-model="contact" name="kanalen" aria-label="Kanalen" class="ps-6">
      <FsCheckbox label="E-mail" value="email" />
      <FsCheckbox label="Telefoon" value="telefoon" />
      <FsCheckbox label="Post" value="post" />
    </FsCheckboxGroup>
  </div>
</template>

Disabled ​

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

<template>
  <div class="flex flex-col gap-3">
    <FsCheckbox disabled label="Factuur per post" />
    <FsCheckbox disabled :model-value="true" label="Offerte per e-mail" />
  </div>
</template>

Read-only ​

A read-only checkbox shows its value without letting it change. Unlike a disabled one it stays focusable and is submitted.

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

<template>
  <FsCheckbox readonly :model-value="true" label="Algemene voorwaarden geaccepteerd" />
</template>

Invalid ​

Put the message on the field's error; the group is marked invalid with it.

vue
<script setup lang="ts">
import { FsCheckbox, FsCheckboxGroup, FsField } from '@fivespark/ui'
import { ref } from 'vue'

const contact = ref<string[]>([])
</script>

<template>
  <FsField label="Contact via" error="Kies minstens één manier om contact op te nemen." class="max-w-sm">
    <FsCheckboxGroup v-model="contact" name="contact-fout">
      <FsCheckbox label="E-mail" value="email" />
      <FsCheckbox label="Telefoon" value="telefoon" />
    </FsCheckboxGroup>
  </FsField>
</template>

Keyboard ​

KeyDoes
SpaceChecks or unchecks the focused box
TabMoves to the next box

API Reference ​

FsCheckbox ​

PropTypeDefaultDescription
valuestring"on"Submitted when checked, and its value in a group's array.
labelstringThe visible name. Or the default slot, for a label with a link in it.
descriptionstringOne short sentence under the label. Or the `description` slot.
idstringWithout a field. In a field, the box takes the field's.
invalidbooleanMarks the box as wrong; the field says why. In a field, the box takes the field's.
requiredbooleanIt must be checked, as for accepting terms. Never in a group: its legend says so.
disabledbooleanUnavailable for now. In a field, the box takes the field's.
readonlybooleanFocusable and submitted, its value fixed. Say why in the field's description.
readonlyTextstringReplaces the hidden "alleen lezen" or "read-only" of a single read-only box.
modelValuebooleanfalseChecked, for a single box. In a group, the group's `v-model` holds it.
indeterminatebooleanfalseShows the minus, exposed as mixed. A click clears it and checks the box.
EventPayloadDescription
update:modelValue[value: boolean]Sent with the new `modelValue`, for `v-model`.
update:indeterminate[value: boolean]Sent with the new `indeterminate`, for `v-model:indeterminate`.
SlotPropsDescription
defaultanyThe visible name, in place of `label`: for a label with a link in it.
descriptionanyOne short sentence under the label, in place of `description`.

FsCheckboxGroup ​

PropTypeDefaultDescription
namestringGiven to every box, so the form posts `name=a&name=b`.
orientation"vertical" | "horizontal""vertical"Horizontal for up to three short options without descriptions. They stack when they do not fit.
size"default" | "dense"`dense` puts the options closer together; the box does not change.
invalidbooleanMarks the group as wrong; the field says why. In a field, the group takes the field's.
requiredbooleanAt least one must be checked, which the form validates. Said in the legend, never on the boxes.
disabledbooleanUnavailable for now, every box with it. In a field, the group takes the field's.
readonlybooleanFocusable and submitted, its values fixed. Say why in the field's description.
requiredTextstringReplaces the hidden "verplicht" or "required" of a group without a field.
readonlyTextstringReplaces the hidden "alleen lezen" or "read-only" of a group without a field.
modelValuestring[][]The values of the checked boxes.
EventPayloadDescription
update:modelValue[value: string[]]Sent with the new `modelValue`, for `v-model`.
SlotPropsDescription
defaultanyThe `FsCheckbox`es.