Skip to content
LIBRARYNavigation

CommandPalette ​

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.

Web preview
Open example ↗
vue
<MCommandPalette v-model:open="open" :items="commands" label="Commands" @select="run" />
PropTypeDefaultDescription
itemsreadonly CommandItem[]requiredCommands with value, label, description, group, keywords, icon, disabled and a display-only shortcut.
open / queryboolean / stringfalse / localControlled presentation and optionally controlled search. A local query resets on close.
shortcut / loading / disabledbooleanfalseOpt-in Cmd/Ctrl+K on Web; loading blocks selection while the application fetches.
label / searchLabel / placeholder / emptyLabel / loadingLabel / closeLabelstringsee sourceLocalizable title, search and state labels.
returnFocusSheetReturnFocuscaptured openerWeb focus destination after closing: element ID (without #), callback or false, inherited from MSheet.

Search ignores accents and matches all space-separated terms against labels, descriptions, groups and keywords. Arrow keys move from search to enabled actions; Home/End work inside results, Enter selects, Escape closes. The Web shortcut is opt-in, ignores editable targets, composition and other dialogs, and is released on unmount. Native uses a Sheet with search and explicit actions. The application executes commands and owns async work; selection closes the palette. Item shortcut strings are hints, not registered hotkeys.

Events: update:open(boolean), update:query(string), select(ChoiceValue, CommandItem).

Motion ​

Opening lets the results arrive in a short cascade below the search field. As the query narrows or widens the list, results that join it arrive in turn, the ones that no longer match fade out and the rest slide into place. A highlight marks the result that acts next: the one with keyboard focus, or, while you type, the first available result that Enter would run. It glides between rows as that changes. When nothing matches, a search icon pops in above the message and gives a small shake each time the query still finds nothing. The status message, the focus order and every accessible name change at once; a row that receives focus while it arrives settles immediately. Reduced motion skips the arrivals and settles the highlight. In forced colors the highlight becomes an outline.

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
import type { CommandItem, ChoiceValue } from '@getcortexlabs/mavis-core'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const t = (en: string, br: string) => ((props.lang ?? locale.value) === 'pt' ? br : en)
const open = ref(false)
const selected = ref<ChoiceValue>('—')
const items = computed<CommandItem[]>(() => [
  {
    value: 'overview',
    label: t('Open overview', 'Abrir visão geral'),
    icon: 'layout-dashboard',
    group: t('Go somewhere', 'Explore'),
    keywords: ['dashboard'],
    shortcut: 'G O',
  },
  {
    value: 'insights',
    label: t('Explore insights', 'Explorar análises'),
    icon: 'chart-no-axes-combined',
    group: t('Go somewhere', 'Explore'),
    description: t('A fresh perspective on your workspace.', 'Um novo olhar para seu espaço.'),
  },
  {
    value: 'invite',
    label: t('Invite a teammate', 'Convidar alguém'),
    icon: 'user-plus',
    group: t('Make something happen', 'Faça acontecer'),
    description: t('Good work starts with good company.', 'Bom trabalho começa com boa companhia.'),
    keywords: ['team', 'equipe'],
    shortcut: 'I',
  },
  {
    value: 'export',
    label: t('Export report', 'Exportar relatório'),
    icon: 'download',
    group: t('Make something happen', 'Faça acontecer'),
    disabled: true,
  },
])
</script>

<template>
  <MCard padding="xl" gap="lg">
    <MRow justify="between" gap="md"
      ><MBadge text="ORBIT / STUDIO" tone="primary" /><MIcon
        name="command"
        :size="32"
        tone="primary"
    /></MRow>
    <MText :text="t('Less searching. More doing.', 'Encontre. Faça. Continue.')" variant="title" />
    <MText
      :text="
        t('Your workspace, one command away.', 'Seu espaço de trabalho a um comando de distância.')
      "
      tone="muted"
    />
    <MButton
      id="command-trigger"
      :accessibilityLabel="`${t('Find an action', 'Encontrar uma ação')} ⌘ K`"
      :text="t('Find an action', 'Encontrar uma ação')"
      icon="search"
      @click="open = true"
      ><template #trailing><MBadge text="⌘ K" /></template
    ></MButton>
    <MText id="command-result" :text="String(selected)" variant="caption" tone="muted" />
  </MCard>
  <MCommandPalette
    v-model:open="open"
    :items="items"
    :label="t('Your next move', 'Seu próximo passo')"
    :searchLabel="t('Search commands', 'Buscar comandos')"
    :placeholder="t('Try invite or insights…', 'Tente convidar ou análises…')"
    :emptyLabel="t('No matching commands', 'Nenhum comando encontrado')"
    :closeLabel="t('Close commands', 'Fechar comandos')"
    shortcut
    returnFocus="command-trigger"
    @select="(key) => (selected = key)"
  />
</template>

Desktop ​

MCommandPalette opens inside the window with the keyboard in its search field, where the arrow keys move the highlighted command and Enter runs it; shortcut opens it with Command-K on the Mac and Control-K on Windows. returnFocus has no effect: the keyboard always returns to the control that had it. See Desktop components.

Components for NativeScript and Web. Starting with Vue.