Skip to content

Command

A searchable command palette for quick navigation and actions, with keyboard support and dialog mode.

NameCategoryDescriptionTypeDefault
maxHeight? StyleMaximum list heightstring'300px'
disabled? StateWhether the item is disabledbooleanfalse
modelValue / v-model? StateWhether the dialog is openbooleanfalse
filter? BehaviorCustom filter function(value: string, search: string, keywords?: string[]) => boolean
shortcut? BehaviorEnable Ctrl+K keyboard shortcutbooleantrue
ArrowDown? BehaviorHighlight next item
ArrowUp? BehaviorHighlight previous item
Enter? BehaviorSelect highlighted item
Escape? BehaviorClose dialog
Ctrl+K / Cmd+K? BehaviorToggle command dialog
modelValue / v-model? ContentSearch textstring''
label? ContentAria label for accessibilitystring
placeholder? ContentInput placeholder textstring''
icon? ContentSearch icon namestring'search'
value? ContentUnique item value (required)string
keywords? ContentAdditional search keywordsstring[][]
icon? ContentItem iconstring
shortcut? ContentShortcut key labelsstring[][]
heading? ContentGroup heading textstring
update:modelValue? EventEmitted when search text changes(value: string) => void
select? EventEmitted when an item is selected(value: string) => void
update:modelValue? EventEmitted when dialog state changes(value: boolean) => void
open? EventEmitted when dialog opens() => void
close? EventEmitted when dialog closes() => void

Basic Usage

A simple command menu with search filtering.

<template>
  <px-command label="Command menu">
    <px-command-input placeholder="Type a command or search..." />
    <px-command-list>
      <px-command-empty>No results found.</px-command-empty>
      <px-command-item value="calendar" icon="calendar">Calendar</px-command-item>
      <px-command-item value="search" icon="search">Search</px-command-item>
      <px-command-item value="settings" icon="settings">Settings</px-command-item>
      <px-command-item value="profile" icon="user">Profile</px-command-item>
    </px-command-list>
  </px-command>
</template>

<style scoped>
.px-command {
  max-width: 480px;
}
</style>

Grouped Items

Use CommandGroup to organize items with headings and CommandSeparator for visual dividers.

<template>
  <px-command label="Grouped command menu">
    <px-command-input placeholder="Search commands..." />
    <px-command-list>
      <px-command-empty>No results found.</px-command-empty>
      <px-command-group heading="Navigation">
        <px-command-item value="home" icon="home">Home</px-command-item>
        <px-command-item value="dashboard" icon="analytics">Dashboard</px-command-item>
        <px-command-item value="settings" icon="settings">Settings</px-command-item>
      </px-command-group>
      <px-command-separator />
      <px-command-group heading="Actions">
        <px-command-item value="new-file" icon="add-box">New File</px-command-item>
        <px-command-item value="upload" icon="upload">Upload</px-command-item>
        <px-command-item value="download" icon="download">Download</px-command-item>
      </px-command-group>
    </px-command-list>
  </px-command>
</template>

<style scoped>
.px-command {
  max-width: 480px;
}
</style>

Dialog Mode

Use CommandDialog to show the command palette in a modal overlay. Press Ctrl+K (or Cmd+K on Mac) to toggle.

<template>
  <div>
    <px-button type="primary" @click="open = true">
      Open Command Palette
      <px-badge size="small" type="info">Ctrl+K</px-badge>
    </px-button>

    <px-command-dialog v-model="open">
      <px-command @select="onSelect" label="Command palette">
        <px-command-input placeholder="What do you need?" />
        <px-command-list>
          <px-command-empty>No results found.</px-command-empty>
          <px-command-group heading="Pages">
            <px-command-item value="home" icon="home" :shortcut="['Ctrl', 'H']">Home</px-command-item>
            <px-command-item value="docs" icon="bookmark" :shortcut="['Ctrl', 'D']">Documentation</px-command-item>
          </px-command-group>
          <px-command-separator />
          <px-command-group heading="Theme">
            <px-command-item value="light" icon="sun">Light Mode</px-command-item>
            <px-command-item value="dark" icon="moon">Dark Mode</px-command-item>
          </px-command-group>
        </px-command-list>
      </px-command>
    </px-command-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const open = ref(false);

function onSelect() {
  open.value = false;
}
</script>

Custom Filter

Provide a custom filter function for advanced matching (e.g., fuzzy search).

<template>
  <px-command :filter="fuzzyFilter" label="Custom filter">
    <px-command-input placeholder="Try fuzzy search..." />
    <px-command-list>
      <px-command-empty>No matches.</px-command-empty>
      <px-command-item value="calendar">Calendar</px-command-item>
      <px-command-item value="calculator">Calculator</px-command-item>
      <px-command-item value="contacts">Contacts</px-command-item>
      <px-command-item value="configuration">Configuration</px-command-item>
    </px-command-list>
  </px-command>
</template>

<script setup lang="ts">
function fuzzyFilter(value: string, search: string): boolean {
  if (!search) return true;
  const chars = search.toLowerCase().split('');
  let idx = 0;
  for (const char of value.toLowerCase()) {
    if (char === chars[idx]) idx++;
    if (idx === chars.length) return true;
  }
  return false;
}
</script>

<style scoped>
.px-command {
  max-width: 480px;
}
</style>

Disabled Items

Set disabled on items to prevent selection. Disabled items are skipped during keyboard navigation.

<template>
  <px-command label="Command with disabled items">
    <px-command-input placeholder="Search..." />
    <px-command-list>
      <px-command-item value="save" icon="check">Save</px-command-item>
      <px-command-item value="delete" icon="close" disabled>Delete (Disabled)</px-command-item>
      <px-command-item value="export" icon="download">Export</px-command-item>
      <px-command-item value="archive" icon="archive" disabled>Archive (Disabled)</px-command-item>
    </px-command-list>
  </px-command>
</template>

<style scoped>
.px-command {
  max-width: 480px;
}
</style>