Radio
BasicSelection
<co-radio>Radio and RadioGroup choose exactly one option from a short visible list.
import { Radio } from 'health-components';
Examples
Showcase
Inline
With Error
Disabled
Single Radio
Usage
<RadioGroup label="Visit Mode" inline required options={["In person", "Telehealth"]} value={mode} onChange={setMode} />
When to use
- Two to six options that need explanation: "Text message", "Authenticator app".
When not to use
- Many options: Select.
- A compact view switch: SegmentedControl.
Variants and states
| Variant | What it is |
|---|---|
| vertical | Default, one per line with optional description. |
| inline | Options in a row. |
| error | Message under the group. |
| disabled option | Greyed. |
Accessibility
- Fieldset with legend; arrow keys move between options natively.
Do and don't
- Do: Describe the cost of each choice: "Card on file (Visa ending 4242)".
- Don't: A radio group with one option.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label * | ReactNode | — | Visible label; the whole row is clickable. Required |
description | ReactNode | none | Help text under the label |
disabled | boolean | false | Disables the radio |
Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, onChange, onInput, readOnly, name, value, max, step, placeholder, accept, autoComplete, checked, maxLength, min, multiple, required, plus className and event handlers on the root element.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-radio>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.
Angular template
<co-radio disabled default-checked [defaultValue]="defaultValue" (co-change)="onChange($event.detail)"></co-radio>
| Kind | Name | Description |
|---|---|---|
| attribute | disabled | Disables the radio; default false |
| attribute | default-checked / defaultChecked | |
| property / JSON attribute | default-value / defaultValue | |
| attribute | auto-focus / autoFocus | |
| attribute | read-only / readOnly | |
| attribute | name | |
| property / JSON attribute | value | |
| property / JSON attribute | max | |
| property / JSON attribute | step | |
| attribute | placeholder | |
| attribute | accept | |
| property / JSON attribute | auto-complete / autoComplete | |
| attribute | checked | |
| attribute | max-length / maxLength | |
| property / JSON attribute | min | |
| attribute | multiple | |
| attribute | required | |
| event | co-change | (React: onChange) |
| event | co-input | (React: onInput) |
| slot | label | Visible label; the whole row is clickable. Required Plain text also works as the `label` attribute. |
| slot | description | Help text under the label; default none Plain text also works as the `description` attribute. |