Select
MSelect · A compact field that opens a local list of choices.
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 interest = ref<ChoiceValue | null>(null)
const options: ChoiceOption[] = [
{ value: 'design', label: 'Design', helperText: 'Ideas taking shape.' },
{ value: 'photo', label: 'Photography' },
{ value: 'film', label: 'Film', disabled: true },
]
</script>
<template>
<MScreen scroll>
<MColumn padding="lg" gap="md">
<MSelect
v-model="interest"
:options="options"
label="Your world"
placeholder="Choose an interest"
/>
<MButton variant="ghost" @click="interest = null">Clear selection</MButton>
</MColumn>
</MScreen>
</template>API
| Prop | Type | Default | Purpose |
|---|---|---|---|
modelValue / v-model | ChoiceValue | null | null | Controlled value. Null means no choice. |
options | readonly ChoiceOption[] | required | The Radio choice contract: stable string/finite-number values, labels and optional helperText/disabled. |
label | string | required | Visible field label and list title. |
placeholder | string | Select an option | Field text when no option matches the value. |
helperText | string | '' | Explanation below the field. |
error | string | '' | Replaces helper text and gives the field an error border. |
disabled | boolean | false | Blocks opening; closes an open list without changing the value. |
closeLabel | string | Close | Accessible name of the list's close button. |
emptyText | string | No options available | Message inside an empty list. |
width / grow / shrink | dimension / number | auto / 0 / layout context | Field size and space distribution. |
id identifies the opener. accessibilityHidden follows the shared contract. Translate placeholder, closeLabel and emptyText along with labels and help.
update:modelValue emits one string or number when an enabled option different from the current value is activated. Selection closes the list immediately; there is no Apply step. Choosing the current option only closes it. Opening, cancelling, closing and external writes never emit. The parent can reject a proposal: the field continues to show the parent's value when the list closes.
Clear externally by writing null; Select does not emit null or add a synthetic empty option. An empty string and zero remain valid option values. Required-field validation, persistence and submission belong to the app. error displays a message; it does not validate the value.
Changes while open
Options and their labels, help and disabled states update live. Reordering preserves identity. Removing the selected option displays the placeholder without changing the model; adding the value back restores its label. A selected disabled option keeps its label and selection mark. Removed or disabled options cannot be chosen by an earlier event. No implicit fallback is written to the model.
The Web keyboard cursor stays on an enabled option, or moves to the selected enabled option/first enabled option when its target disappears. An external model update moves that cursor to the new selection. An empty list shows emptyText; a list with only disabled options remains cancellable.
Platform presentation
NativeScript: declare Select inside MScreen, which owns the Sheet layer. It uses the existing Jolt Sheet, scrollable choices with wrapping labels/help and native button/radio states. The close action stays in the header. Opening ends text editing before presenting the list, so dismissing it does not reopen the previous editor’s keyboard. The owning page remains mounted. With vue-router-ns, supply claimSystemBack to createMavis, as described in Sheet; Android back dismisses the list before navigating. Navigation/unload closes the list; unmount removes the layer and press listeners. Native keyboard movement follows the platform's focus navigation.
Web: a button opens a modal dialog containing a single-select listbox. Tab reaches the field; Enter, Space or Arrow Up/Down opens it. Focus starts at the selected enabled option, otherwise the first enabled one. Up/Down wrap and skip disabled options; Home/End reach the first/last; typing letters moves to a matching label. These movements do not change the value. Enter/Space or a click confirms. Escape, the close button and the backdrop cancel. Tab stays in the dialog while open; closing returns focus to the opener. Selection and keyboard cursor have separate visual indicators.
Both themes use the same tokens as Input. Long field labels wrap, and the chevron keeps its place.
Motion: the field's chevron turns with a spring as the list opens and turns back as it closes. The options arrive one after another as the sheet rises, and the chosen option's check pops in once its row has landed. Roles, the keyboard cursor and focus belong to the rows from the first frame; only their presentation moves, and reduced motion settles it at once. Motion runs through Jolt on both platforms.
The first scope is a local, unvirtualized list. Validation covers empty, four-option and 50-option lists; 50 is a tested size, not a guaranteed performance limit. Search, remote loading, multiple selection and custom option templates are deferred. Prefer Radio for a short list that should remain visible.
Helper and error text share one space below the field. Changing the message cross-fades the two lines. Clearing it collapses that space.
Desktop
On the Mac and Windows the list opens under the field, above the screen, and the arrows, Home, End, Return and the first letters of an option move and choose without the mouse. Escape or a click outside closes it and the keyboard goes back to the field; see Desktop components.
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 { theme } = useMavisTheme()
const selected = ref<ChoiceValue | null>(null)
const changes = ref(0)
const requiredInterest = ref<ChoiceValue | null>(null)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const options = computed<ChoiceOption[]>(() =>
pt.value
? [
{ value: 'design', label: 'Design', helperText: 'Ideias que ganham forma.' },
{ value: 'photography', label: 'Fotografia', helperText: 'Histórias contadas pela luz.' },
{
value: 'architecture',
label: 'Arquitetura e espaços para viver',
helperText: 'Um olhar novo sobre os lugares de todo dia.',
},
{ value: 'film', label: 'Cinema', helperText: 'Disponível em breve.', disabled: true },
]
: [
{ value: 'design', label: 'Design', helperText: 'Ideas taking shape.' },
{ value: 'photography', label: 'Photography', helperText: 'Stories told through light.' },
{
value: 'architecture',
label: 'Architecture and spaces to live in',
helperText: 'A new perspective on everyday places.',
},
{ value: 'film', label: 'Film', 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.accentSoft">
<m-row justify="between" gap="md">
<m-text variant="overline" tone="accent">{{
t(pt ? 'UM NOVO OLHAR' : 'A FRESH PERSPECTIVE')
}}</m-text>
<m-icon name="compass" size="lg" tone="accent" />
</m-row>
<m-text variant="heading">{{ t(pt ? 'O que move você?' : 'What moves you?') }}</m-text>
<m-text variant="caption" tone="muted">{{
t(pt ? 'Um interesse abre novas possibilidades.' : 'One interest opens new possibilities.')
}}</m-text>
</m-column>
<m-select
:modelValue="selected"
:options="options"
:label="t(pt ? 'Seu universo' : 'Your world')"
:placeholder="t(pt ? 'Escolha um interesse' : 'Choose an interest')"
:helperText="
t(
pt
? 'Comece pelo que desperta a sua curiosidade.'
: 'Start with what sparks your curiosity.',
)
"
:closeLabel="t(pt ? 'Fechar' : 'Close')"
@update:modelValue="choose"
/>
<m-column padding="md" gap="xs" radius="md" :backgroundColor="theme.colors.primarySoft">
<m-text variant="caption" tone="primary">{{ t(pt ? 'SUA ESCOLHA' : 'YOUR CHOICE') }}</m-text>
<m-text>{{
t(current ?? (pt ? 'Um mundo para descobrir.' : 'A world to discover.'))
}}</m-text>
</m-column>
<m-select
:modelValue="'design'"
:options="options"
disabled
:label="t(pt ? 'Seleção da equipe' : 'Team selection')"
/>
<m-select
v-model="requiredInterest"
:options="options"
:label="t(pt ? 'Interesse obrigatório' : 'Required interest')"
:placeholder="t(pt ? 'Escolha um interesse' : 'Choose an interest')"
:error="
t(
requiredInterest === null
? pt
? 'Escolha um interesse para continuar.'
: 'Choose an interest to continue.'
: '',
)
"
:closeLabel="t(pt ? 'Fechar' : 'Close')"
/>
<m-row justify="between" wrap gap="sm">
<m-text variant="caption" tone="muted">{{
t(
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(pt ? 'Limpar escolha' : 'Clear selection')
}}</m-button>
</m-row>
</m-column>
</template>Profile combines Select, Input and Switch. Save and Discard include the selected interest along with the text and boolean fields.
Mavis alpha.5 with Jolt RC.7 supports overlays inside animated cards. See composition boundaries and the static fallback.