On this page

Radio group

Live examples of Radio group, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

Choose one

One option is always chosen.

When a product runs out
RadioGroupBasic.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

const outOfStock = ref('sold-out')
</script>

<template>
  <FieldSet class="max-w-sm">
    <FieldLegend variant="label">When a product runs out</FieldLegend>
    <RadioGroup v-model="outOfStock">
      <Field orientation="horizontal">
        <RadioGroupItem id="oos-sold-out" value="sold-out" />
        <FieldLabel for="oos-sold-out">Show it as sold out</FieldLabel>
      </Field>
      <Field orientation="horizontal">
        <RadioGroupItem id="oos-hide" value="hide" />
        <FieldLabel for="oos-hide">Hide it from the online store</FieldLabel>
      </Field>
      <Field orientation="horizontal">
        <RadioGroupItem id="oos-backorder" value="backorder" />
        <FieldLabel for="oos-backorder">Keep selling it on backorder</FieldLabel>
      </Field>
    </RadioGroup>
  </FieldSet>
</template>

With descriptions

A line under each option explains it.

When the same product changed in both places
RadioGroupWithDescription.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

const conflicts = [
  { value: 'erp', label: 'The ERP wins', description: 'Prices and stock in the ERP overwrite the online store.' },
  { value: 'store', label: 'The online store wins', description: 'Changes made in the store are sent back to the ERP.' },
  { value: 'ask', label: 'Ask me each time', description: 'The sync pauses that product until someone chooses.' },
]
const winner = ref('erp')
</script>

<template>
  <FieldSet class="max-w-md">
    <FieldLegend variant="label">When the same product changed in both places</FieldLegend>
    <RadioGroup v-model="winner">
      <Field v-for="option in conflicts" :key="option.value" orientation="horizontal">
        <RadioGroupItem :id="`conflict-${option.value}`" :value="option.value" :aria-describedby="`conflict-${option.value}-help`" />
        <FieldContent>
          <FieldLabel :for="`conflict-${option.value}`">{{ option.label }}</FieldLabel>
          <FieldDescription :id="`conflict-${option.value}-help`">{{ option.description }}</FieldDescription>
        </FieldContent>
      </Field>
    </RadioGroup>
  </FieldSet>
</template>

An option that is not available

Its description says why.

Default delivery
RadioGroupDisabled.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

// One option can't be chosen yet; its description says why.
const carrier = ref('standard')
</script>

<template>
  <FieldSet class="max-w-md">
    <FieldLegend variant="label">Default delivery</FieldLegend>
    <RadioGroup v-model="carrier">
      <Field orientation="horizontal">
        <RadioGroupItem id="delivery-standard" value="standard" />
        <FieldLabel for="delivery-standard">Standard, 3 to 5 days</FieldLabel>
      </Field>
      <Field orientation="horizontal">
        <RadioGroupItem id="delivery-express" value="express" />
        <FieldLabel for="delivery-express">Express, next day</FieldLabel>
      </Field>
      <Field orientation="horizontal" data-disabled="true">
        <RadioGroupItem id="delivery-same-day" value="same-day" disabled aria-describedby="delivery-same-day-help" />
        <FieldContent>
          <FieldLabel for="delivery-same-day">Same day</FieldLabel>
          <FieldDescription id="delivery-same-day-help">Connect a courier account first.</FieldDescription>
        </FieldContent>
      </Field>
    </RadioGroup>
  </FieldSet>
</template>