CommandPalette

A command palette with full-text search powered by Fuse.js for efficient fuzzy matching.

Usage

Use the v-model directive to control the value of the CommandPalette or the default-value prop to set the initial value when you do not need to control its state.

<script setup lang="ts">
const groups = ref([
  {
    id: 'users',
    label: 'Users',
    items: [
      {
        label: 'praburangki',
        suffix: 'praburangki',
        avatar: {
          src: 'https://github.com/praburangki.png'
        }
      },
      {
        label: 'Wahyu Ivan',
        suffix: 'wahyu-ivan',
        avatar: {
          src: 'https://github.com/wahyu-ivan.png'
        }
      },
      {
        label: 'Sébastien Chopin',
        suffix: 'atinux',
        avatar: {
          src: 'https://github.com/atinux.png'
        }
      },
      {
        label: 'Hugo Richard',
        suffix: 'HugoRCD',
        avatar: {
          src: 'https://github.com/HugoRCD.png'
        }
      },
      {
        label: 'Sandro Circi',
        suffix: 'sandros94',
        avatar: {
          src: 'https://github.com/sandros94.png'
        }
      },
      {
        label: 'Daniel Roe',
        suffix: 'danielroe',
        avatar: {
          src: 'https://github.com/danielroe.png'
        }
      },
      {
        label: 'Jakub Michálek',
        suffix: 'J-Michalek',
        avatar: {
          src: 'https://github.com/J-Michalek.png'
        }
      },
      {
        label: 'Eugen Istoc',
        suffix: 'genu',
        avatar: {
          src: 'https://github.com/genu.png'
        }
      }
    ]
  }
])
const value = ref({})
</script>

<template>
  <PCommandPalette v-model="value" :groups="groups" class="flex-1 h-80" />
</template>
You can also use the @update:model-value event to listen to the selected item(s).

Groups

The CommandPalette component filters groups and ranks matching commands by relevance as users type. It provides dynamic, instant search results for efficient command discovery. Use the groups prop as an array of objects with the following properties:

You must provide an id for each group otherwise the group will be ignored.

Each group contains an items array of objects that define the commands. Each item can have the following properties:

  • prefix?: string
  • label?: string
  • suffix?: string
  • icon?: string
  • avatar?: AvatarProps
  • chip?: ChipProps
  • kbds?: string[] | KbdProps[]
  • active?: boolean
  • loading?: boolean
  • disabled?: boolean
  • slot?: string
  • placeholder?: string
  • children?: PCommandPaletteItem[]
  • onSelect?: (e: Event) => void
  • class?: any
  • pohon?: { item?: ClassNameValue, itemLeadingIcon?: ClassNameValue, itemLeadingAvatarSize?: ClassNameValue, itemLeadingAvatar?: ClassNameValue, itemLeadingChipSize?: ClassNameValue, itemLeadingChip?: ClassNameValue, itemLabel?: ClassNameValue, itemLabelPrefix?: ClassNameValue, itemLabelBase?: ClassNameValue, itemLabelSuffix?: ClassNameValue, itemTrailing?: ClassNameValue, itemTrailingKbds?: ClassNameValue, itemTrailingKbdsSize?: ClassNameValue, itemTrailingHighlightedIcon?: ClassNameValue, itemTrailingIcon?: ClassNameValue }

You can pass any property from the Link component such as to, target, etc.

<script setup lang="ts">
const groups = ref([
  {
    id: 'users',
    label: 'Users',
    items: [
      {
        label: 'praburangki',
        suffix: 'praburangki',
        avatar: {
          src: 'https://github.com/praburangki.png'
        }
      },
      {
        label: 'Wahyu Ivan',
        suffix: 'wahyu-ivan',
        avatar: {
          src: 'https://github.com/wahyu-ivan.png'
        }
      },
      {
        label: 'Sébastien Chopin',
        suffix: 'atinux',
        avatar: {
          src: 'https://github.com/atinux.png'
        }
      },
      {
        label: 'Hugo Richard',
        suffix: 'HugoRCD',
        avatar: {
          src: 'https://github.com/HugoRCD.png'
        }
      },
      {
        label: 'Sandro Circi',
        suffix: 'sandros94',
        avatar: {
          src: 'https://github.com/sandros94.png'
        }
      },
      {
        label: 'Daniel Roe',
        suffix: 'danielroe',
        avatar: {
          src: 'https://github.com/danielroe.png'
        }
      },
      {
        label: 'Jakub Michálek',
        suffix: 'J-Michalek',
        avatar: {
          src: 'https://github.com/J-Michalek.png'
        }
      },
      {
        label: 'Eugen Istoc',
        suffix: 'genu',
        avatar: {
          src: 'https://github.com/genu.png'
        }
      }
    ]
  }
])
const value = ref({})
</script>

<template>
  <PCommandPalette v-model="value" :groups="groups" class="flex-1" />
</template>
Each item can take a children array of objects with the following properties to create submenus:

Multiple

Use the multiple prop to allow multiple selections.

