Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Radio Group

Choose an option

Runtime example adjustment

Each RadioGroupItem has an explicit accessible name. The Runtime-backed styled item renders a focusable role="radio" element separately from its hidden form input.

Installation

Framework Availability

Astro Available React Available

Radio Group is available for Astro and React.

Usage

variant

Default
Primary
Secondary
Info
Success
Warning
Error

Runtime example adjustment

Variant styling does not change the radio contract, so every item keeps an explicit accessible name in addition to its visible label.

size

Small
Medium
Large

Runtime example adjustment

Size only changes presentation; each focusable Runtime radio remains explicitly named.

orientation

Vertical (Default)

Horizontal

Accessibility adjustment

Give each Runtime radio an explicit accessible name. The styled radio uses a focusable role="radio" element while its hidden input handles native form participation.

Event Handling

The RadioGroup component emits a starwind:value-change event when a radio option is selected. This can be listened to in order to update your UI based on the event.detail.value property.

Radio Group Event Test

Choose an option
Selected value: none

Runtime example adjustment

Listen on the Radio Group root. Runtime value-change details include value, previousValue, radioValue, and reason; listeners no longer need a component-id detail field. Each item also keeps an explicit accessible name on the focusable Runtime radio.

API Reference

Styled Component API

These props are added or materially changed by the installed Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.

Radio Group

Inherits div attributes. Omits `defaultValue` and `onChange`.

Contains the following additional props:

Prop Type Default Toggle details
defaultValue string
Description
Sets the initial value when the component is uncontrolled.
Classification
Primitive override
Primitive prop
radio-group.Root.defaultValue
legend string
Description
Provides accessible text for the grouped choices.
Classification
Wrapper prop
orientation "vertical" | "horizontal" "vertical"
Description
Selects the horizontal or vertical layout direction.
Classification
Styled variant
Primitive prop
radio-group.Root.orientation
value string
Description
Controls or identifies the component value.
Classification
Primitive override
Primitive prop
radio-group.Root.value

Radio Group Item

Inherits span attributes. Omits `defaultChecked` and `onChange`.

Contains the following additional props:

Prop Type Default Toggle details
defaultChecked boolean
Description
Sets the initial checked state when the choice is uncontrolled.
Classification
Primitive override
Primitive prop
radio.Root.defaultChecked
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
variant "default" | "primary" | "secondary" | "info" | "success" | "warning" | "error" "primary"
Description
Selects the component's visual variant.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Radio Group.

Runtime API

Radio primitive
createRadio from @starwind-ui/runtime/radio
Radio Group primitive
createRadioGroup from @starwind-ui/runtime/radio-group

Changelog

v2.0.0

  • Rebuilt Radio Group on Starwind Runtime for radio ownership, form participation, keyboard navigation, and value details.
  • See the Radio Primitive and Radio Group Primitive for the underlying unstyled anatomy and behavior API.

v1.2.6

  • Refactor tailwind variants functions into separate variants.ts file

v1.2.4

  • Add starwind:init event listener to enable initialization of additional Radio Groups loaded after an initial page load, such as when using server islands

v1.2.3

  • add aria-invalid styling

v1.2.2

  • Removed debug logging statements

v1.2.1

  • Add named slot “icon” to RadioGroupItem to enable easy icon swapping

v1.2.0

  • style and focus state updates

v1.1.0

  • Add data-slot attribute to enable global styling updates

v1.0.0

  • Initial release with starwind v1.7.0