TreeSelect
RC.12.1
Included in RC.12.1 for Vue + Vite, Nuxt and NativeScript.
<MTreeSelect
v-model="selected"
v-model:expanded="expanded"
:nodes="nodes"
multiple
label="Disciplines"
/>| Prop | Type | Default | Contract |
|---|---|---|---|
nodes | readonly TreeSelectNode[] | required | Unique id, label, optional children/disabled/selectable; up to 2000 nodes and 32 levels. |
modelValue / expanded | readonly string[] | [] / [] | Selected IDs and expanded IDs, both controlled. Single mode accepts at most one ID. |
multiple / disabled / animated | boolean | false / false / true | Multiple choice, editing lock and Jolt entry fades. |
label / id | string | required / optional | Accessible component name and optional stable ID. |
Search reveals matching descendants with their ancestors, without changing the controlled expansion. Disabled parents disable their descendants. Selection is explicit per node, without cascading or implicit partial states. Unknown selected IDs are retained. Clearing removes only selectable, enabled IDs. Standard buttons and checkboxes support Tab, Enter and Space; Escape closes the popover and restores its trigger. All control labels are localizable. No virtualization or asynchronous tree loading is included.
update:modelValue → string[]; update:expanded → string[].
New rows settle into their final boxes with Jolt, one after another, dropping a few pixels from the row that revealed them. Options already on screen never move, so expanding or filtering never slides another option over a clickable target. The expand control is a chevron that turns with a spring; its accessible name still says Expand or Collapse. In single mode the chosen option shows a check that pops in. Selection does not restart row motion. Use :animated="false" for static presentation; reduced motion shows new rows at once.
<script setup lang="ts">
import { computed, ref, onBeforeUnmount } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const t = (en: string, pt: string) => ((props.lang ?? locale.value) === 'pt' ? pt : en)
const animated = ref(true)
const selection = ref<string[]>(['lettering']),
expanded = ref(['studio'])
const nodes = computed(() => [
{
id: 'studio',
label: t('Creative studio', 'Estúdio criativo'),
selectable: false,
children: [
{
id: 'identity',
label: t('Brand identity', 'Identidade visual'),
selectable: false,
children: [
{ id: 'lettering', label: 'Lettering' },
{ id: 'color', label: t('Color systems', 'Sistemas de cor') },
],
},
{
id: 'editorial',
label: 'Editorial',
selectable: false,
children: [
{ id: 'print', label: t('Print editions', 'Edições impressas') },
{ id: 'digital', label: t('Digital stories', 'Histórias digitais') },
],
},
{ id: 'archive', label: t('Archive · locked', 'Arquivo · bloqueado'), disabled: true },
],
},
])
</script>
<template>
<MColumn gap="lg">
<MText text="THE FIELD GUIDE / 01" variant="overline" tone="primary" />
<MText
:text="t('Find your corner of the studio.', 'Encontre seu canto no estúdio.')"
variant="title"
/>
<MText
:text="
t(
'A little structure. Endless possibilities.',
'Um pouco de estrutura. Possibilidades sem fim.',
)
"
tone="muted"
/>
<MCard padding="lg"
><MTreeSelect
id="studio-tree-select"
v-model="selection"
v-model:expanded="expanded"
:nodes="nodes"
multiple
:animated="animated"
:label="t('Your disciplines', 'Suas disciplinas')"
:searchLabel="t('Find a discipline', 'Buscar disciplina')"
:placeholder="t('Choose disciplines', 'Escolher disciplinas')"
:clearLabel="t('Clear selection', 'Limpar seleção')"
:emptyLabel="t('No matches', 'Nenhum resultado')"
:expandLabel="t('Expand', 'Expandir')"
:collapseLabel="t('Collapse', 'Recolher')"
/></MCard>
<MText id="tree-select-value" :text="selection.join(',')" variant="caption" tone="muted" />
<MSwitch v-model="animated" :label="t('Animate changes', 'Animar mudanças')" />
</MColumn>
</template>On Web, iOS and Android, collapsing a branch can fade its outgoing rows in place. The remaining choices stay still during the exit so that a pointer or finger keeps the same target.
Desktop
The tree opens below the field. Use the search field or expand a branch with the arrow keys or its button. Removed rows fade in place while the remaining controls take their new positions immediately. See Desktop components.