<script setup lang="ts">
const groups = ref([
  {
    id: 'users',
    label: 'Users',
    items: [
      {
        label: 'praburangki',
        suffix: 'praburangki',
        avatar: {
          src: 'https://github.com/praburangki.png'
        }
      },
      {
        label: 'Wahyu Ivan',
        suffix: 'wahyu-ivan',
        avatar: {
          src: 'https://github.com/wahyu-ivan.png'
        }
      },
      {
        label: 'Sébastien Chopin',
        suffix: 'atinux',
        avatar: {
          src: 'https://github.com/atinux.png'
        }
      },
      {
        label: 'Hugo Richard',
        suffix: 'HugoRCD',
        avatar: {
          src: 'https://github.com/HugoRCD.png'
        }
      },
      {
        label: 'Sandro Circi',
        suffix: 'sandros94',
        avatar: {
          src: 'https://github.com/sandros94.png'
        }
      },
      {
        label: 'Daniel Roe',
        suffix: 'danielroe',
        avatar: {
          src: 'https://github.com/danielroe.png'
        }
      },
      {
        label: 'Jakub Michálek',
        suffix: 'J-Michalek',
        avatar: {
          src: 'https://github.com/J-Michalek.png'
        }
      },
      {
        label: 'Eugen Istoc',
        suffix: 'genu',
        avatar: {
          src: 'https://github.com/genu.png'
        }
      }
    ]
  }
])
const value = ref([])
</script>

<template>
  <PCommandPalette multiple v-model="value" :groups="groups" class="flex-1" />
</template>
Ensure to pass an array to the default-value prop or the v-model directive.

Placeholder

Use the placeholder prop to change the placeholder text.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette placeholder="Search an app..." :groups="groups" class="flex-1" />
</template>

Icon

Use the icon prop to customize the input Icon. Defaults to i-lucide:search.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette icon="i-lucide:box" :groups="groups" class="flex-1" />
</template>
You can customize this icon globally in your app.config.ts under pohon.icons.search key.
You can customize this icon globally in your vite.config.ts under pohon.icons.search key.

Selected Icon

Use the selected-icon prop to customize the selected item Icon. Defaults to i-lucide:check.

<script setup lang="ts">
const groups = ref([
  {
    id: 'users',
    label: 'Users',
    items: [
      {
        label: 'praburangki',
        suffix: 'praburangki',
        avatar: {
          src: 'https://github.com/praburangki.png'
        }
      },
      {
        label: 'Wahyu Ivan',
        suffix: 'wahyu-ivan',
        avatar: {
          src: 'https://github.com/wahyu-ivan.png'
        }
      },
      {
        label: 'Sébastien Chopin',
        suffix: 'atinux',
        avatar: {
          src: 'https://github.com/atinux.png'
        }
      },
      {
        label: 'Hugo Richard',
        suffix: 'HugoRCD',
        avatar: {
          src: 'https://github.com/HugoRCD.png'
        }
      },
      {
        label: 'Sandro Circi',
        suffix: 'sandros94',
        avatar: {
          src: 'https://github.com/sandros94.png'
        }
      },
      {
        label: 'Daniel Roe',
        suffix: 'danielroe',
        avatar: {
          src: 'https://github.com/danielroe.png'
        }
      },
      {
        label: 'Jakub Michálek',
        suffix: 'J-Michalek',
        avatar: {
          src: 'https://github.com/J-Michalek.png'
        }
      },
      {
        label: 'Eugen Istoc',
        suffix: 'genu',
        avatar: {
          src: 'https://github.com/genu.png'
        }
      }
    ]
  }
])
const value = ref([
  {
    label: 'praburangki',
    suffix: 'praburangki',
    avatar: {
      src: 'https://github.com/praburangki.png'
    }
  }
])
</script>

<template>
  <PCommandPalette multiple v-model="value" selected-icon="i-lucide:circle-check" :groups="groups" class="flex-1" />
</template>
You can customize this icon globally in your app.config.ts under pohon.icons.check key.
You can customize this icon globally in your vite.config.ts under pohon.icons.check key.

Trailing Icon

Use the trailing-icon prop to customize the trailing Icon when an item has children. Defaults to i-lucide:chevron-right.

