Create

Form

Radio

Copy page View as Markdown Open in ChatGPT Open in Claude

A set of checkable buttons where no more than one of the buttons can be checked at a time.

Usage#

app.component.ts
import { WDS_RADIO } from '@wds/angular/radio';

Examples#

Default#

value on wds-radio-group selects the option with the same value.

Default Comfortable Compact

Description#

The description slot adds helper text below the label.

Default Standard spacing for most use cases. Comfortable More space between elements. Compact Minimal spacing for dense layouts.

Choice card#

variant="card" turns each option into a card: a click anywhere on it selects the option.

Plus For individuals and small teams. Pro For growing businesses. Enterprise For large teams and enterprises.

Fieldset#

wds-field-set with a legend and a description groups the options. wds-change reports the new value.

Subscription planYearly and lifetime plans offer significant savings.Monthly ($9.99/month)Yearly ($99.99/year)Lifetime ($299.99)

plan: monthly

Disabled#

disabled on an option skips it; on the group it disables all options.

Disabled Option 2 Option 3

Invalid#

invalid on the group shows the error state on every option.

Notification preferences Choose how you want to receive notifications. Email only SMS only Both email and SMS

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsRadioGroupField connects the group to [formField]. In wds-field the label names the group and wds-field-error describes it.

Notify me about...All new messagesDirect messages and mentionsNothingSubmit

Submitted: —

Template-driven#

WdsRadioGroupValueAccessor makes ngModel work on wds-radio-group; required needs a selected option.

Notify me about...All new messagesDirect messages and mentionsNothingSubmit

Submitted: —

Reactive forms#

The same WdsRadioGroupValueAccessor works with formControl and formControlName.

Notify me about...All new messagesDirect messages and mentionsNothingSubmit

Submitted: —

API References#

wds-radio-group#

A radio group: manages the selection, arrow-key navigation and the form value.

Attributes

AttributeTypeDefaultDescription
namestring''Field name in the form. Reflected to the attribute, which FormData uses (also when a framework sets it as a property).
valuestring''Value of the selected wds-radio.
disabledbooleanfalseDisables the whole group and excludes it from form submission.
requiredbooleanfalseOne of the options must be selected for the form to be valid.
invalidbooleanfalseError state of the whole group: sets invalid on every wds-radio.

Events

EventDescription
wds-changeCustomEvent<WdsChangeDetail>The user selected another option.

Methods

MethodDescription
formResetCallback()Jak natywne pola: reset wraca do wartości z atrybutu value (np. wyrenderowanej przez serwer).
formDisabledCallback(disabled: boolean)
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

Slots

SlotDescription
(default)<wds-radio> elements.

wds-radio#

A single radio button. Use it inside <wds-radio-group>.

Attributes

AttributeTypeDefaultDescription
valuestring''Value passed to the group and the form.
checkedbooleanfalseSet by the group.
disabledbooleanfalseDisables this option.
invalidbooleanfalseError state: red border and aria-invalid. A group with invalid sets it on every option.
variantWdsRadioVariant'default'card is a clickable card with a border and the control on the right.

Slots

SlotDescription
(default)Label content.
descriptionHelper text below the label (read as a description, not as the name).

CSS parts (::part)

PartDescription
rootThe container (the card in the card variant).
controlThe round indicator.
labelThe label container.
descriptionThe helper text.

CSS custom properties

PropertyDescription
--wds-radio-borderBorder color.
--wds-radio-checkedChecked color.

Accessibility#

Screen reader#

wds-radio-group has role="radiogroup" and each wds-radio role="radio" with aria-checked. Give the group a name: aria-label, wds-field-label in wds-field, or a legend of wds-field-set around it.

The content of wds-radio is its name; the description slot is read as a description, not as part of the name.

invalid sets aria-invalid="true" on the group and the options, required sets aria-required="true" on the group, and a disabled option gets aria-disabled="true".

The group takes part in forms: the value of the selected option is submitted under name, and a form reset restores the value attribute.

Keyboard support#

KeyFunction
TabMoves focus into the group, to the selected option or, without one, to the first enabled option. Tab again leaves the group.
ArrowDownArrowRightMoves to the next enabled option and selects it; from the last option wraps to the first.
ArrowUpArrowLeftMoves to the previous enabled option and selects it; from the first option wraps to the last.
SpaceSelects the focused option.
Footer