ComponentUpdated in v15

Radio

Pick one option from a short list.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrRadio, WrRadioGroup } from 'ngwr/radio';

@Component({ imports: [WrRadio, WrRadioGroup] })
export class MyComponent {}

Basic usage

Put radios in a <wr-radio-group> and bind its value with [(value)] or any Angular form.

Value: md
<wr-radio-group [(value)]="size">
  <wr-radio value="sm">Small</wr-radio>
  <wr-radio value="md">Medium</wr-radio>
  <wr-radio value="lg">Large</wr-radio>
</wr-radio-group>

Descriptive labels

The label is projected content, so it can hold any markup.

<wr-radio-group [(value)]="plan">
  <wr-radio value="starter">Starter — $0/mo</wr-radio>
  <wr-radio value="pro">Pro — $9/mo</wr-radio>
  <wr-radio value="enterprise">Enterprise — custom</wr-radio>
</wr-radio-group>

Disabled (whole group)

<wr-radio-group [disabled]="true" [(value)]="size">
  <wr-radio value="sm">Small</wr-radio>
  <wr-radio value="md">Medium</wr-radio>
</wr-radio-group>

Disabled (single option)

Disable one option while the rest stay selectable.

<wr-radio-group [(value)]="size">
  <wr-radio value="sm">Small</wr-radio>
  <wr-radio value="md">Medium</wr-radio>
  <wr-radio value="lg" disabled>Large</wr-radio>
</wr-radio-group>

Radio API

NameDescriptionTypeDefault
idStable id used to associate the native input with its label. Lands on the inner <input>; the host never keeps it.stringrandomId('wr-radio')
valuerequiredValue selected when this radio is checked.unknown—
iconOptional icon name rendered inside the dot when checked, in place of the default solid circle. Use any registered NGWR icon.WrIconName | nullnull
sizeControl size — shares the --wr-control-* contract. Set per option; the group has no size.WrRadioSize'md'
disabledDisable just this option. The group can also be disabled as a whole via <wr-radio-group disabled>; either source disables this radio.booleanfalse

Radio Group API

NameDescriptionTypeDefault
nameShared name attribute. Defaults to a random id so multiple groups on the same page don't collide. (Also the FormUiControl.name slot.)stringrandomId('wr-radio-group')
disabledDisable the whole group. Bound automatically from the field's disabled state when used with [formField].booleanfalse
readonlyRefuse selection changes while every option stays focusable and the value still submits. Bound automatically from the field's readonly state when used with [formField]. Native radios ignore the readonly attribute, so the group cancels the activation instead and mirrors the state as aria-readonly, which role radiogroup supports.booleanfalse
valueThe selected radio's value. Bound by [formField], or two-way via [(value)].unknownnull
(touch)Emitted on blur from any child so a bound field can mark itself touched.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/radio's own element.

VariableDefaultDeclared on
--wr-radio-bgvar(--wr-color-surface).wr-radio +1 variant override
--wr-radio-bordervar(--wr-border-base).wr-radio +2 variant overrides
--wr-radio-colorvar(--wr-color-on-surface).wr-radio +1 variant override
--wr-radio-dottransparent.wr-radio +1 variant override
--wr-radio-font-familyvar(--wr-font-family-base).wr-radio
--wr-radio-font-sizevar(--wr-text-sm).wr-radio +2 variant overrides
--wr-radio-group-gapvar(--wr-space-sm).wr-radio-group
--wr-radio-label-gapvar(--wr-space-sm).wr-radio
--wr-radio-line-heightvar(--wr-control-line-height-md).wr-radio +2 variant overrides
--wr-radio-size1.125rem.wr-radio +2 variant overrides

Dependencies

Built onForm, Icon
Used bySchema Form

See also