<script setup lang="ts">
const groups = ref([
  {
    id: 'actions',
    items: [
      {
        label: 'Share',
        icon: 'i-lucide:share',
        children: [
          {
            label: 'Email',
            icon: 'i-lucide:mail'
          },
          {
            label: 'Copy',
            icon: 'i-lucide:copy'
          },
          {
            label: 'Link',
            icon: 'i-lucide:link'
          }
        ]
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette trailing-icon="i-lucide:arrow-right" :groups="groups" class="flex-1" />
</template>
You can customize this icon globally in your app.config.ts under pohon.icons.chevronRight key.
You can customize this icon globally in your vite.config.ts under pohon.icons.chevronRight key.

Loading

Use the loading prop to show a loading icon on the CommandPalette.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette loading :groups="groups" class="flex-1" />
</template>

Loading Icon

Use the loading-icon prop to customize the loading icon. Defaults to i-lucide:loader-circle.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette loading loading-icon="i-lucide:loader" :groups="groups" class="flex-1" />
</template>
You can customize this icon globally in your app.config.ts under pohon.icons.loading key.
You can customize this icon globally in your vite.config.ts under pohon.icons.loading key.

Close

Use the close prop to display a Button to dismiss the CommandPalette.

An update:open event will be emitted when the close button is clicked.
<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette close :groups="groups" class="flex-1" />
</template>

You can pass any property from the Button component to customize it.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette
    :close="{
      color: 'primary',
      variant: 'outline',
      class: 'rounded-full'
    }"
    :groups="groups"
    class="flex-1"
  />
</template>

Close Icon

Use the close-icon prop to customize the close button Icon. Defaults to i-lucide:x.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette close close-icon="i-lucide:arrow-right" :groups="groups" class="flex-1" />
</template>
You can customize this icon globally in your app.config.ts under pohon.icons.close key.
You can customize this icon globally in your vite.config.ts under pohon.icons.close key.

Back

Use the back prop to customize or hide the back button (with false value) displayed when navigating into a submenu.

You can pass any property from the Button component to customize it.

<script setup lang="ts">
const groups = ref([
  {
    id: 'actions',
    items: [
      {
        label: 'Share',
        icon: 'i-lucide:share',
        children: [
          {
            label: 'Email',
            icon: 'i-lucide:mail'
          },
          {
            label: 'Copy',
            icon: 'i-lucide:copy'
          },
          {
            label: 'Link',
            icon: 'i-lucide:link'
          }
        ]
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette
    :back="{
      color: 'primary'
    }"
    :groups="groups"
    class="flex-1"
  />
</template>

Back Icon

Use the back-icon prop to customize the back button Icon. Defaults to i-lucide:arrow-left.

<script setup lang="ts">
const groups = ref([
  {
    id: 'actions',
    items: [
      {
        label: 'Share',
        icon: 'i-lucide:share',
        children: [
          {
            label: 'Email',
            icon: 'i-lucide:mail'
          },
          {
            label: 'Copy',
            icon: 'i-lucide:copy'
          },
          {
            label: 'Link',
            icon: 'i-lucide:link'
          }
        ]
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette back back-icon="i-lucide:house" :groups="groups" class="flex-1" />
</template>
You can customize this icon globally in your app.config.ts under pohon.icons.arrowLeft key.
You can customize this icon globally in your vite.config.ts under pohon.icons.arrowLeft key.

Disabled

Use the disabled prop to disable the CommandPalette.

<script setup lang="ts">
const groups = ref([
  {
    id: 'apps',
    items: [
      {
        label: 'Calendar',
        icon: 'i-lucide:calendar'
      },
      {
        label: 'Music',
        icon: 'i-lucide:music'
      },
      {
        label: 'Maps',
        icon: 'i-lucide:map'
      }
    ]
  }
])
</script>

<template>
  <PCommandPalette disabled :groups="groups" class="flex-1" />
</template>

Examples

Control selected item(s)

You can control the selected item(s) by using the default-value prop or the v-model directive, by using the onSelect field on each item or by using the @update:model-value event.

<script setup lang="ts">
import { ref, useToast } from '#imports';

const toast = useToast();

const groups = ref([
  {
    id: 'users',
    label: 'Users',
    items: [
      {
        label: 'praburangki',
        suffix: 'praburangki',
        to: 'https://github.com/praburangki',
        target: '_blank',
        avatar: {
          src: 'https://github.com/praburangki.png',
        },
      },
      {
        label: 'Wahyu Ivan',
        suffix: 'wahyu-ivan',
        to: 'https://github.com/wahyu-ivan',
        target: '_blank',
        avatar: {
          src: 'https://github.com/wahyu-ivan.png',
        },
      },
      {
        label: 'Sébastien Chopin',
        suffix: 'atinux',
        to: 'https://github.com/atinux',
        target: '_blank',
        avatar: {
          src: 'https://github.com/atinux.png',
        },
      },
      {
        label: 'Hugo Richard',
        suffix: 'HugoRCD',
        to: 'https://github.com/HugoRCD',
        target: '_blank',
        avatar: {
          src: 'https://github.com/HugoRCD.png',
        },
      },
      {
        label: 'Sandro Circi',
        suffix: 'sandros94',
        to: 'https://github.com/sandros94',
        target: '_blank',
        avatar: {
          src: 'https://github.com/sandros94.png',
        },
      },
      {
        label: 'Daniel Roe',
        suffix: 'danielroe',
        to: 'https://github.com/danielroe',
        target: '_blank',
        avatar: {
          src: 'https://github.com/danielroe.png',
        },
      },
      {
        label: 'Jakub Michálek',
        suffix: 'J-Michalek',
        to: 'https://github.com/J-Michalek',
        target: '_blank',
        avatar: {
          src: 'https://github.com/J-Michalek.png',
        },
      },
      {
        label: 'Eugen Istoc',
        suffix: 'genu',
        to: 'https://github.com/genu',
        target: '_blank',
        avatar: {
          src: 'https://github.com/genu.png',
        },
      },
    ],
  },
  {
    id: 'actions',
    items: [
      {
        label: 'Add new file',
        suffix: 'Create a new file in the current directory or workspace.',
        icon: 'i-lucide:file-plus',
        kbds: [
          'meta',
          'N',
        ],
        onSelect() {
          toast.add({ title: 'Add new file' });
        },
      },
      {
        label: 'Add new folder',
        suffix: 'Create a new folder in the current directory or workspace.',
        icon: 'i-lucide:folder-plus',
        kbds: [
          'meta',
          'F',
        ],
        onSelect() {
          toast.add({ title: 'Add new folder' });
        },
      },
      {
        label: 'Add hashtag',
        suffix: 'Add a hashtag to the current item.',
        icon: 'i-lucide:hash',
        kbds: [
          'meta',
          'H',
        ],
        onSelect() {
          toast.add({ title: 'Add hashtag' });
        },
      },
      {
        label: 'Add label',
        suffix: 'Add a label to the current item.',
        icon: 'i-lucide:tag',
        kbds: [
          'meta',
          'L',
        ],
        onSelect() {
          toast.add({ title: 'Add label' });
        },
      },
    ],
  },
]);

function onSelect(item: any) {
  console.log(item);
}
</script>

<template>
  <PCommandPalette
    :groups="groups"
    class="flex-1 h-80"
    @update:model-value="onSelect"
  />
</template>

Control search term

Use the v-model:search-term directive to control the search term.

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

const users = [
  {
    label: 'praburangki',
    suffix: 'praburangki',
    to: 'https://github.com/praburangki',
    target: '_blank',
    avatar: {
      src: 'https://github.com/praburangki.png',
    },
  },
  {
    label: 'Wahyu Ivan',
    suffix: 'wahyu-ivan',
    to: 'https://github.com/wahyu-ivan',
    target: '_blank',
    avatar: {
      src: 'https://github.com/wahyu-ivan.png',
    },
  },
  {
    label: 'Sébastien Chopin',
    suffix: 'atinux',
    to: 'https://github.com/atinux',
    target: '_blank',
    avatar: {
      src: 'https://github.com/atinux.png',
    },
  },
  {
    label: 'Hugo Richard',
    suffix: 'HugoRCD',
    to: 'https://github.com/HugoRCD',
    target: '_blank',
    avatar: {
      src: 'https://github.com/HugoRCD.png',
    },
  },
  {
    label: 'Sandro Circi',
    suffix: 'sandros94',
    to: 'https://github.com/sandros94',
    target: '_blank',
    avatar: {
      src: 'https://github.com/sandros94.png',
    },
  },
  {
    label: 'Daniel Roe',
    suffix: 'danielroe',
    to: 'https://github.com/danielroe',
    target: '_blank',
    avatar: {
      src: 'https://github.com/danielroe.png',
    },
  },
  {
    label: 'Jakub Michálek',
    suffix: 'J-Michalek',
    to: 'https://github.com/J-Michalek',
    target: '_blank',
    avatar: {
      src: 'https://github.com/J-Michalek.png',
    },
  },
  {
    label: 'Eugen Istoc',
    suffix: 'genu',
    to: 'https://github.com/genu',
    target: '_blank',
    avatar: {
      src: 'https://github.com/genu.png',
    },
  },
];

const searchTerm = ref('B');

function onSelect() {
  searchTerm.value = '';
}
</script>

<template>
  <PCommandPalette
    v-model:search-term="searchTerm"
    :groups="[{ id: 'users', items: users }]"
    class="flex-1"
    @update:model-value="onSelect"
  />
</template>
This example uses the @update:model-value event to reset the search term when an item is selected.

With children in items

You can create hierarchical menus by using the children property in items. When an item has children, it will automatically display a chevron icon and enable navigation into a submenu.

<script setup lang="ts">
import { useToast } from '#imports'

const toast = useToast()

const groups = [
  {
    id: 'actions',
    label: 'Actions',
    items: [
      {
        label: 'Create new',
        icon: 'i-lucide:plus',
        children: [
          {
            label: 'New file',
            icon: 'i-lucide:file-plus',
            suffix: 'Create a new file in the current directory',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'New file created!' })
            },
            kbds: ['meta', 'N']
          },
          {
            label: 'New folder',
            icon: 'i-lucide:folder-plus',
            suffix: 'Create a new folder in the current directory',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'New folder created!' })
            },
            kbds: ['meta', 'F']
          },
          {
            label: 'New project',
            icon: 'i-lucide:folder-git',
            suffix: 'Create a new project from a template',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'New project created!' })
            },
            kbds: ['meta', 'P']
          }
        ]
      },
      {
        label: 'Share',
        icon: 'i-lucide:share',
        children: [
          {
            label: 'Copy link',
            icon: 'i-lucide:link',
            suffix: 'Copy a link to the current item',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'Link copied to clipboard!' })
            },
            kbds: ['meta', 'L']
          },
          {
            label: 'Share via email',
            icon: 'i-lucide:mail',
            suffix: 'Share the current item via email',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'Share via email dialog opened!' })
            }
          },
          {
            label: 'Share on social',
            icon: 'i-lucide:share-2',
            suffix: 'Share the current item on social media',
            children: [
              {
                label: 'Twitter',
                icon: 'i-simple-icons:twitter',
                onSelect(e: Event) {
                  e.preventDefault()
                  toast.add({ title: 'Shared on Twitter!' })
                }
              },
              {
                label: 'LinkedIn',
                icon: 'i-simple-icons:linkedin',
                onSelect(e: Event) {
                  e.preventDefault()
                  toast.add({ title: 'Shared on LinkedIn!' })
                }
              },
              {
                label: 'Facebook',
                icon: 'i-simple-icons:facebook',
                onSelect(e: Event) {
                  e.preventDefault()
                  toast.add({ title: 'Shared on Facebook!' })
                }
              }
            ]
          }
        ]
      },
      {
        label: 'Settings',
        icon: 'i-lucide:settings',
        children: [
          {
            label: 'General',
            icon: 'i-lucide:sliders',
            suffix: 'Configure general settings',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'General settings opened!' })
            }
          },
          {
            label: 'Appearance',
            icon: 'i-lucide:palette',
            suffix: 'Customize the appearance',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'Appearance settings opened!' })
            }
          },
          {
            label: 'Security',
            icon: 'i-lucide:shield',
            suffix: 'Manage security settings',
            onSelect(e: Event) {
              e.preventDefault()
              toast.add({ title: 'Security settings opened!' })
            }
          }
        ]
      }
    ]
  }
]
</script>

