Guides
Keyboard shortcuts and command palette
Register shortcuts, show them the same way on Mac and PC, and add actions to the command palette.
Register a shortcut
Use Vuetify's useHotkey. It understands cmd, which becomes ⌘ on Mac and Ctrl on Windows and Linux:
import { useHotkey } from 'vuetify'
useHotkey('c', () => compose())
useHotkey('cmd+enter', () => send(), { inputs: true })
useHotkey('slash', () => searchRef.value?.focus())
By default a shortcut does not fire while the user types in a field. Pass { inputs: true } for shortcuts that should, such as sending a message.
Show a shortcut
Display keys with v-hotkey, never with hand-written <kbd> elements, so each platform sees its own symbols:
<v-hotkey keys="cmd+k" />
Show a shortcut on screen only where it is part of the interaction:
- the
Ctrl/⌘ Ksearch trigger in the navbar; - the legend of the command palette;
- Enter in a quick-add field;
BaseTextSearch hotkey="/"while the field is empty.
Every other shortcut goes in the tooltip of its control through BaseTooltip, which also sets aria-keyshortcuts:
<BaseTooltip :text="$t('apps.email.compose')" keys="c" location="end">
<template #default="{ props: tooltip }">
<BaseIconButton v-bind="tooltip" icon="pencil" :aria-label="$t('apps.email.compose')" @click="compose" />
</template>
</BaseTooltip>
The command palette
AppCommandPalette opens with Ctrl/⌘ K or the search trigger in the navbar. It lists every page the user may open, grouped by menu section, plus a few actions (theme, customizer, sign out). Pages come from useNavigation(), so a new menu item appears in the palette automatically.
Open it from your own code:
const { open } = useCommandPalette()
Add a global action
Add an entry to the actions list in components/layout/AppCommandPalette.vue:
{
key: 'new-invoice',
group: 'actions',
title: t('commandPalette.newInvoice'),
icon: 'receipt',
action: () => navigateTo('/billing/invoices/new'),
},
Shortcuts in the demo
Screen | Keys |
|---|---|
| Everywhere | Ctrl/⌘ K command palette |
j / k next and previous, e archive, s star, u mark unread, r reply, c compose, / search, Esc close | |
| Tasks | n focus the quick add field |
| Kanban | Alt + arrows move the focused card |
| Help center | / focus the search |