Skip to content

RadioGroup

A group of radio buttons in a fieldset with a legend, vertical or horizontal layout, and standard field accessibility.

Import

import { RadioGroup } from "@hyzer-labs/ui"

Demo

Disc stability
const stabilities: FormOption[] = [
	{ value: 'understable', label: 'Understable' },
	{ value: 'stable', label: 'Stable' },
	{ value: 'overstable', label: 'Overstable' },
	{ value: 'flippy', label: 'Roller-only (unavailable)', disabled: true }
];

<RadioGroup name="stability" label="Disc stability" options={stabilities} bind:value={stability} />

Props

NameTypeDefaultNote
namestringRequired. Shared by every radio in the group.
labelstringRequired. Rendered as the fieldset legend; sr-only with hideLabel.
optionsFormOption[]Required. See FormOption below.
valuestring''Bindable. The selected option value.
orientation'horizontal' | 'vertical''vertical'
descriptionstringHelp text below the legend.
errorstringInline error message; sets the error state.
requiredbooleanfalse
disabledbooleanfalseDisables the whole group.
hideLabelbooleanfalse
classstringMerged after the hz-field hz-field--radio-group classes.

FormOption

NameTypeDefaultNote
valuestringRequired.
labelstringRequired.
disabledbooleanDisables only this option.

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-field hz-field--radio-group

Data attributes

HookValuesStyles
data-state'default' | 'error' | 'disabled'The universal field state hook, on the root. Precedence is fixed: error beats disabled.
data-orientation'horizontal' | 'vertical'Default vertical. The root is a fieldset and the label is its legend.

Part classes

HookValuesStyles
.hz-field-labelchild elementThe label.
.hz-field-requiredchild elementThe required marker.
.hz-field-descriptionchild elementThe hint text.
.hz-field-errorchild elementThe error message.
.hz-radio-optionschild elementThe radiogroup container.
.hz-radio-optionchild elementOne option row.

Accessibility

The group is a <fieldset> whose label renders as the <legend>. With hideLabel, the legend stays in the DOM as screen-reader-only text. Each radio has its own label.

The options sit in an inner role="radiogroup" container that carries aria-describedby (description first, then error), aria-invalid on error, and aria-required when required.

Arrow-key movement between radios is native browser behavior.

References: APG Radio Group pattern · MDN: <input type="radio">