<template>
  <PCommandPalette :groups="groups" class="flex-1" />
</template>
When navigating into a submenu:
  • The search term is reset
  • A back button appears in the input
  • You can go back to the previous group by pressing the key

With fetched items

You can fetch items from an API and use them in the CommandPalette.

No data
<script setup lang="ts">
import { useFetch } from '#app';
import { computed, ref } from 'vue';

const searchTerm = ref('');

const { data: users, status } = await useFetch('https://jsonplaceholder.typicode.com/users', {
  key: 'command-palette-users',
  transform: (data: Array<{ id: number; name: string; email: string }>) => {
    return data?.map((user) => ({ id: user.id, label: user.name, suffix: user.email, avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` } })) || [];
  },
  lazy: true,
});

const groups = computed(() => [{
  id: 'users',
  label: searchTerm.value ? `Users matching “${searchTerm.value}”...` : 'Users',
  items: users.value || [],
}]);
</script>

<template>
  <PCommandPalette
    v-model:search-term="searchTerm"
    :loading="status === 'pending'"
    :groups="groups"
    class="flex-1 h-80"
  />
</template>

With ignore filter

You can set the ignoreFilter field to true on a group to disable the internal search and use your own search logic.

<script setup lang="ts">
import { useFetch } from '#app';
import { refDebounced } from '@vueuse/core';
import { computed, ref } from 'vue';

const searchTerm = ref('');
const searchTermDebounced = refDebounced(searchTerm, 200);

const { data: users, status } = await useFetch('https://jsonplaceholder.typicode.com/users', {
  params: { q: searchTermDebounced },
  transform: (data: Array<{ id: number; name: string; email: string }>) => {
    return data?.map((user) => ({ id: user.id, label: user.name, suffix: user.email, avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` } })) || [];
  },
  lazy: true,
});

