Skip to content
LIBRARYNavigationUpdated

Tabs ​

MTabs · One space, different perspectives.

Next alpha

Available in 0.1.0-alpha.4.

Web preview
Open example ↗

Usage ​

vue
<script setup lang="ts">
import { ref } from 'vue'
import type { ChoiceValue, TabOption } from '@getcortexlabs/mavis-core'

const active = ref<ChoiceValue | null>('profile')
const tabs: TabOption[] = [
  { value: 'profile', label: 'Profile' },
  { value: 'activity', label: 'Activity' },
  { value: 'upcoming', label: 'Coming soon', disabled: true },
]
</script>

<template>
  <m-tabs v-model="active" :tabs="tabs" label="Your space">
    <template #default="{ value }">
      <m-column v-if="value === 'profile'" gap="md">
        <m-text variant="heading">About you</m-text>
        <m-text>Your profile content.</m-text>
      </m-column>
      <m-text v-else>Recent activity.</m-text>
    </template>
  </m-tabs>
</template>

Props ​

PropTypeDefaultBehavior
modelValuestring | number | nullnullControlled selection. Use v-model and choose the initial value in the app.
tabsreadonly TabOption[]requiredOrdered list of tabs.
labelstringrequiredNonempty group name used by assistive technology.
disabledbooleanfalsePrevents user activation; the parent can still change selection.
keepAlivebooleanfalseRetains visited panels until their tab is removed.
idstring—Container identifier.
widthnumber | % | autoautoContainer width, not individual tab width.
grow / shrinknumber0 / contextParticipation in the parent layout.
accessibilityHiddenbooleanfalseHides the group from assistive technology.

TabOption: { value: string | number; label: string; disabled?: boolean }.

Values must be unique and numbers finite. 0 and '0' are distinct values; nonempty labels can change with the language. Core exports this type and TabPanelProps.

Selection and panels ​

update:modelValue(value) requests a change to a different enabled tab. Repeated activation, scrolling the strip or focusing another tab does not emit a change. The parent can reject the request. There is no automatic selection: initialize the model in the app.

The default slot receives { value } and runs only when that value matches a tab. By default, only that panel is mounted; switching tabs unmounts its predecessor and releases its components/effects. Keep forms, filters and shared data in the parent, as in Library. Panel caching is opt-in, as described below.

null, an empty list or an absent value removes the panel and indicator without changing the model or emitting events. Reinserting the tab restores its panel. Disabling the selected tab retains its current content: disabled limits interaction rather than rewriting the app's decision.

Interaction and motion ​

The strip uses intrinsic widths and horizontal scrolling. Labels stay on one line; external selection reveals the tab without scrolling the page vertically. Resizing and text-size changes reposition the indicator. Dragging the strip only scrolls; it does not switch panels.

Web uses a tablist, tab buttons and a tabpanel named by its active tab. Tab enters one tab stop; arrows, Home and End move focus between enabled tabs. Enter/Space activate. Left/right follow document RTL direction. The panel is keyboard-focusable too.

Native tabs are labelled buttons with selected state and follow system text size. Android supports arrows/Home/End focus navigation and normal button activation. The initial native strip lays out left to right; audited RTL mirroring and iOS hardware-keyboard navigation are not promised.

The indicator travels with Jolt on both renderers: its leading edge reaches the new tab first, the trailing edge follows and settles with the theme's bounce. The new panel enters from the side the selection moved toward (mirrored in RTL); its focusable tabpanel stays still and only an inner wrapper moves, released once it arrives. Tab labels shrink slightly while pressed. Reduced motion places the indicator directly and skips the panel entrance. Unload/unmount releases animations, listeners, pending measurements and observers; retained native pages measure again on return. This is basic behavior, not a comprehensive screen-reader audit.

Tabs organizes local content. Routes, deep links, bottom navigation bars, vertical orientation, arbitrary header slots and swiping between panels are outside this contract.

Full example ​

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
import type { ChoiceValue, TabOption } from '@getcortexlabs/mavis-core'

const { t, locale } = useCatalogLocale(() => props.lang)

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })

const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const { theme } = useMavisTheme()
const active = ref<ChoiceValue | null>('overview')
const tabs = computed<TabOption[]>(() => [
  { value: 'overview', label: pt.value ? 'Visão geral' : 'Overview' },
  { value: 'activity', label: pt.value ? 'Atividade' : 'Activity' },
  { value: 'favorites', label: pt.value ? 'Favoritos' : 'Favorites' },
  { value: 'soon', label: pt.value ? 'Em breve' : 'Coming soon', disabled: true },
])
</script>
<template>
  <m-column gap="lg">
    <m-column padding="lg" gap="md" radius="lg" :backgroundColor="theme.colors.accentSoft">
      <m-row justify="between" gap="sm"
        ><m-text variant="overline" tone="accent">{{
          t(pt ? 'SEU PEQUENO UNIVERSO' : 'YOUR LITTLE UNIVERSE')
        }}</m-text
        ><m-icon name="sparkles" tone="accent"
      /></m-row>
      <m-text variant="title">{{ t(pt ? 'Mude a perspectiva.' : 'A fresh perspective.') }}</m-text>
      <m-text tone="muted">{{
        t(
          pt
            ? 'Histórias, encontros e ideias. Cada coisa tem o seu lugar.'
            : 'Stories, encounters and ideas. Everything has its place.',
        )
      }}</m-text>
    </m-column>
    <m-tabs v-model="active" :tabs="tabs" :label="t(pt ? 'Seu espaço' : 'Your space')">
      <template #default="{ value }">
        <m-column v-if="value === 'overview'" gap="md">
          <m-card gap="md" :backgroundColor="theme.colors.primarySoft">
            <m-row justify="between" gap="sm"
              ><m-text variant="overline" tone="primary">{{
                t(pt ? 'ESTA SEMANA' : 'THIS WEEK')
              }}</m-text
              ><m-icon name="heart" tone="primary"
            /></m-row>
            <m-text variant="display" tone="primary">12</m-text>
            <m-text variant="heading">{{
              t(pt ? 'Ideias que ficaram.' : 'Ideas worth keeping.')
            }}</m-text>
            <m-text tone="muted">{{
              t(
                pt
                  ? 'Pequenas descobertas que merecem uma segunda visita.'
                  : 'Small discoveries that deserve a second look.',
              )
            }}</m-text>
          </m-card>
        </m-column>
        <m-column v-else-if="value === 'activity'" gap="md">
          <m-text variant="heading">{{
            t(pt ? 'Aconteceu por aqui.' : 'Around here lately.')
          }}</m-text>
          <m-card
            v-for="(label, index) in pt
              ? [
                  'Uma nova coleção começou.',
                  'Você guardou uma boa ideia.',
                  'Uma conversa virou inspiração.',
                ]
              : [
                  'A new collection began.',
                  'You saved a good idea.',
                  'A conversation became inspiration.',
                ]"
            :key="index"
            gap="sm"
          >
            <m-text variant="overline" tone="accent">0{{ t(index + 1) }}</m-text>
            <m-text>{{ t(label) }}</m-text>
          </m-card>
        </m-column>
        <m-card v-else gap="lg" :backgroundColor="theme.colors.accentSoft">
          <m-icon name="bookmark" tone="accent" size="lg" />
          <m-text variant="title">{{ t(pt ? 'Para voltar depois.' : 'For another day.') }}</m-text>
          <m-text tone="muted">{{
            t(
              pt
                ? 'Um lugar para as coisas que você quer ter por perto.'
                : 'A home for the things you want to keep close.',
            )
          }}</m-text>
        </m-card>
      </template>
    </m-tabs>
    <m-button variant="ghost" @click="active = 'overview'">{{
      t(pt ? 'Voltar à visão geral' : 'Back to overview')
    }}</m-button>
  </m-column>
</template>

Retaining form state ​

Set keepAlive (boolean, default false) to preserve child component state when switching tabs:

vue
<m-tabs v-model="active" :tabs="tabs" label="Your account" keepAlive>
  <template #default="{ value }"><AccountForm :signup="value === 'signup'" /></template>
</m-tabs>

Only visited panels are created. Inactive content leaves the visible tree and cannot be focused or announced. Vue preserves the instance and calls onDeactivated/onActivated; NativeScript detaches the views and delivers unload/load. The default policy still unmounts the previous panel.

Identity follows value, distinguishing numbers and strings. Reordering or relabelling retains the draft. Removing a tab evicts its cache; reinsertion starts fresh. null or a missing selected value deactivates the panel while retaining caches for listed tabs. Turning keepAlive off or unmounting Tabs discards all caches. Memory is bounded to one panel per listed tab, without preloading unvisited tabs; size the list for the cost of your forms.

Mavis releases press feedback and suspends its hosts/overlays on deactivation. Open modals request programmatic closure; a local Toast queue clears while the application queue remains. App-owned timers, requests and observers need pause/cancellation in onDeactivated, as well as final cleanup in onBeforeUnmount. Vue does not automatically suspend every effect. Motion references are unavailable while their views are detached; reapply imperative scene state in onActivated when needed.

See the independent forms in Morrow and Vue's KeepAlive lifecycle.

Desktop ​

On the desktop the tab list is one tab stop: the left and right arrows, Home and End move the keyboard among the tabs without choosing one, and the system's activation chooses it. With keepAlive, visited panels go through Vue's KeepAlive as on the other hosts: a panel leaves the window with its views and state kept, and onActivated and onDeactivated are called. A shared screen can also use <KeepAlive> itself on the desktop. See Desktop components.

Components for NativeScript and Web. Starting with Vue.