Radio
An easily stylable radio button component.
The Stencil example uses fs-radio-group, fs-radio-root, and fs-radio-indicator directly. The group owns selection and arrow-key navigation; its cancelable valueChange event provides event.detail.value for controlled consumers to write back. inputRef exposes the native radio input. The indicator unmounts when unchecked unless keepMounted is enabled. Use nativeButton (or the HTML native-button attribute) to render a native button instead of the default span.
Native labels, forms, the migrated Fieldset legend, and Field integration are supported. Field supplies validation, automatic field labels, and field-state attributes. The migrated Form adds inherited validation mode, consolidated values, form-level errors, and submit validation. React render, function-valued className/style, and React context are not Web Component APIs. No component-specific controller or hidden behavior is supplied by the docs.
Usage guidelines
- Form controls must have an accessible name: It can be created using
<label>elements, or theFieldandFieldsetcomponents. See Labeling a radio group and the forms guide.
Anatomy
Radio is always placed within Radio Group. Import the components and place them together:
Examples
Labeling a radio group
Label the group with aria-labelledby and a sibling label element:
An enclosing <label> is the simplest labeling pattern for each radio:
Rendering as a native button
By default, <Radio.Root> renders a <span> element to support enclosing labels. Prefer rendering each radio as a native button when using sibling labels (htmlFor/id).
Native buttons with wrapping labels are supported by using the render callback to avoid invalid HTML, so the hidden input is placed outside the label:
Form integration
Use Field and Fieldset for group labeling and form integration:
API reference
RadioGroup
Provides a shared state to a series of radio buttons. Renders a <div> element.
namestring—
- Name
- Description
Identifies the field when a form is submitted.
- Type
defaultValueValue—
- Name
- Description
The uncontrolled value of the radio button that should be initially selected.
To render a controlled radio group, use the
valueprop instead.- Type
valueValue—
- Name
- Description
The controlled value of the radio item that should be currently selected.
To render an uncontrolled radio group, use the
defaultValueprop instead.- Type
onValueChangefunction—
- Name
- Description
Callback fired when the value changes.
- Type
formstring—
- Name
- Description
Identifies the form that owns the radio inputs. Useful when the radio group is rendered outside the form.
- Type
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
- Default
false
readOnlybooleanfalse
- Name
- Description
Whether the user should be unable to select a different radio button in the group.
- Type
- Default
false
requiredbooleanfalse
- Name
- Description
Whether the user must choose a value before submitting a form.
- Type
- Default
false
inputRefReact.Ref<HTMLInputElement>—
- Name
- Description
A ref to access the hidden input element.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-disabled
Present when the radio group is disabled.
Attribute | Description | |
|---|---|---|
data-disabled | Present when the radio group is disabled. | |
RadioGroup.PropsHide
Re-Export of RadioGroup props as RadioGroupProps
RadioGroup.StateHide
RadioGroup.ChangeEventReasonHide
RadioGroup.ChangeEventDetailsHide
Root
Represents the radio button itself.
Renders a <span> element and a hidden <input> beside.
value*Value—
- Name
- Description
The unique identifying value of the radio in a group.
- Type
nativeButtonbooleanfalse
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
- Default
false
disabledboolean—
- Name
- Description
Whether the component should ignore user interaction.
- Type
readOnlyboolean—
- Name
- Description
Whether the user should be unable to select the radio button.
- Type
requiredboolean—
- Name
- Description
Whether the user must choose a value before submitting a form.
- Type
inputRefReact.Ref<HTMLInputElement>—
- Name
- Description
A ref to access the hidden input element.
- Type
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-checked
Present when the radio is checked.
data-unchecked
Present when the radio is not checked.
data-disabled
Present when the radio is disabled.
data-readonly
Present when the radio is readonly.
data-required
Present when the radio is required.
data-valid
Present when the radio is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the radio is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the radio’s value has changed (when wrapped in Field.Root).
data-touched
Present when the radio has been touched (when wrapped in Field.Root).
data-filled
Present when the radio is checked (when wrapped in Field.Root).
data-focused
Present when the radio is focused (when wrapped in Field.Root).
Attribute | Description | |
|---|---|---|
data-checked | Present when the radio is checked. | |
data-unchecked | Present when the radio is not checked. | |
data-disabled | Present when the radio is disabled. | |
data-readonly | Present when the radio is readonly. | |
data-required | Present when the radio is required. | |
data-valid | Present when the radio is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the radio is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the radio’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the radio has been touched (when wrapped in Field.Root). | |
data-filled | Present when the radio is checked (when wrapped in Field.Root). | |
data-focused | Present when the radio is focused (when wrapped in Field.Root). | |
Radio.Root.StateHide
Indicator
Indicates whether the radio button is selected.
Renders a <span> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
styleReact.CSSProperties | function—
- Name
- Description
Style applied to the element, or a function that returns a style object based on the component’s state.
- Type
keepMountedbooleanfalse
- Name
- Description
Whether to keep the HTML element in the DOM when the radio button is inactive.
- Type
- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
data-checked
Present when the radio is checked.
data-unchecked
Present when the radio is not checked.
data-disabled
Present when the radio is disabled.
data-readonly
Present when the radio is readonly.
data-required
Present when the radio is required.
data-valid
Present when the radio is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the radio is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the radio’s value has changed (when wrapped in Field.Root).
data-touched
Present when the radio has been touched (when wrapped in Field.Root).
data-filled
Present when the radio is checked (when wrapped in Field.Root).
data-focused
Present when the radio is focused (when wrapped in Field.Root).
data-starting-style
Present when the radio indicator begins animating in.
data-ending-style
Present when the radio indicator is animating out.
Attribute | Description | |
|---|---|---|
data-checked | Present when the radio is checked. | |
data-unchecked | Present when the radio is not checked. | |
data-disabled | Present when the radio is disabled. | |
data-readonly | Present when the radio is readonly. | |
data-required | Present when the radio is required. | |
data-valid | Present when the radio is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the radio is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the radio’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the radio has been touched (when wrapped in Field.Root). | |
data-filled | Present when the radio is checked (when wrapped in Field.Root). | |
data-focused | Present when the radio is focused (when wrapped in Field.Root). | |
data-starting-style | Present when the radio indicator begins animating in. | |
data-ending-style | Present when the radio indicator is animating out. | |