const groups = computed(() => [{
  id: 'users',
  label: searchTerm.value ? `Users matching “${searchTerm.value}”...` : 'Users',
  items: users.value || [],
  ignoreFilter: true,
}]);
</script>

<template>
  <PCommandPalette
    v-model:search-term="searchTerm"
    :loading="status === 'pending'"
    :groups="groups"
    class="flex-1 h-80"
  />
</template>
This example uses refDebounced to debounce the API calls.

With post-filtered items

You can use the postFilter field on a group to filter items after the search happened.

<script setup lang="ts">
const items = [
  {
    id: '/',
    label: 'Introduction',
    level: 1,
  },
  {
    id: '/docs/pohon/getting-started',
    label: 'Getting Started',
    level: 2,
  },
  {
    id: '/docs/pohon/getting-started#akar',
    label: 'Akar',
    level: 3,
  },
  {
    id: '/docs/pohon/getting-started#unocss-variants',
    label: 'UnoCSS Variants',
    level: 3,
  },
  {
    id: '/docs/pohon/getting-started/installation',
    label: 'Installation',
    level: 1,
  },
];

function postFilter(searchTerm: string, items: Array<any>) {
  // Filter only first level items if no searchTerm
  if (!searchTerm) {
    return items?.filter((item) => item.level === 1);
  }

  return items;
}
</script>

<template>
  <PCommandPalette
    :groups="[{ id: 'files', items, postFilter }]"
    class="flex-1"
  />
</template>
Start typing to see items with higher level appear.

You can use the fuse prop to override the options of useFuse which defaults to:

{
  fuseOptions: {
    ignoreLocation: true,
    threshold: 0.1,
    keys: ['label', 'suffix']
  },
  resultLimit: 12,
  matchAllWhenSearchEmpty: true
}
The fuseOptions are the options of Fuse.js, the resultLimit is the maximum number of results to return and the matchAllWhenSearchEmpty is a boolean to match all items when the search term is empty.

