Keyboard shortcut: Ctrl + K
Get started

Hotkeys

VHotkeys displays a keyboard shortcut using platform conventions. Enable listen to emit an event when it is pressed.

Usage

vue
Keyboard shortcut: Ctrl + K
<script setup lang="ts">
import { VHotkeys } from 'vectis-ui'
</script>

<template>
  <VHotkeys keys="mod+k" />
</template>

Examples

What you can write

Write keys as a +-separated string, ignoring case and spaces. mod means Command on macOS and Ctrl elsewhere; meta is the literal system key. Write the plus key as plus. Unknown tokens display unchanged.

You writemacOSWindows and Linux
modKeyboard shortcut: CommandKeyboard shortcut: Ctrl
metacmdcommandwinsuperKeyboard shortcut: CommandKeyboard shortcut: Win
ctrlcontrolKeyboard shortcut: CtrlKeyboard shortcut: Ctrl
altoptionoptKeyboard shortcut: AltKeyboard shortcut: Alt
shiftKeyboard shortcut: ShiftKeyboard shortcut: Shift
enterreturnKeyboard shortcut: EnterKeyboard shortcut: Enter
escescapeKeyboard shortcut: EscKeyboard shortcut: Esc
spaceKeyboard shortcut: SpaceKeyboard shortcut: Space
backspaceKeyboard shortcut: BackspaceKeyboard shortcut: Backspace
deletedelKeyboard shortcut: DelKeyboard shortcut: Del
tabKeyboard shortcut: TabKeyboard shortcut: Tab
updownleftrightKeyboard shortcut: Up arrowKeyboard shortcut: Down arrowKeyboard shortcut: Left arrowKeyboard shortcut: Right arrowKeyboard shortcut: Up arrowKeyboard shortcut: Down arrowKeyboard shortcut: Left arrowKeyboard shortcut: Right arrow
plusKeyboard shortcut: +Keyboard shortcut: +
kf5,Keyboard shortcut: KKeyboard shortcut: F5Keyboard shortcut: ,Keyboard shortcut: KKeyboard shortcut: F5Keyboard shortcut: ,

Variants

variant selects soft, outlined or raised keycaps. Colours inherit from the surrounding text.

vue
Keyboard shortcut: Ctrl + Shift + P

soft

Keyboard shortcut: Ctrl + Shift + P

outline

Keyboard shortcut: Ctrl + Shift + P

elevated

<script setup lang="ts">
import { VHotkeys, VTypography, type HotkeysVariant } from 'vectis-ui'

const VARIANTS: HotkeysVariant[] = ['soft', 'outline', 'elevated']
</script>

<template>
  <div class="row">
    <div v-for="variant in VARIANTS" :key="variant" class="cell">
      <VHotkeys keys="mod+shift+p" :variant="variant" />
      <VTypography variant="caption" tone="muted">{{ variant }}</VTypography>
    </div>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-6);
}
.cell {
  display: grid;
  justify-items: center;
  gap: var(--vectis-space-2);
}
</style>

Sizes

Choose xs or sm.

vue
Keyboard shortcut: Ctrl + K

xs

Keyboard shortcut: Ctrl + K

sm

<script setup lang="ts">
import { VHotkeys, VTypography, type HotkeysSize } from 'vectis-ui'

const SIZES: HotkeysSize[] = ['xs', 'sm']
</script>

<template>
  <div class="row">
    <div v-for="size in SIZES" :key="size" class="cell">
      <VHotkeys keys="mod+k" :size="size" variant="outline" />
      <VTypography variant="caption" tone="muted">{{ size }}</VTypography>
    </div>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--vectis-space-6);
}
.cell {
  display: grid;
  justify-items: center;
  gap: var(--vectis-space-2);
}
</style>

Attached

attached frames the whole shortcut as one key. It does not change its accessible name or behaviour.

vue
Keyboard shortcut: Ctrl + Shift + K

One cap per key

Keyboard shortcut: Ctrl + Shift + K

attached

Keyboard shortcut: Ctrl + Shift + K

attached, no separator

<script setup lang="ts">
import { VHotkeys, VTypography } from 'vectis-ui'
</script>

