Skip to content

Radio ​

One choice out of a few, with every option visible at once.

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

const moment = ref<string>()
</script>

<template>
  <FsField label="Moment van levering" class="w-full max-w-sm">
    <FsRadioGroup v-model="moment">
      <FsRadio label="Ochtend" value="ochtend" />
      <FsRadio label="Middag" value="middag" />
      <FsRadio label="Avond" value="avond" />
    </FsRadioGroup>
  </FsField>
</template>

Usage ​

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

const levering = ref<string>()
</script>

<template>
  <FsField label="Levering">
    <FsRadioGroup v-model="levering">
      <FsRadio label="Bezorgen" value="bezorgen" />
      <FsRadio label="Ophalen" value="ophalen" />
    </FsRadioGroup>
  </FsField>
</template>

Radios always live in an FsRadioGroup, which holds the value and, inside a Field, gives the group its label. Nothing is selected until the user chooses, so preselect only a known answer. For several choices use Checkbox; for a long list use Select.

Examples ​

With a description ​

A line under an option says what choosing it means.

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

const moment = ref<string>()
</script>

<template>
  <FsField label="Moment van levering" class="w-full max-w-sm">
    <FsRadioGroup v-model="moment">
      <FsRadio label="Ochtend" value="ochtend" description="Tussen 8:00 en 12:00" />
      <FsRadio label="Middag" value="middag" description="Tussen 12:00 en 17:00" />
      <FsRadio label="Avond" value="avond" description="Tussen 17:00 en 21:00" />
    </FsRadioGroup>
  </FsField>
</template>

Horizontal ​

For a few short options. The group's orientation is vertical by default.

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

const tarief = ref<string>()
</script>

<template>
  <FsField label="Btw-tarief" class="w-full max-w-sm">
    <FsRadioGroup v-model="tarief" orientation="horizontal">
      <FsRadio label="0%" value="0" />
      <FsRadio label="9%" value="9" />
      <FsRadio label="21%" value="21" />
    </FsRadioGroup>
  </FsField>
</template>

Required and invalid ​

required and the error belong to the field around the group, not to a single radio.

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

const betaling = ref<string>()
</script>

<template>
  <FsField label="Betaalwijze" required error="Kies een betaalwijze." class="w-full max-w-sm">
    <FsRadioGroup v-model="betaling">
      <FsRadio label="Op factuur" value="factuur" />
      <FsRadio label="Vooraf betalen" value="vooraf" />
    </FsRadioGroup>
  </FsField>
</template>

Disabled option ​

Disable a single option when it is temporarily unavailable, and say why. Put disabled on the group to disable them all.

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

const levering = ref('bezorgen')
</script>

<template>
  <FsField label="Levering" class="w-full max-w-sm">
    <FsRadioGroup v-model="levering">
      <FsRadio label="Bezorgen" value="bezorgen" />
      <FsRadio label="Ophalen" value="ophalen" disabled description="Alleen mogelijk op werkdagen." />
    </FsRadioGroup>
  </FsField>
</template>

Read-only ​

readonly on the field shows the choice without letting it change.

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

const levering = ref('bezorgen')
</script>

<template>
  <FsField label="Levering" readonly class="w-full max-w-sm">
    <FsRadioGroup v-model="levering">
      <FsRadio label="Bezorgen" value="bezorgen" />
      <FsRadio label="Ophalen" value="ophalen" />
    </FsRadioGroup>
  </FsField>
</template>

Keyboard ​

KeyDoes
TabMoves into the group, on the selected radio or else the first, and out of it
↑, ↓, ←, →Moves to the next or previous radio and selects it
SpaceSelects the focused radio

API Reference ​

FsRadioGroup ​

PropTypeDefaultDescription
namestringGiven to every radio. Generated when absent, since the browser groups radios by name.
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 circle does not change.
invalidbooleanMarks the group as wrong; the field says why. In a field, the group takes the field's.
requiredbooleanOne must be chosen. Said on the group, never on the radios, so the browser does not validate it: check it on submit.
disabledbooleanUnavailable for now, every option with it. In a field, the group 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 group without a field.
modelValuestringThe checked radio's value; undefined while none is, which is where a group starts unless the answer is known.
EventPayloadDescription
update:modelValue[value: string | undefined]Sent with the new `modelValue`, for `v-model`.
change[value: string]The user chose another radio.
SlotPropsDescription
defaultanyThe `FsRadio`s.

FsRadio ​

PropTypeDefaultDescription
valuestringrequiredSubmitted when checked, and the group's `v-model` while it is.
labelstringThe visible name. Or the default slot.
descriptionstringOne short sentence under the label. Or the `description` slot.
idstringIn a field too: each radio has its own.
disabledbooleanThis option is unavailable. A disabled group disables every option.
SlotPropsDescription
defaultanyThe visible name, in place of `label`.
descriptionanyOne short sentence under the label, in place of `description`.