API: components
Radio
A radio of a RadioGroup and its dot, with the hidden input the form submits, following the APG's radio group pattern, in each framework.
One choice of a RadioGroup (WAI-ARIA APG
radio group pattern): a button with the
radio role, its dot, and a hidden radio input that the form submits. A Radio.Root must be
inside a RadioGroup, which holds the value, the tab stop and the arrow keys.
Contact settings
Behaviour
- Check: a click on the Root or on its
<label>checks it and focuses it, as does Space on it; Enter does nothing. A checked radio stays checked: another radio of the group clears it. - Disabled:
disabled, or the group's, ignores the pointer and the keys, and the arrows skip it. - Forms: a visually hidden
radioinput right after the Root carries the group'sname, the radio'svalueand its checked state. It is never in the accessibility tree nor the tab order. - Name: a
<label>around the Root,<label for>(the Root is abutton, which is labelable), oraria-label.
Anatomy
| part | element | data-primitives-part | role |
|---|---|---|---|
| Root | button | radio-root | a radio of its group |
| Indicator | span | radio-indicator | the dot; rendered only while checked |
| (hidden input) | input type="radio" | radio-input | what the form submits |
Usage
import { Radio } from "@fragiola/primitives-react/radio";
<label>
<Radio.Root value="pro">
<Radio.Indicator />
</Radio.Root>
Pro
</label>;Each sits inside a RadioGroup.
Props
Every part also takes what the primitive contract gives:
render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which
it forwards.
Root
| prop | type | default | description |
|---|---|---|---|
value | string | required | its value in the group |
disabled | boolean | false | this radio only |
id | string | the button's id, for a <label for> |
Indicator
| prop | type | default | description |
|---|---|---|---|
keepMounted | boolean | false | rendered in every state (Angular: *radioIndicator="true") |
State and part attributes
| part | attributes |
|---|---|
| Root | role="radio", type="button", aria-checked ("true" or "false"), tabindex (0 on the group's tab stop, -1 on the others), disabled and data-disabled when disabled (itself or the group), data-checked / data-unchecked (exactly one), data-required |
| Indicator | aria-hidden="true", data-checked / data-unchecked, data-disabled |
| hidden input | type="radio", name, value, checked, required, disabled, aria-hidden="true", tabindex="-1", visually hidden |
Keyboard
| key | action |
|---|---|
| Space | checks the focused radio |
| Enter | nothing |
| Arrows | the group's: the next or previous enabled radio, focused and checked |
Exports
| entry | exports |
|---|---|
@fragiola/primitives-react/radio | Radio, RadioIndicatorProps, RadioRootProps, RadioState, RenderProp |
@fragiola/primitives-vue/radio | Radio, RadioIndicatorProps, RadioRootProps, RadioState, RenderSlotProps |
@fragiola/primitives-angular/radio | RadioIndicator, RadioRoot, RadioState |