You can for example set { fuseOptions: { includeMatches: true } } to highlight the search term in the items.

No data
<script setup lang="ts">
import { useFetch } from '#app';

const { data: users } = await useFetch('https://jsonplaceholder.typicode.com/users', {
  key: 'command-palette-users',
  transform: (data: Array<{ id: number; name: string; email: string }>) => {
    return data?.map((user) => ({ id: user.id, label: user.name, suffix: user.email, avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` } })) || [];
  },
  lazy: true,
});
</script>

<template>
  <PCommandPalette
    :groups="[{ id: 'users', items: users || [] }]"
    :fuse="{ fuseOptions: { includeMatches: true } }"
    class="flex-1 h-80"
  />
</template>

With virtualization

Use the virtualize prop to enable virtualization for large lists as a boolean or an object with options like { estimateSize: 32, overscan: 12 }. When enabled, all groups are flattened into a single list due to a limitation of Akar.

<script setup lang="ts">
import type { PCommandPaletteItem } from 'pohon-ui';

const items: Array<PCommandPaletteItem> = Array(1000)
  .fill(0)
  .map((_, value) => ({
    label: `item-${value}`,
    value,
  }));

const groups = [
  {
    id: 'items',
    items,
  },
];
</script>

<template>
  <PCommandPalette
    virtualize
    :fuse="{ resultLimit: 1000 }"
    :groups="groups"
    class="flex-1 h-80"
  />
</template>

Within a Popover

You can use the CommandPalette component inside a Popover's content.

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

const items = ref([
  {
    label: 'bug',
    value: 'bug',
    chip: {
      color: 'error' as const,
    },
  },
  {
    label: 'feature',
    value: 'feature',
    chip: {
      color: 'success' as const,
    },
  },
  {
    label: 'enhancement',
    value: 'enhancement',
    chip: {
      color: 'info' as const,
    },
  },
]);
const label = ref([]);
</script>

<template>
  <PPopover :content="{ side: 'right', align: 'start' }">
    <PButton
      icon="i-lucide:tag"
      label="Select labels"
      color="neutral"
      variant="subtle"
    />

    <template #content>
      <PCommandPalette
        v-model="label"
        multiple
        placeholder="Search labels..."
        :groups="[{ id: 'labels', items }]"
        :pohon="{ input: '[&>input]:h-8 [&>input]:text-sm' }"
      />
    </template>
  </PPopover>
</template>

Within a Modal

You can use the CommandPalette component inside a Modal's content.

<script setup lang="ts">
import { useFetch } from '#app';
import { computed, ref } from 'vue';

const searchTerm = ref('');

const { data: users, status } = await useFetch('https://jsonplaceholder.typicode.com/users', {
  key: 'command-palette-users',
  params: { q: searchTerm },
  transform: (data: Array<{ id: number; name: string; email: string }>) => {
    return data?.map((user) => ({ id: user.id, label: user.name, suffix: user.email, avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` } })) || [];
  },
  lazy: true,
});

const groups = computed(() => [{
  id: 'users',
  label: searchTerm.value ? `Users matching “${searchTerm.value}”...` : 'Users',
  items: users.value || [],
  ignoreFilter: true,
}]);
</script>

<template>
  <PDialog>
    <PButton
      label="Search users..."
      color="neutral"
      variant="subtle"
      icon="i-lucide:search"
    />

    <template #content>
      <PCommandPalette
        v-model:search-term="searchTerm"
        :loading="status === 'pending'"
        :groups="groups"
        placeholder="Search users..."
        class="h-80"
      />
    </template>
  </PDialog>
</template>

Within a Drawer

You can use the CommandPalette component inside a Drawer's content.

<script setup lang="ts">
import { useFetch } from '#app';
import { computed, ref } from 'vue';

const searchTerm = ref('');

const { data: users, status } = await useFetch('https://jsonplaceholder.typicode.com/users', {
  key: 'command-palette-users',
  params: { q: searchTerm },
  transform: (data: Array<{ id: number; name: string; email: string }>) => {
    return data?.map((user) => ({ id: user.id, label: user.name, suffix: user.email, avatar: { src: `https://i.pravatar.cc/120?img=${user.id}` } })) || [];
  },
  lazy: true,
});

const groups = computed(() => [{
  id: 'users',
  label: searchTerm.value ? `Users matching “${searchTerm.value}”...` : 'Users',
  items: users.value || [],
  ignoreFilter: true,
}]);
</script>

<template>
  <PDrawer :handle="false">
    <PButton
      label="Search users..."
      color="neutral"
      variant="subtle"
      icon="i-lucide:search"
    />

    <template #content>
      <PCommandPalette
        v-model:search-term="searchTerm"
        :loading="status === 'pending'"
        :groups="groups"
        placeholder="Search users..."
        class="h-80"
      />
    </template>
  </PDrawer>
</template>

Listen open state

When using the close prop, you can listen to the update:open event when the button is clicked.

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

