Skip to content
Forms, switch product

Radio Group

Radio Group widgets are Input Fields that present a set of mutually exclusive options. Users can select exactly one option from the group.

radiogroup.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.radiogroup('preference', {
options: [
{
label: 'Option A',
value: 'a',
},
{
label: 'Option B',
value: 'b',
},
{
label: 'Option C',
value: 'c',
},
],
label: 'Select your preference',
uid: 'radiogroup_id',
}),
];
radiogroup.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "radiogroup_id",
"kind": "input",
"type": "radiogroup",
"path": "preference",
"label": "Select your preference",
"props": {
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
]
}
}
]
}

Use these props to customize your Radio Group widget.

proptypedescription
optionsarrayRequired. Collection of options to display
appearance'default' | 'segmented''segmented' shows the options as a row of joined buttons. Defaults to 'default'
directionrow | columnLayout direction for the radio options. Defaults to column
hintstringDescription text displayed below the label
labelFieldstringCustom key to use for the display label of each option. Defaults to label
valueFieldstringCustom key to use for the underlying value of each option. Defaults to value

Use the property hint to provide instructions for the user.

radiogroup.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.radiogroup('preference', {
options: [
{
label: 'Email',
value: 'email',
},
{
label: 'SMS',
value: 'sms',
},
],
hint: 'We will use this method to send you notifications.',
label: 'Select your preference',
uid: 'radiogroup_hint',
}),
];
radiogroup.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "radiogroup_hint",
"kind": "input",
"type": "radiogroup",
"path": "preference",
"label": "Select your preference",
"props": {
"options": [
{
"label": "Email",
"value": "email"
},
{
"label": "SMS",
"value": "sms"
}
],
"hint": "We will use this method to send you notifications."
}
}
]
}

You can map different fields for the options using labelField and valueField.

radiogroup.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.radiogroup('preference', {
options: [
{
name: 'Choice 1',
id: '1',
},
{
name: 'Choice 2',
id: '2',
},
],
labelField: 'name',
valueField: 'id',
label: 'Select your preference',
uid: 'radiogroup_custom',
}),
];
radiogroup.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "radiogroup_custom",
"kind": "input",
"type": "radiogroup",
"path": "preference",
"label": "Select your preference",
"props": {
"options": [
{
"name": "Choice 1",
"id": "1"
},
{
"name": "Choice 2",
"id": "2"
}
],
"labelField": "name",
"valueField": "id"
}
}
]
}

Use the direction property to display radio options horizontally.

radiogroup.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.radiogroup('preference', {
options: [
{
label: 'Option A',
value: 'a',
},
{
label: 'Option B',
value: 'b',
},
{
label: 'Option C',
value: 'c',
},
],
direction: 'row',
label: 'Select your preference',
uid: 'radiogroup_direction',
}),
];
radiogroup.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"uid": "radiogroup_direction",
"kind": "input",
"type": "radiogroup",
"path": "preference",
"label": "Select your preference",
"props": {
"options": [
{
"label": "Option A",
"value": "a"
},
{
"label": "Option B",
"value": "b"
},
{
"label": "Option C",
"value": "c"
}
],
"direction": "row"
}
}
]
}

Use appearance: 'segmented' to show the options as a segmented control, a row of joined buttons, for a few short options such as Day, Week and Month. The value, the keyboard and the validation stay those of a radio group.

radiogroup.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.radiogroup('view', {
appearance: 'segmented',
options: [
{
label: 'Day',
value: 'day',
},
{
label: 'Week',
value: 'week',
},
{
label: 'Month',
value: 'month',
},
],
label: 'View',
defaultValue: 'week',
}),
];
radiogroup.json
{
"$schema": "https://golemui.com/schemas/form.schema.json",
"form": [
{
"kind": "input",
"type": "radiogroup",
"path": "view",
"label": "View",
"defaultValue": "week",
"props": {
"appearance": "segmented",
"options": [
{
"label": "Day",
"value": "day"
},
{
"label": "Week",
"value": "week"
},
{
"label": "Month",
"value": "month"
}
]
}
}
]
}

Radio Groups can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-intent-primaryColor for the inner circle when selected, and of the selected segment
--gui-intent-primary-textText of the selected segment
--gui-border-strongBorder of the segments
--gui-bg-surface-hoverBackground of a segment under the pointer

This is the anatomy of the Radio Group Widget in case you want to use your CSS styles.

radiogroup-anatomy.html
<gui-radiogroup-input class="gui-radiogroup gui-field">
<gui-radiogroup class="gui-field">
<span class="gui-label" id="fieldUid_label">
<span class="gui-label__text">Label</span>
<div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div>
</span>
<div
role="radiogroup"
class="gui-widget"
id="fieldUid"
aria-labelledby="fieldUid_label"
aria-describedby="fieldUid_hint"
>
<label for="fieldUid_0">
<input
type="radio"
tabindex="0"
id="fieldUid_0"
name="fieldUid"
form="fieldUid_none"
value="a"
aria-describedby="fieldUid_hint"
/>
Option A
</label>
<label for="fieldUid_1">
<input
type="radio"
tabindex="-1"
id="fieldUid_1"
name="fieldUid"
form="fieldUid_none"
value="b"
aria-describedby="fieldUid_hint"
/>
Option B
</label>
<label for="fieldUid_2">
<input
type="radio"
tabindex="-1"
id="fieldUid_2"
name="fieldUid"
form="fieldUid_none"
value="c"
aria-describedby="fieldUid_hint"
/>
Option C
</label>
</div>
<div class="gui-validator gui-validator--empty" id="fieldUid_errors" role="alert"></div>
</gui-radiogroup>
</gui-radiogroup-input>