Radio
MRadioGroup · Choose one option from a visible list.
Next alpha
Available in 0.1.0-alpha.4.
Usage
<script setup lang="ts">
import { ref } from 'vue'
import type { ChoiceOption, ChoiceValue } from '@getcortexlabs/mavis-core'
const rhythm = ref<ChoiceValue | null>(null)
const options: ChoiceOption[] = [
{ value: 'weekly', label: 'Take it slow', helperText: 'A weekly digest.' },
{ value: 'daily', label: 'A little every day' },
{ value: 'live', label: 'As it happens', disabled: true },
]
</script>
<template>
<MRadioGroup v-model="rhythm" :options="options" label="Reading rhythm" />
</template>The group renders its options; no separate MRadio item or platform layout is required. Use plain text labels and keep links or other controls outside the group options.
API
| Prop | Type | Default | Purpose |
|---|---|---|---|
modelValue / v-model | ChoiceValue | null | null | Controlled selection; null means no choice. |
options | readonly ChoiceOption[] | required | Ordered list of uniquely identified options. |
label | string | required | Visible group label. |
helperText | string | '' | Optional explanation below the group label. |
disabled | boolean | false | Disables every option without changing the value. |
width / grow / shrink | dimension / number | auto / 0 / layout context | Group size and space distribution. |
id identifies the group. accessibilityHidden follows the shared contract.
update:modelValue emits one string or number when the user requests a different enabled option. Repeated activation of the selected option emits nothing. External changes never emit; the control does not emit null or clear itself.
Shared choice contract
ChoiceValue is a string or finite number. ChoiceOption has value, a non-empty label, optional helperText and optional disabled. Labels can change with the language without changing values. The number 1 and string '1' are different choices; 0 and '' are valid values. Duplicate values, empty labels and invalid values throw. The same core types are used by Select.
| Change | Result |
|---|---|
| Initial null or empty list | Nothing is selected. No implicit first choice. |
| Parent accepts an activation | The requested option becomes selected. |
| Parent rejects an activation | The previous selection remains, including the browser input state. |
| Selected option is disabled | It stays selected and cannot be activated. Other enabled options remain available. |
| Selected option is removed, or the value is absent | No option is marked; the model is left untouched. Reintroducing that value restores its mark. |
| Labels or order change | Selection follows the value. |
| Parent writes null | The selection clears without an event. |
The app owns required-field validation, persistence and submission. The group does not mutate the options array or choose a fallback.
Interaction and appearance
The indicator, label and help share one touch target. Labels wrap and the circle keeps its size. Mavis and Midnight colors follow the active theme.
Web uses native radio inputs inside a labelled radiogroup. Tab enters at the selected enabled option, or the first enabled option when needed. Arrow keys wrap through enabled choices and select them; Home/End go to the first/last enabled choice. Space selects the focused option. Tab leaves the group in one step. If every option is disabled, the group has no tab stop. CSS press feedback respects reduced motion. The dot of a newly selected option pops in with the theme's spring and one ring leaves its circle, both through Jolt.
NativeScript draws the themed circle above a native button input surface. Android exposes RadioButton and checked state, with a visible keyboard-focus outline. iOS exposes button/selected traits. Jolt handles press feedback and pops the dot of an option selected after the group has loaded, with a light haptic; it is stopped and the mark restored on disable, unload and unmount. Native keyboard movement follows platform focus navigation; the Web arrow-key group behavior is implemented in the Web renderer. Dragging to scroll must not select an option.
Full example
View source
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import type { ChoiceOption, ChoiceValue } from '@getcortexlabs/mavis-core'
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
const { t, locale } = useCatalogLocale(() => props.lang)
const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })
const language = computed(() => props.lang ?? locale.value)
const { theme } = useMavisTheme()
const selected = ref<ChoiceValue | null>(null)
const changes = ref(0)
const options = computed<ChoiceOption[]>(() =>
(props.lang ?? locale.value) === 'pt'
? [
{ value: 'calm', label: 'Sem pressa', helperText: 'Um resumo leve, no fim da semana.' },
{ value: 'daily', label: 'Um pouco por dia', helperText: 'Uma seleção nova a cada manhã.' },
{
value: 'live',
label: 'Em tempo real',
helperText: 'Disponível em breve.',
disabled: true,
},
]
: [
{
value: 'calm',
label: 'Take it slow',
helperText: 'A light digest at the end of the week.',
},
{
value: 'daily',
label: 'A little every day',
helperText: 'A fresh selection each morning.',
},
{ value: 'live', label: 'As it happens', helperText: 'Coming soon.', disabled: true },
],
)
const current = computed(
() => options.value.find((option) => option.value === selected.value)?.label,
)
function choose(value: ChoiceValue) {
selected.value = value
changes.value++
}
</script>
<template>
<m-column gap="lg">
<m-column padding="lg" gap="sm" radius="lg" :backgroundColor="theme.colors.primarySoft">
<m-text variant="overline" tone="primary">{{
t(language === 'pt' ? 'MENOS RUÍDO' : 'LESS NOISE')
}}</m-text>
<m-text variant="heading">{{
t(language === 'pt' ? 'No seu tempo.' : 'At your own pace.')
}}</m-text>
<m-text variant="caption" tone="muted">{{
t(
language === 'pt'
? 'Escolha como as novidades chegam até você.'
: 'Choose how new ideas reach you.',
)
}}</m-text>
</m-column>
<m-radio-group
:modelValue="selected"
:options="options"
:label="t(language === 'pt' ? 'Ritmo de leitura' : 'Reading rhythm')"
@update:modelValue="choose"
/>
<m-column padding="md" gap="xs" radius="md" :backgroundColor="theme.colors.accentSoft">
<m-text variant="caption" tone="accent">{{
t(language === 'pt' ? 'SUA ESCOLHA' : 'YOUR CHOICE')
}}</m-text>
<m-text>{{
t(current ?? (language === 'pt' ? 'Ainda sem escolha' : 'Nothing selected yet'))
}}</m-text>
</m-column>
<m-radio-group
:modelValue="'calm'"
:options="options.slice(0, 2)"
disabled
:label="t(language === 'pt' ? 'Preferência da equipe' : 'Team preference')"
/>
<m-row justify="between" wrap gap="sm">
<m-text variant="caption" tone="muted">{{
t(
language === 'pt'
? `${changes} ${changes === 1 ? 'alteração' : 'alterações'}`
: `${changes} ${changes === 1 ? 'change' : 'changes'}`,
)
}}</m-text>
<m-button size="sm" variant="ghost" @click="selected = null">{{
t(language === 'pt' ? 'Limpar escolha' : 'Clear selection')
}}</m-button>
</m-row>
</m-column>
</template>Focus session uses Radio for the ambience preference alongside a Slider, loading action and session summary. Use Checkbox for independent selections and Switch for a boolean setting.
Desktop
On the desktop each option is a button drawn with the colours of the theme, and the group is a single Tab stop: the arrow keys, Home and End select the next option that is available. The Mac reports the chosen option to VoiceOver; Windows does not yet (#489); see Desktop components.