<template>
  <div class="row">
    <div class="cell">
      <VHotkeys keys="mod+shift+k" variant="outline" />
      <VTypography variant="caption" tone="muted">One cap per key</VTypography>
    </div>

    <div class="cell">
      <VHotkeys keys="mod+shift+k" attached variant="outline" />
      <VTypography variant="caption" tone="muted">attached</VTypography>
    </div>

    <div class="cell">
      <VHotkeys keys="mod+shift+k" attached separator="" variant="outline" />
      <VTypography variant="caption" tone="muted">attached, no separator</VTypography>
    </div>
  </div>
</template>

<style scoped>
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-6);
}
.cell {
  display: grid;
  justify-items: center;
  gap: var(--vectis-space-2);
}
</style>

Platform

platform overrides automatic platform detection.

vue

macOS

Keyboard shortcut: Command + KKeyboard shortcut: Command + Shift + EnterKeyboard shortcut: Alt + Backspace

Windows

Keyboard shortcut: Ctrl + KKeyboard shortcut: Win + Shift + EnterKeyboard shortcut: Alt + Backspace

Linux

Keyboard shortcut: Ctrl + KKeyboard shortcut: Super + Shift + EnterKeyboard shortcut: Alt + Backspace

Unknown

Keyboard shortcut: Ctrl + KKeyboard shortcut: Super + Shift + EnterKeyboard shortcut: Alt + Backspace
<script setup lang="ts">
import { VHotkeys, VTypography, type HotkeysPlatform } from 'vectis-ui'

const PLATFORMS: { value: HotkeysPlatform; label: string }[] = [
  { value: 'mac', label: 'macOS' },
  { value: 'windows', label: 'Windows' },
  { value: 'linux', label: 'Linux' },
  { value: 'other', label: 'Unknown' },
]
</script>

<template>
  <div class="grid">
    <template v-for="platform in PLATFORMS" :key="platform.value">
      <VTypography variant="caption" tone="muted">{{ platform.label }}</VTypography>
      <div class="keys">
        <VHotkeys keys="mod+k" :platform="platform.value" variant="outline" />
        <VHotkeys keys="meta+shift+enter" :platform="platform.value" variant="outline" />
        <VHotkeys keys="alt+backspace" :platform="platform.value" variant="outline" />
      </div>
    </template>
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--vectis-space-3) var(--vectis-space-5);
}
.keys {
  display: flex;
  flex-wrap: wrap;
  gap: var(--vectis-space-3);
}
</style>

Separator

separator sets the text between keys. Use an empty string for adjacent macOS symbols.

vue
Keyboard shortcut: Ctrl + Shift + K

The default

Keyboard shortcut: Ctrl + Shift + K

Nothing, the macOS convention

Keyboard shortcut: Ctrl + Shift + K

A middle dot

Keyboard shortcut: Ctrl + Shift + K

A slash

<script setup lang="ts">
import { VHotkeys, VTypography } from 'vectis-ui'

const SEPARATORS = [
  { value: '+', label: 'The default' },
  { value: '', label: 'Nothing, the macOS convention' },
  { value: '·', label: 'A middle dot' },
  { value: '/', label: 'A slash' },
]
</script>

<template>
  <div class="grid">
    <template v-for="separator in SEPARATORS" :key="separator.label">
      <VHotkeys keys="mod+shift+k" :separator="separator.value" variant="outline" />
      <VTypography variant="caption" tone="muted">{{ separator.label }}</VTypography>
    </template>
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: var(--vectis-space-3) var(--vectis-space-5);
  justify-items: start;
}
</style>

In text and in components

Place shortcuts beside controls, in menus or in tooltips.

vue

Press Keyboard shortcut: Ctrl + K to open the command palette, then type the first letters of what you are after. Keyboard shortcut: Esc puts it away again.

<script setup lang="ts">
import {
  VButton,
  VHotkeys,
  VMenu,
  VMenuItem,
  VMenuSeparator,
  VTooltip,
  VTypography,
} from 'vectis-ui'

const COMMANDS = [
  { label: 'New file', keys: 'mod+n' },
  { label: 'Save', keys: 'mod+s' },
  { label: 'Save as', keys: 'mod+shift+s' },
]
</script>

