Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Radio Group for Vue UI SDK

Radio buttons for Vue on UI SDK: every option stays on screen, picking one clears the others, and the arrow keys move the choice.

On this page9 sections

A radio group shows every option at once and lets people pick exactly one, and picking another clears the first. It suits a short list where seeing the choices side by side helps the decision, such as a shipping speed, a billing period or a layout density.

For a long list, a Select takes less room. When more than one option can be on at the same time, use a Checkbox for each.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Radio Group anatomy: root, label, item control, indicator, item, item text

Usage

<script setup lang="ts">
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
</script>

<template>
  <RadioGroup class="w-fit" defaultValue="comfortable">
    <RadioGroupItem value="default">Default</RadioGroupItem>
    <RadioGroupItem value="comfortable">Comfortable</RadioGroupItem>
    <RadioGroupItem value="compact">Compact</RadioGroupItem>
  </RadioGroup>
</template>

Accessibility

RadioGroup has the radiogroup role, and each option is a button with the radio role and aria-checked, with a hidden native radio behind it for forms. Only one option at a time is in the tab order. Text inside RadioGroupItem names its option, since the item then renders a <label> around the circle and the text. Name the group too: wrap it in a FieldSet with a FieldLegend, or pass aria-label.

Tab
Moves focus to the checked item, or to the first item when none is checked.
Space
When focus is on an unchecked item, checks it.
Arrow Down
Moves focus to the next item and checks it, skipping disabled items, from the last back to the first.
Arrow Right
Moves focus to the next item and checks it, skipping disabled items, from the last back to the first.
Arrow Up
Moves focus to the previous item and checks it, skipping disabled items, from the first to the last.
Arrow Left
Moves focus to the previous item and checks it, skipping disabled items, from the first to the last.
Enter
Submits the form the group is in.

Demos

Description

Three density settings, Default, Comfortable and Compact, each with a short line that says what it changes, and Comfortable picked to start. The name stays inside RadioGroupItem and the line goes in a FieldContent after it, so the two sit side by side on one row. Add the line when the names alone don't say what happens, and leave it off when it would only repeat the label.

Preview width

Choice card

Three plans, Plus, Pro and Enterprise, drawn as cards with a title, a line on who each is for, and the radio at the end of the row. A FieldLabel wraps each card's Field, so a click anywhere on the card picks that plan. Use cards when each option is a decision of its own, like a pricing tier, and plain rows when the options are single words.

Preview width

Fieldset

A Subscription Plan question with three answers, monthly at $9.99, yearly at $99.99 and lifetime at $299.99, and a note that the longer plans cost less. FieldSet and FieldLegend render a real fieldset and legend, so a screen reader names the group as focus enters it. Use one whenever the question isn't already written as a heading right above the options.

Preview width

Horizontal

Three short options, Option 1 to Option 3, side by side in one row that wraps when the space runs out. flex classes on RadioGroup replace its one-column grid, and orientation set to horizontal tells assistive technology about the row. Use a row for two to four one-word answers, such as a billing period, and stack anything longer.

Preview width

Disabled

Three options where the first, labeled Disabled, can't be picked, and Option 2 is selected to start. That item gets disabled, which fades its circle, and data-disabled on its Field fades its label. Disable one option when it exists but isn't available right now, such as a sold-out size, and say why next to it.

Preview width

Invalid

Notification preferences, Email only, SMS only or both, drawn in their error state under a legend and a description. The demo sets invalid on RadioGroup, which draws the circles red, and data-invalid on each Field, which turns the labels red. Show it after a failed submit, together with a message that says what has to change.

Preview width

RTL

The density options in Arabic, each with its description, inside a Direction provider set to right to left, and every circle sits to the right of its word. The provider sets dir on a wrapper with no box of its own, so dir set to rtl on RadioGroup or any parent lines the rows up the same way.

Preview width

FAQ

How do I control the selected Radio Group value in Vue?

Bind v-model on RadioGroup to a ref that holds the picked item's value. Listen to @value-change when you need the details object, and use default-value when you only need a starting value.

The group's value is the value of whichever RadioGroupItem is picked. Hold it in state when another part of the page depends on it, such as a price that changes with the plan.

How do I submit a Radio Group with a form?

Set name on RadioGroup. The form then receives that name with the picked item's value, not its visible label, and receives nothing at all while no option is picked.

