Radio
Radios represent a single option within a mutually exclusive set. Use them inside a radio group when users must pick exactly one choice from a small list.
This component must be used as a child of <wa-radio-group>. Please see the Radio Group docs to see examples of this component in action.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/[email protected]/components/radio/radio.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/radio/radio.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/radio/radio.js';
To import this component for React 18 or below, use the following code:
import WaRadio from '@awesome.me/webawesome/dist/react/radio/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The radio's label. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
appearanceappearance |
The radio's visual appearance.
Type
'default' | 'button'
Default
'default'
|
|
disableddisabled |
Disables the radio.
Type
boolean
Default
false
|
|
form |
By default, form controls are associated with the nearest containing
<form> element. This attribute allows you
to place the form control outside of a form and associate it with the form that has this id. The form must be in
the same document or shadow root for this to work.
Type
HTMLFormElement | null
|
|
namename |
The name of the input, submitted as a name/value pair with form data.
Type
string | null
Default
null
|
|
sizesize |
The radio's size. When used inside a radio group, the size will be determined by the radio group's size, which will
override this attribute.
Type
'xs' | 's' | 'm' | 'l' | 'xl'
|
|
valuevalue |
The radio's value. When selected, the radio group will receive this value.
Type
string
|
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
setCustomValidity() |
Sets a custom validation message. While the message is set, the form control is invalid and the message is shown when validity is reported. Pass an empty string to clear it. |
message: string
|
Events
Learn more about events.
| Name | Description |
|---|---|
blur |
Emitted when the control loses focus. |
focus |
Emitted when the control gains focus. |
CSS Custom Properties
Learn more about CSS custom properties.
| Name | Description |
|---|---|
--checked-icon-color |
The color of the checked icon.
|
--checked-icon-scale |
The size of the checked icon relative to the radio.
|
Custom States
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
checked |
Applied when the control is checked. |
:state(checked)
|
disabled |
Applied when the control is disabled. |
:state(disabled)
|
invalid |
Applied when the form control fails validation. |
:state(invalid)
|
optional |
Applied when the form control is not required. |
:state(optional)
|
required |
Applied when the form control is required. |
:state(required)
|
user-invalid |
Applied when the form control fails validation after the user has interacted with it. |
:state(user-invalid)
|
user-valid |
Applied when the form control passes validation after the user has interacted with it. |
:state(user-valid)
|
valid |
Applied when the form control passes validation. |
:state(valid)
|
CSS Parts
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
checked-icon |
The checked icon. |
::part(checked-icon)
|
control |
The circular container that wraps the radio's checked state. |
::part(control)
|
label |
The container that wraps the radio's label. |
::part(label)
|
Dependencies
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.