Radio group
A set of options where the user picks one, or several with multiple. As chips, as a segmented control or as a classic list of radios.
Showcase
<LnxRadioGroup v-model="..." <-- Pass a reactive variable here to bind its value :options="[{'value':'month','label':'Month'},{'value':'quarter','label':'Quarter'},{'value':'year','label':'Year'}]" @update:modelValue="..." <-- Two way binding of the component > Period </LnxRadioGroup>
v-model
T | T[]The value of the picked option, or the values of the picked ones with `multiple` Default value: undefinedmode
RadioGroupModePills that wrap, a joined block for 2 to 4 options, or classic radios in a column Default value: RADIO_GROUP_MODES.CHIPSmultiple
booleanCheckboxes instead of radios: several can be picked and `v-model` is an array Default value: falsename
stringName of the inputs in a form. By default, a unique one, so the arrows move between the options Default value: undefinedhideLegend
booleanHides the legend, the default slot, but screen readers still read it Default value: falseWhen to use
- For a few options that fit on screen at once, so the user sees them all without opening anything. With many options, use a Select.
segmentedfor 2 to 4 options that change a view, like a period.multiplefor filters of several values with the look of chips. For a yes or no, use a Checkbox.
Examples
Chips
Pills that wrap to the next line. The arrows move the selection, as in any group of radios.
vue
<LnxRadioGroup v-model="category" :options="CATEGORIES" name="category">
What kind of document?
</LnxRadioGroup>1
2
3
2
3
Segmented
A joined block. With is-block, it takes the whole width.
vue
<LnxRadioGroup
v-model="period"
mode="segmented"
hide-legend
is-block
:options="[{ value: 'month', label: 'Month' }, { value: 'quarter', label: 'Quarter' }, { value: 'year', label: 'Year' }]"
>
Period
</LnxRadioGroup>1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
Several values
multiple turns the options into checkboxes and v-model into an array. Tab goes through the chips and the space bar picks them.
[
"open"
]
vue
<LnxRadioGroup
v-model="statuses"
multiple
:options="[{ value: 'open', label: 'Open' }, { value: 'in-progress', label: 'In progress' }, { value: 'closed', label: 'Closed' }]"
>
Status
</LnxRadioGroup>
<span>{{ statuses }}</span>1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
List and objects
mode="list" shows classic radios in a column. Values can be objects, and the option slot changes what each option shows.
vue
<form @submit.prevent>
<LnxRadioGroup v-model="property" mode="list" required :options="PROPERTIES.map(p => ({ value: p, label: p.name }))">
Property
<template #option="{ option, checked }">
<span>{{ option.label }}</span>
<small v-if="checked">(picked)</small>
</template>
</LnxRadioGroup>
<LnxButton type="submit">Save</LnxButton>
</form>
<span>{{ property }}</span>1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
API
Props
| Prop | Type | Description |
|---|---|---|
v-model | T | T[] | The value of the picked option, or the values of the picked ones with multiple |
options | RadioGroupOption<T>[] | The options to pick from |
mode | RadioGroupMode | Pills that wrap, a joined block for 2 to 4 options, or classic radios in a column Default: RADIO_GROUP_MODES.CHIPS |
multiple | boolean | Checkboxes instead of radios: several can be picked and v-model is an arrayDefault: false |
name | string | Name of the inputs in a form. By default, a unique one, so the arrows move between the options |
hide-legend | boolean | Hides the legend, the default slot, but screen readers still read it Default: false |
is-block | boolean | Takes the whole width of its container Default: false |
required | boolean | A radio must be picked to submit the form Default: false |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | T | T[] | Two way binding of the component |
Slots
| Slot | Scope | Description |
|---|---|---|
default | — | The legend of the group: what the options answer |
option | — | Content of each option, instead of its icon and label. Gets { option, checked } |
Accessibility
- It's a
<fieldset>with native inputs: the legend names the group, the arrows move between radios andnameandrequiredwork in forms. hide-legendhides the legend only on screen, so screen readers still read it.disabledon the radio group disables every option, anddisabledon an option only that one.
Types
RadioGroupOption
ts
export interface RadioGroupOption<T> {
value: T; /* Any value, also an object */
label: string; /* Text of the option */
icon?: string; /* Iconify icon before the label */
disabled?: boolean; /* Can't be picked */
}1
2
3
4
5
6
2
3
4
5
6
RadioGroupMode
ts
export const RADIO_GROUP_MODES = {
CHIPS: 'chips',
SEGMENTED: 'segmented',
LIST: 'list',
} as const;
export type RadioGroupMode = ValueOf<typeof RADIO_GROUP_MODES>;1
2
3
4
5
6
2
3
4
5
6