Radio
<afp-radio>
The Radio component allows users to select a single option from a set of choices. It is typically used in groups where only one radio button can be selected at a time.
Examples #
Sizes #
Use the size attribute to change the radios size.
Hint #
Use the hint attribute to provide additional information below the radio.
Checked #
Use the checked attribute to render a radio in the checked state.
Disabled #
Use the disabled attribute to make a radio unselectable.
Invalid #
Use the invalid attribute to display an error message and style the radio accordingly.
Custom Icons #
Use the checked-icon slot to provide custom icons for the checked state.
Customization #
Use the --afp-radio-control-color CSS variable to customize the checked radio color.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
checked
|
Whether the radio is checked
Type
boolean
Default
false |
|
||||||||
value
|
The value associated with the radio
Type
string
|
|||||||||
group
|
The group name (shared among radios)
Type
string
|
|||||||||
disabled
|
Whether the radio is disabled
Type
boolean
Default
false |
|
||||||||
size
|
size of the radio.
Type
AfpSize
Default
AfpSize.MEDIUM |
|
||||||||
invalid
|
Error message shown below the checkbox when present. Sets `aria-invalid`.
Provide a non-empty string to put the component in an error state.
Type
string
|
|||||||||
hint
|
Optional hint message below the radio
Type
string
Default
'' |
Events
Learn more about events.
| Name | Return | Description |
|---|---|---|
afp-value-changed
|
{ value: number | string | undefined; checked: boolean }
|
Fired when the radio is selected.
|
afp-change
|
string
|
Fired when the checked state changes.
|
afp-focus
|
void
|
Fired when the radio gains focus.
|
afp-blur
|
void
|
Fired when the radio loses focus.
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
default
|
The label content of the radio button.
|
checked-icon
|
The icon to display inside the selected radio.
|
Internationalization
Learn more about internationalization.
| Key | Description |
|---|---|
radio.aria-label
|
The default `aria-label` text for radio.
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
base
|
The outer wrapper of the radio.
|
::part(base)
|
input
|
The internal `<input>` element.
|
::part(input)
|
control
|
The visual control (the circle).
|
::part(control)
|
checked-icon
|
The icon shown when the radio is checked.
|
::part(checked-icon)
|
invalid
|
The error message text.
|
::part(invalid)
|
hint
|
The hint message text.
|
::part(hint)
|
label
|
The text label next to the control.
|
::part(label)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-radio-disabled-opacity
|
The opacity of the radio when disabled.
|
0.5
|
--afp-radio-control-color
|
The color of the radio when checked
|
--afp-color-neutral-fill-loud
|
--afp-radio-tranform-scale
|
The scale transform of the radio from unchecked to checked.
|
0.8
|
--afp-input-error-border-color
|
The border color of the radio control in the invalid/error state.
|
--afp-color-error-500
|
Dependencies
The component automatically brings in the listed items, including any nested dependencies that may exist.
| Component | CSS Part Prefix |
|---|---|
|
|
checked-icon
- The icon shown when the radio is checked.
|
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/radio/radio.js';