Form radio
Lets users choose exactly one option from a related set.
On this page
This docs is LLM-friendly and available as clean Markdown.
Supported browser agents can also use WebMCP to search, read, and open these docs. Learn more
Usage
import { GlFormRadio } from "gitlab-ui-react/form-radio";
import { GlFormRadioGroup } from "gitlab-ui-react/form-radio-group";<GlFormRadioGroup
aria-label="Visibility"
defaultValue="private"
name="visibility">
<GlFormRadio value="private">Private</GlFormRadio>
<GlFormRadio value="public">Public</GlFormRadio>
</GlFormRadioGroup>Default
Use GlFormRadioGroup for related options when exactly one can be selected. The group shares its value, name, state, required state, and disabled state with child radios.
Radio group
import {
GlFormFieldLegend,
GlFormFieldSet,
} from "gitlab-ui-react/form-field";
import { GlFormRadio } from "gitlab-ui-react/form-radio";
import { GlFormRadioGroup } from "gitlab-ui-react/form-radio-group";
export default function FormRadioExample() {
return (
<GlFormFieldSet>
<GlFormFieldLegend id="visibility-options">
Visibility
</GlFormFieldLegend>
<GlFormRadioGroup
aria-label="Visibility"
defaultValue="private"
name="visibility">
<GlFormRadio value="private">Private</GlFormRadio>
<GlFormRadio value="internal">Internal</GlFormRadio>
<GlFormRadio value="public">Public</GlFormRadio>
</GlFormRadioGroup>
</GlFormFieldSet>
);
}
States and help text
Individual radios support initial selection, disabled state, validation state, and help content. A radio used outside a group needs a shared name when it belongs to other native radios.
Radio states
import { GlFormRadio } from "gitlab-ui-react/form-radio";
export default function FormRadioStatesExample() {
return (
<div className="flex flex-col gap-3">
<GlFormRadio defaultChecked name="example-state" value="selected">
Selected option
</GlFormRadio>
<GlFormRadio disabled name="example-state" value="disabled">
Unavailable option
</GlFormRadio>
<GlFormRadio help="This choice can be changed later." name="separate-example">
Option with help text
</GlFormRadio>
</div>
);
}
Accessibility
- Wrap a related set in
GlFormFieldSetwith a conciseGlFormFieldLegend. - Give
GlFormRadioGroupits own accessible name witharia-label, and retain each option’s visible label. - Keep options together and vertically stacked. Do not insert unrelated interactive content inside the group.
- Preselect a common or recommended option when appropriate, but do not select one merely to avoid an empty state.
- Use checkboxes instead when users may select zero or multiple options.
API
Both components forward supported native attributes. A radio inside a group takes selection and shared form state from the group.
GlFormRadio
| Prop | Description | Default |
|---|---|---|
checked |
Controls the checked state outside a group. | — |
defaultChecked |
Sets the initial uncontrolled checked state. | false |
onCheckedChange |
Reports the next checked state. | — |
value |
Sets the native value and the option value inside a group. | true |
disabled |
Disables the radio. | false |
required |
Marks a named radio as required. | false |
state |
Sets valid, invalid, or neutral appearance. | null |
help |
Renders help content under the label. | — |
GlFormRadioGroup
| Prop | Description | Default |
|---|---|---|
value |
Controls the selected option value. | — |
defaultValue |
Sets the initial uncontrolled selection. | null |
onValueChange |
Reports the selected option value. | — |
options |
Generates radios from strings, numbers, or option objects. | [] |
name |
Sets the shared name for child radios. | Generated group ID |
disabled |
Disables every radio in the group. | false |
required |
Marks grouped radios as required. | false |
state |
Sets group and child validation appearance. | null |