Add required when an answer is mandatory, which also marks the group with aria-required. Each option has a radio input behind it, so a FormData built from the form reads the answer like any other field.

Why is my Radio Group label not clickable?

Because it sits beside the item instead of inside it. Put the text inside RadioGroupItem as its children: the item renders a <label> around its circle and that text, so a click on the words picks the option and a screen reader reads them as its name.

For a whole card that picks its option, wrap the card in the label, as the Choice card demo does.

How does keyboard navigation work in a Radio Group?

The group is a single stop in the tab order. Tab lands on the checked option, or on the first one when nothing is checked yet, and the arrow keys move to the next or previous option and pick it as they go. Space picks the focused option if it isn't picked already.

Up and Left go back, Down and Right go forward, and the movement wraps from the last option to the first. There are no Home or End shortcuts.

How do I show a Radio Group as invalid with UI SDK?

Set invalid on RadioGroup, and every option gets aria-invalid for screen readers and a red circle. For one option alone, set aria-invalid on its RadioGroupItem instead. Add data-invalid to the Field around each option to color the labels too, as the Invalid demo does.

Color isn't the message, though. Put a sentence that says what's wrong under the options, in a FieldError or the fieldset's description.

How do I disable a Radio Group or one of its options?

Set disabled on RadioGroup to lock every option, or on one RadioGroupItem to lock only that one, as the Disabled demo does. A disabled option stays visible and can't be picked.

For an answer people should see but not change, such as a plan an admin has locked, use readOnly instead, which keeps the options at full strength and still submits the answer.

How do I lay out Radio Group options in a row?

RadioGroup lays its items out as a grid with one column. Add a class to it, such as grid-cols-3 for three equal columns, or flex with a gap for a row that sizes to its labels, as the Horizontal demo does.

Set orientation to horizontal as well, which tells assistive technology through aria-orientation. The arrow keys work the same either way.

Should I use a Radio Group, a Select or a Segment Group?

Use a radio group when there are a handful of options and people should read them all before choosing, especially when an option needs a description or its own card.

A Select suits a long list, or a short one where space is tight and the options are familiar, like a country. A Segment Group is a compact row of short labels with a sliding indicator, which fits a view switcher better than a form question. If several options can be on at once, use a Checkbox for each.

API Reference

RadioGroup

<div> data-slot="radio-group"

PropType
value?T | null

The checked radio's value. Pass it to control the group. null checks nothing. Two-way with v-model.

Type
T | null
defaultValue?T | null

The radio checked at first, when uncontrolled. A form reset returns to it.

Type
T | null
controller?{ getValue: () → T | null; setValue: (value: T | null, details?: Details) → boolean; focus: () → void; }

Checks radios from anywhere. Create one with createRadioGroupController().

Type
{ getValue: () → T | null; setValue: (value: T | null, details?: Details) → boolean; focus: () → void; }
debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Disables every radio like native ones: they can't be focused or changed, and the value isn't submitted.

form?string

The id of a form to belong to, when the group isn't inside that form.

loop?boolean

Whether arrow keys wrap from the last item to the first.

Default
true
name?string

The name the value submits under. Without one, the group submits nothing.

readOnly?boolean

Keeps the items focusable and the value submitted, but stops changes.

required?boolean

Blocks form submission until an item is checked, with the browser's own message.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

EventType
@value-change(value: string, details: RadioGroupChangeDetails) → void

Runs when the selection changes. A cleared selection, as a form reset to no value gives, reports "", which selects nothing when passed back.

Type
(value: string, details: RadioGroupChangeDetails) → void
Parameters

value – string

details – RadioGroupChangeDetails

Returns
void
AttributeType
data-disabled?string

Present when disabled, by its own prop, the group or a <fieldset>.

data-readonly?string

Present when the group is read-only.

data-required?string

Present when the group is required.

RadioGroupText

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

RadioGroupLabel

PropType
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

RadioGroupItem

<button> data-slot="radio"

PropType
valuestring

What the group's value becomes when this item is checked.

disabled?boolean

Skips the item, like a disabled native radio: arrow keys pass it and it can't be focused or checked.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

AttributeType
data-checked?string

Present on the checked radio.

data-disabled?string

Present when disabled, by its own prop, the group or a <fieldset>.

data-readonly?string

Present when the group is read-only.

data-required?string

Present when the group is required.

data-unchecked?string

Present on radios that aren't checked.