Radio Group
View as MarkdownAn easily stylable radio button component.
Features
Permalink to heading "Features"- Full keyboard navigation support
- Supports horizontal and vertical orientations
- Syncs with native form elements for proper form submission
- Works with Field component for form integration
<primitives:radioGroup.root>
<primitives:radioGroup.item>
<primitives:radioGroup.itemControl />
<primitives:radioGroup.itemText />
<primitives:radioGroup.itemHiddenInput />
</primitives:radioGroup.item>
<primitives:radioGroup.indicator />
</primitives:radioGroup.root>
Installation
Permalink to heading "Installation"typo3 ui:add radio-group
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Disabled Items
Permalink to heading "Disabled Items"Disable specific radio options.
Disabled Group
Permalink to heading "Disabled Group"Disable the entire radio group.
No Default Value
Permalink to heading "No Default Value"Start with no option selected by default.
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
radioGroup.root
Permalink to heading "radioGroup.root"Provides shared radio group state and semantics. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
defaultValue | stringThe initial value of the checked radio when rendered. Use when you don't need to control the value of the radio group. Inherited from a surrounding field when available. | No | - |
name | stringThe name of the input fields in the radio. Useful for form submission. Inherited from a surrounding field when available. | No | - |
form | stringThe associate form of the underlying input. | No | - |
disabled | booleanIf `true`, the radio group will be disabled. Inherited from a surrounding field when available. | No | - |
readOnly | booleanWhether the radio group is read-only. Inherited from a surrounding field when available. | No | - |
required | booleanIf `true`, the radio group is marked as required. Inherited from a surrounding field when available. | No | - |
orientation | Enum\OrientationOrientation of the radio group. | No | Vertical |
invalid | booleanIf `true`, the radio group is marked as invalid. Inherited from a surrounding field when available. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-radio-group-root | <uid> |
data-orientation | The orientation of the radio-group |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
data-required | Present when required |
radioGroup.label
Permalink to heading "radioGroup.label"Labels the radio group. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-radio-group-label | <uid> |
data-orientation | The orientation of the label |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
data-required | Present when required |
radioGroup.item
Permalink to heading "radioGroup.item"Wraps a single radio item and makes it clickable. Renders a <label> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the radio item. | Yes | - |
disabled | booleanWhether the radio item is disabled. | No | - |
invalid | booleanWhether the radio item is invalid. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-radio-group-item | <uid> |
data-focus | Present when focused |
data-focus-visible | Present when focused with keyboard |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-state | "checked" | "unchecked" |
data-hover | Present when hovered |
data-invalid | Present when invalid |
data-orientation | The orientation of the item |
data-ssr | Present when not rendered in the browser. Useful for ssr styling |
radioGroup.itemHiddenInput
Permalink to heading "radioGroup.itemHiddenInput"Provides the native radio input for form submission. Renders an <input> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
radioGroup.itemControl
Permalink to heading "radioGroup.itemControl"Displays the visual radio control. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-radio-group-item-control | <uid> |
data-active | Present when active or pressed |
data-focus | Present when focused |
data-focus-visible | Present when focused with keyboard |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-state | "checked" | "unchecked" |
data-hover | Present when hovered |
data-invalid | Present when invalid |
data-orientation | The orientation of the item |
data-ssr | Present when not rendered in the browser. Useful for ssr styling |
radioGroup.itemText
Permalink to heading "radioGroup.itemText"Displays the visible label text for a radio item. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-radio-group-item-text | <uid> |
data-focus | Present when focused |
data-focus-visible | Present when focused with keyboard |
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-state | "checked" | "unchecked" |
data-hover | Present when hovered |
data-invalid | Present when invalid |
data-orientation | The orientation of the item |
data-ssr | Present when not rendered in the browser. Useful for ssr styling |
radioGroup.indicator
Permalink to heading "radioGroup.indicator"Displays the moving selection indicator. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-radio-group-indicator | <uid> |
data-disabled | Present when disabled |
data-orientation | The orientation of the indicator |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
value | string | null | The current value of the radio group |
setValue | (value: string) => void | Function to set the value of the radio group |
clearValue | VoidFunction | Function to clear the value of the radio group |
focus | VoidFunction | Function to focus the radio group |
getItemState | (props: ItemProps) => ItemState | Returns the state details of a radio input |
getRootState | () => RootState | Returns the state of the radio group |
Accessibility
Permalink to heading "Accessibility"| Key | Description |
|---|---|
Tab | Moves focus to either the checked radio item or the first radio item in the group. |
Space | When focus is on an unchecked radio item, checks it. |
ArrowDown | Moves focus and checks the next radio item in the group. |
ArrowRight | Moves focus and checks the next radio item in the group. |
ArrowUp | Moves focus to the previous radio item in the group. |
ArrowLeft | Moves focus to the previous radio item in the group. |