const open = ref(false);

const users = [
  {
    label: 'praburangki',
    suffix: 'praburangki',
    to: 'https://github.com/praburangki',
    target: '_blank',
    avatar: {
      src: 'https://github.com/praburangki.png',
    },
  },
  {
    label: 'Wahyu Ivan',
    suffix: 'wahyu-ivan',
    to: 'https://github.com/wahyu-ivan',
    target: '_blank',
    avatar: {
      src: 'https://github.com/wahyu-ivan.png',
    },
  },
  {
    label: 'Sébastien Chopin',
    suffix: 'atinux',
    to: 'https://github.com/atinux',
    target: '_blank',
    avatar: {
      src: 'https://github.com/atinux.png',
    },
  },
  {
    label: 'Hugo Richard',
    suffix: 'HugoRCD',
    to: 'https://github.com/HugoRCD',
    target: '_blank',
    avatar: {
      src: 'https://github.com/HugoRCD.png',
    },
  },
  {
    label: 'Sandro Circi',
    suffix: 'sandros94',
    to: 'https://github.com/sandros94',
    target: '_blank',
    avatar: {
      src: 'https://github.com/sandros94.png',
    },
  },
  {
    label: 'Daniel Roe',
    suffix: 'danielroe',
    to: 'https://github.com/danielroe',
    target: '_blank',
    avatar: {
      src: 'https://github.com/danielroe.png',
    },
  },
  {
    label: 'Jakub Michálek',
    suffix: 'J-Michalek',
    to: 'https://github.com/J-Michalek',
    target: '_blank',
    avatar: {
      src: 'https://github.com/J-Michalek.png',
    },
  },
  {
    label: 'Eugen Istoc',
    suffix: 'genu',
    to: 'https://github.com/genu',
    target: '_blank',
    avatar: {
      src: 'https://github.com/genu.png',
    },
  },
];
</script>

<template>
  <PDialog v-model:open="open">
    <PButton
      label="Search users..."
      color="neutral"
      variant="subtle"
      icon="i-lucide:search"
    />

    <template #content>
      <PCommandPalette
        close
        :groups="[{ id: 'users', items: users }]"
        @update:open="open = $event"
      />
    </template>
  </PDialog>
</template>
This can be useful when using the CommandPalette inside a Modal for example.

Use the #footer slot to add custom content at the bottom of the CommandPalette, such as keyboard shortcuts help or additional actions.

<script setup lang="ts">
const groups = [
  {
    id: 'actions',
    items: [
      {
        label: 'Add new file',
        suffix: 'Create a new file in the current directory',
        icon: 'i-lucide:file-plus',
        kbds: ['meta', 'N'],
      },
      {
        label: 'Add new folder',
        suffix: 'Create a new folder in the current directory',
        icon: 'i-lucide:folder-plus',
        kbds: ['meta', 'F'],
      },
      {
        label: 'Search files',
        suffix: 'Search across all files in the project',
        icon: 'i-lucide:search',
        kbds: ['meta', 'P'],
      },
      {
        label: 'Settings',
        suffix: 'Open application settings',
        icon: 'i-lucide:settings',
        kbds: ['meta', ','],
      },
    ],
  },
  {
    id: 'recent',
    label: 'Recent',
    items: [
      {
        label: 'project.vue',
        suffix: 'components/',
        icon: 'i-vscode-icons:file-type-vue',
      },
      {
        label: 'readme.md',
        suffix: 'docs/',
        icon: 'i-vscode-icons:file-type-markdown',
      },
      {
        label: 'package.json',
        suffix: 'root/',
        icon: 'i-vscode-icons:file-type-node',
      },
    ],
  },
];
</script>

<template>
  <PCommandPalette
    :groups="groups"
    class="flex-1 h-80"
  >
    <template #footer>
      <div class="flex gap-2 items-center justify-between">
        <PIcon
          name="i-simple-icons:nuxtdotjs"
          class="text-dimmed ml-1 size-5"
        />
        <div class="flex gap-1 items-center">
          <PButton
            color="neutral"
            variant="ghost"
            label="Open Command"
            class="text-dimmed"
            size="xs"
          >
            <template #trailing>
              <PKbd value="enter" />
            </template>
          </PButton>
          <PSeparator
            orientation="vertical"
            class="h-4"
          />
          <PButton
            color="neutral"
            variant="ghost"
            label="Actions"
            class="text-dimmed"
            size="xs"
          >
            <template #trailing>
              <PKbd value="meta" />
              <PKbd value="k" />
            </template>
          </PButton>
        </div>
      </div>
    </template>
  </PCommandPalette>
</template>

With custom slot

Use the slot property to customize a specific item or group.

You will have access to the following slots:

  • #{{ item.slot }}
  • #{{ item.slot }}-leading
  • #{{ item.slot }}-label
  • #{{ item.slot }}-trailing
  • #{{ group.slot }}
  • #{{ group.slot }}-leading
  • #{{ group.slot }}-label
  • #{{ group.slot }}-trailing
