ListDetail
A list and the detail of its selected record. From breakpoint up the two sit side by side; below it one pane shows at a time, with a Back button above the detail. The same screen runs on Vue + Vite, Nuxt, NativeScript iOS/Android and the desktop hosts.
<MListDetail v-model:selected="selected" label="Inbox" :height="480">
<template #list="{ row, select }">
<MListItem
v-for="message in messages"
:key="message.id"
v-bind="row(message.id)"
:title="message.subject"
interactive
@click="select(message.id)"
/>
</template>
<template #detail="{ selected }"><Message :id="selected" /></template>
<template #empty><MEmptyState title="Pick a message" /></template>
</MListDetail>API
| Prop | Type | Contract |
|---|---|---|
selected | string | number | null | null. The stable key of the open record, bound with v-model:selected. Never a position: 1 and '1' are different keys. |
label / listLabel / detailLabel / backLabel | string | The composition's required name; List / Detail / Back name the panes and the Back button. |
layout / initialLayout / breakpoint | 'auto' | 'split' | 'stack' / 'split' | 'stack' / number | auto / stack / 720. auto measures the component's own box, not the window. initialLayout holds until that first measurement, on the server too. |
listWidth / height / grow | number | 320 / — / 0. The list's width side by side, a fixed height, or a share of the parent's height. |
direction | 'ltr' | 'rtl' | — follows the page. Right to left puts the list on the right and turns the Back arrow around. |
animated | boolean | true. In a stack, Jolt slides in the pane that arrives. |
| Event | Payload | When |
|---|---|---|
update:selected | key | null, 'select' | 'back' | A row asks to open a record, or Back (button, system back, slot back()) asks to close it. |
layout | 'split' | 'stack' | The composition changed shape. |
Slots: list gets { selected, layout, select, row }, detail gets { selected, layout, back } and empty gets { layout }.
One detail, whatever the width
The detail is one tree in both layouts. Going from side by side to one pane and back never remounts it, so a draft in an input, a request in flight, a save that is running or a dialog opened from the detail keep the same owner and finish once. The pane that is out of view stays laid out but inert: it takes no pointer, keyboard or screen reader. The list keeps its scroll position by the key of the first row in view, so it comes back where it was even after the rows reflowed at another width.
Selection is controlled. The component asks with update:selected and shows what selected says, so the parent decides what a missing or archived record looks like, what loading and failing look like, and what to do when the data changes. Spread row(key) on each row: it ties the row to its key for focus and scrolling, wherever the row moves in the list.
Focus and back
- Opening a record in a stack moves the focus to the first heading of the detail (or an element marked
data-mavis-route-focus). Side by side, the focus stays on the row. - When the pane holding the focus hides, the focus moves to the pane that stays: the detail heading, or the Back button. It never stays in an inert pane.
- Going back returns the focus to the row of the record that was open, by key, and scrolls it into view.
- A focused editor keeps its text and selection while the layout changes.
In a stack, the Back button, the slot's back() and Android's back button all emit update:selected(null, 'back'), once per press. A dialog, sheet or popover open above the screen gets the back press first. Side by side there is no Back button and the composition does not claim the system back.
Routes
Keep the key in the route and the composition follows the router: browser back, the Back button and a guard then agree on the record.
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const selected = computed(() => (route.params.id ? String(route.params.id) : null))
function change(key: ListDetailKey | null, reason: ListDetailReason) {
if (key !== null) router.push(`/inbox/${key}`)
else if (reason === 'back' && window.history.state?.back) router.back()
else router.replace('/inbox')
}
</script>
<template>
<MListDetail :selected="selected" label="Inbox" @update:selected="change">…</MListDetail>
</template>A guard that refuses leaves the route and the detail where they were, and the detail stays usable. The detail only changes after the route has committed, so there is no transition to roll back.
Motion
In a stack, the pane that arrives slides in from its side with a Jolt spring from the theme's layout motion: the detail from the inline end, the list from the inline start. A new selection, a layout change, deactivation inside KeepAlive or unmounting stops the motion and settles the pane. With reduced motion the pane just appears. Side by side nothing moves.
SSR
The server renders initialLayout, because it cannot measure the box. With the default stack, a page that opens on a record renders the detail and an inert list; once the browser measures a wide box, the same detail tree moves beside the list without being created again.
Platforms
- Web: the panes are
sectionelements named bylistLabelanddetailLabel; the hidden one getsinert. - NativeScript: the panes scroll on their own and keep a focused field above the keyboard, like MScreen. The hidden pane is not interactive and is skipped by TalkBack and VoiceOver. A stack showing a detail answers Android's back button and the router's system back.
- Desktop: the hidden pane is left out of the window's views and its keyboard order; Back takes the keyboard when the list hides and returns it to the row. See Desktop components.
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { ListDetailKey, ListDetailLayout, ListDetailReason } from '@getcortexlabs/mavis-core'
import { useCatalogLocale } from '../locale'
import ListDetailMessage from './ListDetailMessage.vue'
import { inbox } from './list-detail-inbox'
const props = withDefaults(
defineProps<{
lang?: 'en' | 'pt'
height?: number
breakpoint?: number
direction?: 'ltr' | 'rtl'
/** With `navigate`, the selection lives outside, for example in the route. */
selected?: ListDetailKey | null
navigate?: (key: ListDetailKey | null, reason: ListDetailReason) => void
}>(),
{
lang: undefined,
height: 480,
breakpoint: 640,
direction: undefined,
selected: null,
navigate: undefined,
},
)
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const order = ref(inbox(false).map((message) => message.id))
const archived = ref<string[]>([])
const messages = computed(() => {
const byId = new Map(inbox(pt.value).map((message) => [message.id, message]))
return order.value.filter((id) => !archived.value.includes(id)).map((id) => byId.get(id)!)
})
const local = ref<ListDetailKey | null>(null)
const selected = computed(() => (props.navigate ? props.selected : local.value))
function change(key: ListDetailKey | null, reason: ListDetailReason) {
if (props.navigate) props.navigate(key, reason)
else local.value = key
}
const layout = ref<ListDetailLayout>('stack')
const requests = ref(0)
const saves = ref(0)
const failNext = ref(false)
const fails = () => {
const fail = failNext.value
failNext.value = false
return fail
}
const open = computed(() => messages.value.find((message) => message.id === selected.value))
function shuffle() {
order.value = [...order.value.slice(3), ...order.value.slice(0, 3)].reverse()
}
function archive() {
if (typeof selected.value === 'string') archived.value = [...archived.value, selected.value]
}
</script>
<template>
<MColumn gap="md">
<MRow justify="between" align="end" gap="md" wrap
><MColumn gap="xs"
><MText
:text="t('INBOX / 12', 'CAIXA DE ENTRADA / 12')"
variant="overline"
tone="primary" /><MText
:text="t('Read, reply, come back.', 'Leia, responda, volte.')"
variant="title" /></MColumn
><MRow gap="sm" wrap
><MButton
id="list-detail-shuffle"
:text="t('Reorder', 'Reordenar')"
variant="secondary"
size="sm"
@click="shuffle" /><MButton
id="list-detail-archive"
:text="t('Archive the open one', 'Arquivar a aberta')"
variant="secondary"
size="sm"
:disabled="!open"
@click="archive" /><MButton
id="list-detail-restore"
:text="t('Restore', 'Restaurar')"
variant="ghost"
size="sm"
:disabled="!archived.length"
@click="archived = []" /></MRow
></MRow>
<MSwitch
id="list-detail-fail"
v-model="failNext"
:label="t('Fail the next load', 'Falhar o próximo carregamento')"
/>
<MListDetail
id="list-detail"
:selected="selected"
:label="t('Inbox', 'Caixa de entrada')"
:listLabel="t('Messages', 'Mensagens')"
:detailLabel="t('Message', 'Mensagem')"
:backLabel="t('Back', 'Voltar')"
:height="height"
:breakpoint="breakpoint"
:listWidth="300"
:direction="direction"
@update:selected="change"
@layout="layout = $event"
>
<template #list="{ row, select, selected: current }"
><MColumn padding="xs"
><MListItem
v-for="message in messages"
:key="message.id"
v-bind="row(message.id)"
:title="message.subject"
:description="message.from"
interactive
@click="select(message.id)"
><template v-if="layout === 'split' && current === message.id" #trailing
><MBadge :text="t('Open', 'Aberta')" tone="primary" /></template></MListItem></MColumn
></template>
<template #detail="{ back }"
><ListDetailMessage
:message="open"
:pt="pt"
:fails="fails"
@request="requests++"
@save="saves++"
@back="back"
/></template>
<template #empty
><MColumn padding="lg"
><MEmptyState
:title="t('Pick a message', 'Escolha uma mensagem')"
:description="t('It opens here, next to the list.', 'Ela abre aqui, ao lado da lista.')"
icon="mail"
compact /></MColumn
></template>
</MListDetail>
<MText
id="list-detail-status"
:text="
t(
`Requests ${requests} · Replies sent ${saves} · ${layout === 'split' ? 'side by side' : 'one at a time'}`,
`Pedidos ${requests} · Respostas enviadas ${saves} · ${layout === 'split' ? 'lado a lado' : 'uma de cada vez'}`,
)
"
variant="caption"
tone="muted"
/>
</MColumn>
</template>Recordings
The inbox keeps the same reply draft as the two panes change to a stack. In the compact layout, Back returns to the message list.
Web
iOS Simulator
Android emulator