Checkbox
MCheckbox · Select independent items, filters or options.
Next alpha
Available in 0.1.0-alpha.4.
Usage
<script setup lang="ts">
import { ref } from 'vue'
const selected = ref(false)
const mixed = ref(true)
</script>
<template>
<MCheckbox
v-model="selected"
v-model:indeterminate="mixed"
label="All topics"
helperText="Choose what appears in your collection."
/>
</template>API
| Prop | Type | Default | Purpose |
|---|---|---|---|
modelValue / v-model | boolean | false | Controlled checked value. |
indeterminate | boolean | false | Controlled partial-selection display; takes precedence over checked. |
label | string | required | Visible label and accessible name. |
helperText | string | '' | Optional supporting text. |
indeterminateLabel | string | Partially selected | Accessible description of the mixed state. Translate with the label. |
disabled | boolean | false | Prevents activation from the whole row and keyboard. |
width | number, percentage or auto | auto | Width of the full row. |
grow / shrink | number | 0 / layout context | Space distribution in the parent. |
id identifies the control. accessibilityHidden follows the shared component contract.
Each activation emits one update:modelValue boolean. With indeterminate=true, it first emits update:indeterminate(false), then update:modelValue(true), even when the previous checked value was already true. Otherwise it toggles the checked value. External updates never emit.
Both values belong to the parent. Use both v-model bindings for stored state, or derive the parent checkbox from a selection array and update that array from update:modelValue, as the full example does. Ignored changes keep the old appearance; indeterminate is not cleared privately. The component does not manage arrays, validation, submission or a checkbox group.
Interaction and appearance
The box, label and supporting text activate one control. Keep labels as plain text; links and other controls belong outside the Checkbox. Long labels wrap without shrinking the mark.
Web uses a native checkbox input beneath the themed appearance. Tab focuses it and Space activates it; Enter retains browser form behavior. The input exposes the mixed state. Selecting draws the check or the mixed dash, bumps the mark and sends one ring outward from the box; the stroke is CSS and the bump and ring are Jolt, and all three respect reduced motion. NativeScript uses a native button as the full-row input surface, with checkbox semantics and a Mavis mark. Android keyboard focus has a theme-colored outline; iOS uses system focus treatment. Jolt animates the mark on press, pops a mark that appears after the control has loaded and asks for a light haptic with it; motion is released on disable, unload and unmount. A mark present when the control loads is the initial state and does not animate. Scroll gestures must not select an item.
Use Switch for an immediate on/off preference.
Full example
This file runs in both catalogs and the preview. The app derives select-all and mixed states from its selected topic IDs.
View source
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
const { t } = useCatalogLocale()
withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: 'pt' })
const { theme } = useMavisTheme()
const topics = [
{ id: 'design', pt: 'Design de interfaces', en: 'Interface design' },
{ id: 'development', pt: 'Desenvolvimento', en: 'Development' },
{ id: 'product', pt: 'Produto e pesquisa', en: 'Product and research' },
]
const selected = ref(['design'])
const all = computed(() => selected.value.length === topics.length)
const mixed = computed(() => selected.value.length > 0 && !all.value)
const changes = ref(0)
function toggle(id: string, checked: boolean) {
selected.value = checked
? [...selected.value, id]
: selected.value.filter((value) => value !== id)
changes.value++
}
function toggleAll(checked: boolean) {
selected.value = checked ? topics.map((topic) => topic.id) : []
changes.value++
}
</script>
<template>
<m-column gap="lg">
<m-column padding="lg" gap="sm" radius="lg" :backgroundColor="theme.colors.accentSoft">
<m-text variant="overline" tone="accent">{{
t(lang === 'pt' ? 'SUA SELEÇÃO' : 'YOUR SELECTION')
}}</m-text>
<m-text variant="heading">{{
t(lang === 'pt' ? 'Ideias que combinam.' : 'Ideas that fit.')
}}</m-text>
<m-text variant="caption" tone="muted">{{
t(
lang === 'pt'
? 'Escolha os assuntos que despertam sua curiosidade.'
: 'Choose the topics that spark your curiosity.',
)
}}</m-text>
</m-column>
<m-column gap="sm">
<m-checkbox
id="all-topics"
:modelValue="all"
:indeterminate="mixed"
:label="t(lang === 'pt' ? 'Todos os assuntos' : 'All topics')"
:helperText="
t(
lang === 'pt'
? `${selected.length} de 3 selecionados`
: `${selected.length} of 3 selected`,
)
"
:indeterminateLabel="lang === 'pt' ? 'Seleção parcial' : 'Partially selected'"
@update:modelValue="toggleAll"
/>
<m-box :height="1" :backgroundColor="theme.colors.border" />
<m-checkbox
v-for="topic in topics"
:key="topic.id"
:id="topic.id"
:modelValue="selected.includes(topic.id)"
:label="t(lang === 'pt' ? topic.pt : topic.en)"
@update:modelValue="toggle(topic.id, $event)"
/>
<m-box :height="1" :backgroundColor="theme.colors.border" />
<m-checkbox
:modelValue="true"
disabled
:label="t(lang === 'pt' ? 'Conteúdo da equipe' : 'Team content')"
:helperText="
t(lang === 'pt' ? 'Incluído pela sua organização.' : 'Included by your organization.')
"
/>
<m-checkbox disabled :label="t(lang === 'pt' ? 'Conteúdo arquivado' : 'Archived content')" />
<m-checkbox
indeterminate
disabled
:label="t(lang === 'pt' ? 'Coleção compartilhada' : 'Shared collection')"
:indeterminateLabel="lang === 'pt' ? 'Seleção parcial' : 'Partially selected'"
/>
</m-column>
<m-row justify="between" gap="sm" wrap>
<m-text variant="caption" tone="muted">{{
t(
lang === 'pt'
? `${changes} ${changes === 1 ? 'alteração' : 'alterações'}`
: `${changes} ${changes === 1 ? 'change' : 'changes'}`,
)
}}</m-text>
<m-button size="sm" variant="ghost" @click="selected = ['design']">{{
t(lang === 'pt' ? 'Restaurar' : 'Reset')
}}</m-button>
</m-row>
</m-column>
</template>In context
Library combines independent filters, select-all, result cards and an empty state in a complete screen.
Desktop
On the desktop the checkbox is a button drawn with the colours of the theme, not the checkbox of the system. A click or Space toggles it, and a mixed box becomes checked first, as on the Web. The Mac reports the checked or mixed state to VoiceOver as the value of a checkbox. Windows does not report it yet (#489), so there a mixed box carries indeterminateLabel in its name; see Desktop components.