Skip to content

Spotlight

A keyboard-first palette for searching and running commands, with nested commands and accessible combobox markup.

Demo ​

Basic

or press Ctrl / ⌘ + K

Last command

Nothing run yet.


Install ​

bash
npm i @vuesimple/vs-spotlight

Usage ​

html
<template>
  <button @click="open = true">Commands</button>
  <vs-spotlight v-model:open="open" :commands="commands" />
</template>

<script>
  import VsSpotlight from '@vuesimple/vs-spotlight';

  export default {
    components: {
      VsSpotlight,
    },

    data() {
      return {
        open: false,
        commands: [
          { id: 'new-file', label: 'New file', group: 'File', shortcut: '⌘N', run: () => this.newFile() },
          { id: 'open-file', label: 'Open file', group: 'File', keywords: ['load'], run: () => this.openFile() },
          {
            id: 'export',
            label: 'Export as',
            group: 'File',
            children: [
              { id: 'export-pdf', label: 'PDF', run: () => this.exportPdf() },
              { id: 'export-csv', label: 'CSV', run: () => this.exportCsv() },
            ],
          },
          { id: 'delete-all', label: 'Delete all items', group: 'Danger', disabled: true, run: () => {} },
        ],
      };
    },

    methods: {
      newFile() {},
      openFile() {},
      exportPdf() {},
      exportCsv() {},
    },
  };
</script>

Press Ctrl / ⌘ + K anywhere on the page to toggle the palette. Pass shortcut="" to turn this off.

CDN ​

html
<script src="https://cdn.jsdelivr.net/npm/@vuesimple/vs-spotlight@3.1.8/dist/index.min.js"></script>
javascript
// Main/Entry file
app.use(VsSpotlight.plugin);

Keyboard ​

KeyAction
↑ / ↓Move through commands (wraps around).
EnterRun the highlighted command, or open its children.
Backspace (empty query)Go back one level in a nested command.
EscapeClose the palette.
TabMove focus between the search input and the Back button (trapped).
Home / End (empty query)Jump to the first or last command.
Ctrl / ⌘ + KToggle the palette (set shortcut to change the letter or "").

Props ​

NameTypeDefaultDescription
openBooleanfalseShows the palette. Use with v-model:open.
commandsArray[]Commands to show. See Command shape.
placeholderStringType a command or search...Placeholder text for the search input.
emptyTextStringNo matching commandsText shown when nothing matches.
maxResultsNumber50Maximum number of commands shown at once.
shortcutStringkLetter used with Ctrl/⌘ to toggle the palette. Pass "" to disable.
closeOnSelectBooleantrueClose the palette after a command runs. Commands with children never close it.
titleString''Heading shown above the search input. Hidden when empty.
badgeString''Small label shown next to the title (for example Beta).
showFooterBooleantrueShows the footer with the result count and key hints.
uppercaseGroupsBooleantrueRenders group headings in uppercase.
animateBooleantrueFades and scales the palette in and out.
teleportBooleantrueMoves the palette to teleportTo so it is not clipped by parent containers.
teleportToString | ObjectbodyTarget for the teleport, passed to Vue's <teleport to>.

Command shape ​

FieldTypeRequiredDescription
idStringYesUnique key for the command.
labelStringYesText shown and matched when searching.
groupStringNoSection heading. Commands with the same group are shown together.
iconComponent | StringNoRendered before the label. Pass a Vue component (for example a heroicon) or an image URL string, which renders as an <img>.
descriptionStringNoMuted second line shown under the label.
keywordsArrayNoExtra search terms. Matches count for less than label matches.
shortcutStringNoDisplay hint only (for example ⌘N). The palette does not bind this key.
disabledBooleanNoShows the command but does not run it.
childrenArrayNoNested commands. Selecting this command opens them instead of running it.
runFunctionNoCalled with the command when it is selected.

Events ​

NamePayloadDescription
update:openbooleanEmitted when the palette wants to open or close.
selectcommandEmitted when a command (without children) is selected.
searchstringEmitted when the search text changes.

Slots ​

NameScopeDescription
item{ command, active }Replaces the markup of each command row.
empty-Replaces the empty-state message.
footer{ statusText, activeCommand }Replaces the footer content.