Svelte Command Palette

A command palette is a list of commands plus fuzzy matching plus a global hotkey, and the hard parts are the ones nobody demos: trapping focus, locking the scroll behind it, dismissing on Escape or an outside click without breaking the layer underneath. SvCommand sits on the same primitives the grid's own popovers use, so those are already handled.

You give it an array of commands with an id, a label, an optional group and a shortcut, and a function to run. It opens on Cmd+K or Ctrl+K by default, or you can drive the open state yourself.

Install

npm i @svgrid/grid

Free and MIT-licensed in @svgrid/grid: no license key, no row cap, no watermark.

The code

<script lang="ts">
  import { SvCommand, type CommandItem } from '@svgrid/grid'

  const commands: CommandItem[] = [
    { id: 'new',    label: 'New record',  group: 'Actions', shortcut: 'Ctrl+N', onRun: create },
    { id: 'export', label: 'Export CSV',  group: 'Actions', onRun: exportCsv },
    { id: 'docs',   label: 'Open docs',   group: 'Help',    onRun: () => goto('/docs') },
  ]
</script>

<!-- Cmd/Ctrl+K opens it -->
<SvCommand {commands} onRun={(c) => track(c.id)} />

What you get

Live examples

Documentation

Related articles

Frequently asked questions

How do I add a Cmd+K command palette to a Svelte app?

Import SvCommand from @svgrid/grid, pass an array of commands with id, label and onRun, and render it once near the root of your layout. The Cmd or Ctrl plus K hotkey is wired by default.

Can I open it from a button?

Yes. Use bind:open and set it to true from anywhere, which is how the header search buttons in the demos work.

Is it accessible?

It traps focus while open, restores focus on close, locks the background scroll and is fully operable with the arrow keys, Enter and Escape.

Is the command palette free?

Yes. SvCommand is MIT-licensed in @svgrid/grid and pulls in no third-party dependency.

Build something else

Get started · Browse the gallery · Pricing