TreeView
Added in alpha.11
Included in Mavis 0.1.0-alpha.11 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.
<MTreeView
v-model="selected"
v-model:expanded="expanded"
:nodes="nodes"
label="Files"
@load="loadChildren"
/>| Prop | Type | Default | Description |
|---|---|---|---|
nodes | readonly TreeNode[] | required | key, label, disabled, children and hasChildren. |
modelValue / v-model | ChoiceValue or null | null | Selected key, independent of expansion. |
expanded / v-model:expanded | readonly ChoiceValue[] | [] | Expanded branch keys. |
loadingKeys | readonly ChoiceValue[] | [] | Loading branches; prevents repeated requests while waiting. |
disabled / emptyLabel | boolean / string | false / No items | Global disabled state and empty fallback. |
Keys are unique across the entire tree; cycles and depth over 100 are rejected. hasChildren with absent children emits load when expanded. The application fetches children, updates nodes and controls loadingKeys; use [] for an empty result. Requests, errors and cancellation belong to the application. Web provides roving tabindex, arrow navigation, Home/End, initial-letter search and Enter/Space; expansion arrows follow the left/right tree convention. Native exposes explicit expand/select actions. MReveal/Jolt animates expansion with reduced-motion support. Cascading selection and virtualization are not part of this version.
Opening a branch grows its height while the chevron turns with a light spring. Children that appear because a branch opened or finished loading arrive one after another, a few milliseconds apart; branches open when the tree first renders stay still. A child that receives keyboard focus during its arrival settles at once, so the focus ring never travels. The selected node shows a check that pops in, and the check shrinks away when the selection moves; its room is always reserved. Under reduced motion children appear in place.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
import type { ChoiceValue, TreeNode } from '@getcortexlabs/mavis-core'
const selected = ref<ChoiceValue | null>('brand')
const expanded = ref<ChoiceValue[]>(['studio'])
const loading = ref<ChoiceValue[]>([])
const nodes = ref<TreeNode[]>([
{
key: 'studio',
label: 'Studio',
children: [
{ key: 'brand', label: 'Brand system' },
{ key: 'website', label: 'Website' },
{ key: 'archive', label: 'Archive', disabled: true },
],
},
{ key: 'research', label: 'Research', hasChildren: true },
{ key: 'notes', label: 'Field notes' },
])
async function load(node: TreeNode) {
loading.value = [...loading.value, node.key]
await new Promise((resolve) => setTimeout(resolve, 250))
nodes.value = nodes.value.map((item) =>
item.key === node.key
? {
...item,
children: [
{ key: 'interviews', label: 'Interviews' },
{ key: 'insights', label: 'Insights' },
],
}
: item,
)
loading.value = loading.value.filter((key) => key !== node.key)
}
</script>
<template>
<MCard padding="lg" gap="md">
<MText variant="overline" :text="t('ROOM TO GROW', 'ESPAÇO PARA CRESCER')" tone="primary" />
<MTreeView
v-model="selected"
v-model:expanded="expanded"
:nodes="nodes"
:loadingKeys="loading"
:label="t('Ideas, organized', 'Ideias organizadas')"
@load="load"
/>
<MSeparator /><MText
id="tree-value"
:text="String(selected ?? '')"
tone="muted"
variant="caption"
/>
</MCard>
</template>Desktop
Each row is a native button: Up and Down walk the visible rows, Right opens a branch or enters it, Left closes it or goes to the parent, Enter or Space selects, and a letter jumps to the next label that starts with it. The chevron opens a branch with the mouse and stays out of the Tab order; children are loaded through load as on the other renderers. See Desktop components.