<script setup lang="ts">
const groups = [
  {
    id: 'settings',
    items: [
      {
        label: 'Profile',
        icon: 'i-lucide:user',
        kbds: ['meta', 'P'],
      },
      {
        label: 'Billing',
        icon: 'i-lucide:credit-card',
        kbds: ['meta', 'B'],
        slot: 'billing' as const,
      },
      {
        label: 'Notifications',
        icon: 'i-lucide:bell',
      },
      {
        label: 'Security',
        icon: 'i-lucide:lock',
      },
    ],
  },
  {
    id: 'users',
    label: 'Users',
    slot: 'users' as const,
    items: [
      {
        label: 'praburangki',
        suffix: 'praburangki',
        to: 'https://github.com/praburangki',
        target: '_blank',
      },
      {
        label: 'Wahyu Ivan',
        suffix: 'wahyu-ivan',
        to: 'https://github.com/wahyu-ivan',
        target: '_blank',
      },
      {
        label: 'Sébastien Chopin',
        suffix: 'atinux',
        to: 'https://github.com/atinux',
        target: '_blank',
      },
      {
        label: 'Hugo Richard',
        suffix: 'HugoRCD',
        to: 'https://github.com/HugoRCD',
        target: '_blank',
      },
      {
        label: 'Sandro Circi',
        suffix: 'sandros94',
        to: 'https://github.com/sandros94',
        target: '_blank',
      },
      {
        label: 'Daniel Roe',
        suffix: 'danielroe',
        to: 'https://github.com/danielroe',
        target: '_blank',
      },
      {
        label: 'Jakub Michálek',
        suffix: 'J-Michalek',
        to: 'https://github.com/J-Michalek',
        target: '_blank',
      },
      {
        label: 'Eugen Istoc',
        suffix: 'genu',
        to: 'https://github.com/genu',
        target: '_blank',
      },
    ],
  },
];
</script>

<template>
  <PCommandPalette
    :groups="groups"
    class="flex-1 h-80"
  >
    <template #users-leading="{ item }">
      <PAvatar
        :src="`https://github.com/${item.suffix}.png`"
        size="2xs"
      />
    </template>

    <template #billing-label="{ item }">
      <span class="text-primary font-medium">{{ item.label }}</span>

      <PBadge
        variant="subtle"
        size="sm"
      >
        50% off
      </PBadge>
    </template>
  </PCommandPalette>
</template>
You can also use the #item, #item-leading, #item-label and #item-trailing slots to customize all items.

API

Props

Prop Default Type

Slots

Slot Type

Emits

Event Type

Theme

We use unocss-variants to customize the theme. Read more about it in the theming guide.

Below is the theme configuration skeleton for the PCommandPalette. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.

app.config.ts
export default defineAppConfig({
  pohon: {
    commandPalette: {
      slots: {
        root: '',
        input: '',
        close: '',
        back: '',
        content: '',
        footer: '',
        viewport: '',
        group: '',
        empty: '',
        label: '',
        item: '',
        itemLeadingIcon: '',
        itemLeadingAvatar: '',
        itemLeadingAvatarSize: '',
        itemLeadingChip: '',
        itemLeadingChipSize: '',
        itemTrailing: '',
        itemTrailingIcon: '',
        itemTrailingHighlightedIcon: '',
        itemTrailingKbds: '',
        itemTrailingKbdsSize: '',
        itemWrapper: '',
        itemLabel: '',
        itemDescription: '',
        itemLabelBase: '',
        itemLabelPrefix: '',
        itemLabelSuffix: ''
      },
      variants: {
        virtualize: {
          true: {
            viewport: ''
          },
          false: {
            viewport: ''
          }
        },
        active: {
          true: {
            item: '',
            itemLeadingIcon: ''
          },
          false: {
            item: '',
            itemLeadingIcon: ''
          }
        },
        loading: {
          true: {
            itemLeadingIcon: ''
          }
        }
      }
    }
  }
};
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'

export default defineAppConfig({
  pohon: {
    commandPalette: {
      slots: {
        root: '',
        input: '',
        close: '',
        back: '',
        content: '',
        footer: '',
        viewport: '',
        group: '',
        empty: '',
        label: '',
        item: '',
        itemLeadingIcon: '',
        itemLeadingAvatar: '',
        itemLeadingAvatarSize: '',
        itemLeadingChip: '',
        itemLeadingChipSize: '',
        itemTrailing: '',
        itemTrailingIcon: '',
        itemTrailingHighlightedIcon: '',
        itemTrailingKbds: '',
        itemTrailingKbdsSize: '',
        itemWrapper: '',
        itemLabel: '',
        itemDescription: '',
        itemLabelBase: '',
        itemLabelPrefix: '',
        itemLabelSuffix: ''
      },
      variants: {
        virtualize: {
          true: {
            viewport: ''
          },
          false: {
            viewport: ''
          }
        },
        active: {
          true: {
            item: '',
            itemLeadingIcon: ''
          },
          false: {
            item: '',
            itemLeadingIcon: ''
          }
        },
        loading: {
          true: {
            itemLeadingIcon: ''
          }
        }
      }
    }
  }
};

Changelog

No recent changes