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.
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', }),];{ "$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.
| prop | type | description |
|---|---|---|
options | array | Required. Collection of options to display |
appearance | 'default' | 'segmented' | 'segmented' shows the options as a row of joined buttons. Defaults to 'default' |
direction | row | column | Layout direction for the radio options. Defaults to column |
hint | string | Description text displayed below the label |
labelField | string | Custom key to use for the display label of each option. Defaults to label |
valueField | string | Custom key to use for the underlying value of each option. Defaults to value |
Use the property hint to provide instructions for the user.
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', }),];{ "$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." } } ]}Custom Fields
Section titled “Custom Fields”You can map different fields for the options using labelField and valueField.
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', }),];{ "$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" } } ]}Direction
Section titled “Direction”Use the direction property to display radio options horizontally.
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', }),];{ "$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" } } ]}Segmented
Section titled “Segmented”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.
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', }),];{ "$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" } ] } } ]}Styling
Section titled “Styling”Radio Groups can be styled as explained in the Styling Guide.
CSS Variables
Section titled “CSS Variables”Following you will find a list with the CSS Variables and a quick description of what you will style.
| CSS Variable | Description |
|---|---|
--gui-intent-primary | Color for the inner circle when selected, and of the selected segment |
--gui-intent-primary-text | Text of the selected segment |
--gui-border-strong | Border of the segments |
--gui-bg-surface-hover | Background of a segment under the pointer |
Anatomy
Section titled “Anatomy”This is the anatomy of the Radio Group Widget in case you want to use your CSS styles.
<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>