<template>
  <div class="stack">
    <VTypography class="prose">
      Press <VHotkeys keys="mod+k" /> to open the command palette, then type the first letters of
      what you are after. <VHotkeys keys="esc" /> puts it away again.
    </VTypography>

    <VMenu>
      <template #trigger="{ triggerProps }">
        <VButton v-bind="triggerProps" variant="outline" tone="neutral">File</VButton>
      </template>
      <VMenuItem v-for="command in COMMANDS" :key="command.keys" :label="command.label">
        <template #end><VHotkeys :keys="command.keys" /></template>
      </VMenuItem>
      <VMenuSeparator />
      <VMenuItem label="Settings">
        <template #end><VHotkeys keys="mod+," /></template>
      </VMenuItem>
    </VMenu>

    <VTooltip>
      <template #default="{ triggerProps }">
        <VButton v-bind="triggerProps" variant="outline" tone="neutral">Save</VButton>
      </template>
      <template #content>Save this file <VHotkeys keys="mod+s" size="xs" /></template>
    </VTooltip>

    <VButton variant="outline" tone="neutral" class="search">
      Search the docs
      <VHotkeys keys="mod+k" variant="outline" />
    </VButton>
  </div>
</template>

<style scoped>
.stack {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: var(--vectis-space-5);
}
.prose {
  max-inline-size: 34rem;
  line-height: 1.9;
}
.search {
  inline-size: 18rem;
  justify-content: space-between;
}
</style>

Listening

listen emits trigger for an exact modifier match. allowDefault preserves the browser action; allowInInput enables matching in editable fields. Escape is never cancelled. Matching uses the produced character: prefer letters and named keys over symbols, AZERTY digits or macOS Option-letter combinations.

vue

Keyboard shortcut: Ctrl + KPress it anywhere on the page. Fired 0 times.

Keyboard shortcut: Ctrl + S With allowDefault, the browser still saves the page. Fired 0 times.

Keyboard shortcut: Ctrl + JQuiet while a field has the focus: 0

Keyboard shortcut: Ctrl + JWith allowInInput, it fires there too: 0

<script setup lang="ts">
import { ref } from 'vue'
import { VHotkeys, VInput, VTypography } from 'vectis-ui'

const opened = ref(0)
const saved = ref(0)
const strict = ref(0)
const permissive = ref(0)
</script>

<template>
  <div class="stack">
    <p class="line">
      <VHotkeys keys="mod+k" variant="outline" listen @trigger="opened++" />
      <VTypography as="span">Press it anywhere on the page. Fired {{ opened }} times.</VTypography>
    </p>

    <!-- allowDefault also lets the browser open its save dialog. -->
    <p class="line">
      <VHotkeys keys="mod+s" variant="outline" listen allow-default @trigger="saved++" />
      <VTypography as="span" tone="muted">
        With allowDefault, the browser still saves the page. Fired {{ saved }} times.
      </VTypography>
    </p>

    <VInput label="Type in here, then press the shortcut below" class="field" />

    <p class="line">
      <VHotkeys keys="mod+j" variant="outline" listen @trigger="strict++" />
      <VTypography as="span">Quiet while a field has the focus: {{ strict }}</VTypography>
    </p>

    <p class="line">
      <VHotkeys keys="mod+j" variant="outline" listen allow-in-input @trigger="permissive++" />
      <VTypography as="span">With allowInInput, it fires there too: {{ permissive }}</VTypography>
    </p>
  </div>
</template>

<style scoped>
.stack {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: var(--vectis-space-4);
}
.line {
  display: flex;
  align-items: center;
  gap: var(--vectis-space-3);
  margin: 0;
}
.field {
  inline-size: 22rem;
}
</style>

API

Props

PropTypeDefault
keysstringnone
Shortcut string separated by +. Use mod for Command/Ctrl and plus for the plus key.
variantHotkeysVariant'soft' | 'outline' | 'elevated''soft'
Keycap style: soft, outlined or raised.
attachedbooleanfalse
Frames the whole combination as one key.
sizeHotkeysSize'xs' | 'sm''xs'
Component size.
platformHotkeysPlatform'mac' | 'windows' | 'linux' | 'other'none
Platform override for display and shortcut matching.
separatorstring'+'
Text between keys. An empty string keeps only spacing.
listenbooleanfalse
Enables shortcut matching and the trigger event.
allowDefaultbooleanfalse
Preserves the browser action when listening. Escape is always preserved.
allowInInputbooleanfalse
Allows matching in editable fields.
labelstringnone
Accessible shortcut name. Defaults to a localized reading of the keys.

Events

EventType
trigger[event: KeyboardEvent]
Matching shortcut was pressed while listen is enabled. Receives the keyboard event.