Skip to content

Radio

WxRadioGroup binds a set of WxRadios to one value. The radios are native inputs sharing a name, which is what makes arrow-key navigation work — the browser does it, not us.

Stacked

Value: draft

Inline, small

Usage

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

const state = ref('draft')
</script>

<template>
  <wx-radio-group
    v-model="state"
    :options="[
      { label: 'Draft', value: 'draft' },
      { label: 'Published', value: 'published' },
      { label: 'Archived', value: 'archived', disabled: true },
    ]"
  />
</template>

Pass the radios yourself when the labels need markup:

vue
<template>
  <wx-radio-group v-model="state" inline>
    <wx-radio value="draft">Draft</wx-radio>
    <wx-radio value="published">Published <b>(live)</b></wx-radio>
  </wx-radio-group>
</template>

A standalone WxRadio also works — it writes its own value into the model when picked.

WxRadio props

PropTypeDefaultDescription
valuestring | number | boolean | nullValue this radio stands for
labelstringLabel text; the default slot wins
disabledbooleanfalseDisables the radio
size'sm' | 'md' | 'lg''md'Dot and label size
namestringname of the underlying input
idstringgeneratedOverrides the id the label points at; WxFormItem supplies one
ariaLabelstringLabel when there is no visible one

Events: update:modelValue (ChoiceValue), change (ChoiceValue).

WxRadioGroup props

PropTypeDefaultDescription
modelValueChoiceValueundefinedSelected value
optionsRadioOption[]Renders the radios for you
disabledbooleanDisables the whole group
size'sm' | 'md' | 'lg'Size for every radio
namestringgeneratedShared name for the inputs
inlinebooleanfalseLay the radios out in a row

Events: update:modelValue (ChoiceValue), change (ChoiceValue).

Picking the value that is already selected emits nothing.

Accessibility

  • The group is a role="radiogroup"; inside a WxFormItem it is labelled by the item's label.
  • Arrow keys move between radios and select as they go — native behaviour of a shared name, which is why a name is always set even when you do not pass one.
  • Focus is shown on the dot through :focus-visible.

Released under the MIT License.