No results found

Radio Group

A set of options where users can select only one choice at a time, commonly used in forms, settings, and questionnaires.

Size
S
M
L
XL

When to use Radio Group

Radio Group is ideal when:

Real-world examples:

Implementation Notes

Radio Group is built on native radio inputs, providing several advantages:

Features

  • WAI-ARIA RadioGroup pattern implementation
  • Keyboard navigation with orientation support
  • Form integration with hidden native inputs
  • Error state handling and validation
  • Default value support
  • Two-way binding support (bind:value)
  • Disabled state for group and individual items
  • Custom styling through data attributes
  • Description and error message support
  • Proper focus management
  • Required field validation
  • Horizontal and vertical orientation

Anatomy

PartDescription
<RadioGroup.Root>Root component that manages the radio group's state and behavior
<RadioGroup.Item>Container component for individual radio options that provides value context
<RadioGroup.Trigger>Interactive button component that handles radio option selection
<RadioGroup.Indicator>Visual indicator component that shows the selected state
<RadioGroup.Label>Label component for the radio group or individual options
<RadioGroup.Description>A description component for the radio group that provides additional context
<RadioGroup.ErrorMessage>Component for displaying validation error messages
<RadioGroup.HiddenInput>Hidden native input for form integration

Examples

Basic Usage

Start with this example if you're new to Radio Group. It shows the minimal setup needed for a functional component.

Choose option
Option 1
Option 2

This example demonstrates:

<RadioGroup.Root>
  <RadioGroup.Item value="option1">
    <RadioGroup.Label>Option 1</RadioGroup.Label>
    <RadioGroup.Trigger>
      <RadioGroup.Indicator />
    </RadioGroup.Trigger>
  </RadioGroup.Item>
</RadioGroup.Root>

Value Based

Manage the radio group's selected value externally using signals, allowing for dynamic updates and state sharing across components.

Choose option
Option 1
Option 2
const currentValue = useSignal("option1");

<RadioGroup.Root
  value={currentValue.value}
  onChange$={(value: string) => {
    currentValue.value = value;
    console.log("Selected:", value);
  }}
>
  {/* Radio items */}
</RadioGroup.Root>

Form Integration

Radio group with form validation and error messages.

Subscription Plan
Choose your preferred subscription plan
Basic - $10/month
Pro - $20/month

Essential for collecting user input. This example demonstrates:

Horizontal Layout

Radio group with horizontal orientation. Use horizontal layout for:

Size
S
M
L
XL

Disabled States

Example showing both group-level and individual item disabled states.

Choose option
Option 1
Option 2 (Disabled)
Option 3

This demonstrates:

Implement disabled states to:

Keyboard Navigation

The component supports full keyboard navigation:

Accessibility

Built following the WAI-ARIA radio group pattern, the component includes:

Form Integration

The component provides several features for form integration:

<RadioGroup.Root
  name="options"        // Form field name
  required={true}      // Required validation
  form="form-id"       // Form connection
>
  {/* Radio items */}
  <RadioGroup.ErrorMessage>
    Please select an option
  </RadioGroup.ErrorMessage>
</RadioGroup.Root>

Styling

The component uses data attributes for styling:

[data-qds-radio-group-root] {
/* Root styles */
}

[data-qds-radio-group-trigger][data-state="checked"] {
/* Checked state styles */
}

[data-qds-radio-group-trigger][data-disabled] {
/* Disabled state styles */
}

API Reference

Radio Group Root

Inherits from: <div />

Props

PropTypeDefaultDescription
bind:valueSignal<string | undefined>-
onChange$(value: string) => void-
disabledboolean-
isDescriptionboolean-
isErrorboolean-
namestring-
requiredboolean-
orientation"horizontal" | "vertical"-
valuestring-

Data Attributes

AttributeDescription
data-disabledIndicates whether the radio group is disabled
data-orientationThe orientation of the radio group

Radio Group Item

Inherits from: <div />

Props

PropTypeDefaultDescription
valuestring-

Data Attributes

AttributeDescription
data-orientationThe orientation of the radio group item

Radio Group Trigger

Inherits from: <button />

Data Attributes

AttributeDescription
data-disabledIndicates whether this trigger is disabled
data-checkedIndicates whether this trigger is checked

Radio Group Error Message

Inherits from: <div />

Data Attributes

AttributeDescription
data-visibleIndicates whether the error message is currently visible

Radio Group Indicator

Inherits from: <span />

Data Attributes

AttributeDescription
data-checkedIndicates whether this indicator is in a checked state

Radio Group Description

Inherits from: <div />

Radio Group Hidden Input

Inherits from: <input />

Radio Group Label

Inherits from: <span />

Accessibility

Keyboard Interactions

KeyDescription
SpaceSelects the focused radio option
EnterSelects the focused radio option
ArrowDownMoves focus to the next enabled radio option in vertical orientation
ArrowRightMoves focus to the next enabled radio option in horizontal orientation
ArrowUpMoves focus to the previous enabled radio option in vertical orientation
ArrowLeftMoves focus to the previous enabled radio option in horizontal orientation
HomeMoves focus to the first enabled radio option
EndMoves focus to the last enabled radio option