Keyboard Map
Draws a keyboard with the keys of one or more shortcuts lit up, for shortcut docs and cheat sheets.
<arc-keyboard-map>Overview
Keyboard Map draws a keyboard as a grid of keycaps and highlights the keys named in its highlight prop. For a key name in a sentence, use Kbd. Highlighted keys get an accent tint, a glow and accent legend text.
Chords are written the way Hotkey writes them: keys join with "+", cmd/command normalize to meta and option to alt. Keyboard Map also takes mod, which Hotkey doesn't. It resolves to Cmd on Mac and Ctrl on Windows, so one chord string documents both. platform sets the modifier legends and how mod resolves: "auto" detects the visitor's platform in the browser (and renders the Mac board on the server), and "mac" or "win" pins it.
The board is a stylized diagram with two layouts. compact (the default) is a 60%-style block with no nav cluster or numpad, and ansi adds the F-row and nav cluster. There's no ISO or JIS layout.
Nothing on the board is clickable or focusable. To make a shortcut work, use Hotkey. The board is one role="img" whose label is computed from the chords ("Keyboard diagram highlighting Cmd+Shift+P"), and the key legends are hidden from assistive technology.
Guidelines
Do
- Use it for cheat sheets and settings pages. For a shortcut mentioned in a sentence, use Kbd
- Put related chords on one board, such as undo and redo, and give it a caption naming the group
- Use the compact layout unless a chord uses the F-row or nav cluster
Don't
- Don't make the board the only place a shortcut is written down. The computed label names the chords, but the surrounding text should too
Features
- Modifier legends: ⌘ ⌥ ⇧ ⌃ on Mac, Ctrl/Alt/Shift/Win on Windows
- `highlight` takes an array property or a comma- or space-separated attribute string. Unknown key names are ignored
- Optional `caption` below the board in muted text
- Scales to its container. `--keyboard-map-key` and `--keyboard-map-gap` set the geometry, and the legends drop out below about 340px
- Unknown `layout` values fall back to compact
Preview
Usage
<!-- Chords as an attribute string; mod = Cmd on Mac, Ctrl on Windows -->
<arc-keyboard-map highlight="mod+z, mod+shift+z" caption="Undo and redo"></arc-keyboard-map>
<!-- Full board with F-row and nav cluster, pinned to Windows legends -->
<arc-keyboard-map layout="ansi" platform="win" highlight="alt+f4"></arc-keyboard-map>
<!-- Chords as an array property -->
<arc-keyboard-map id="palette-map"></arc-keyboard-map>
<script type="module">
document.getElementById('palette-map').highlight = ['mod+shift+p', 'escape'];
</script>import { KeyboardMap } from '@arclux/arc-ui-react';
<KeyboardMap highlight={['mod+z', 'mod+shift+z']} caption="Undo and redo" />
<KeyboardMap layout="ansi" platform="win" highlight="alt+f4" /><script setup>
import { KeyboardMap } from '@arclux/arc-ui-vue';
</script>
<template>
<KeyboardMap :highlight="['mod+z', 'mod+shift+z']" caption="Undo and redo" />
<KeyboardMap layout="ansi" platform="win" highlight="alt+f4" />
</template><script>
import { KeyboardMap } from '@arclux/arc-ui-svelte';
</script>
<KeyboardMap highlight={['mod+z', 'mod+shift+z']} caption="Undo and redo" />
<KeyboardMap layout="ansi" platform="win" highlight="alt+f4" />import { Component } from '@angular/core';
import { KeyboardMap } from '@arclux/arc-ui-angular';
@Component({
imports: [KeyboardMap],
template: `
<arc-keyboard-map highlight="mod+z, mod+shift+z" caption="Undo and redo" />
<arc-keyboard-map layout="ansi" platform="win" highlight="alt+f4" />
`,
})
export class ShortcutsComponent {}import { KeyboardMap } from '@arclux/arc-ui-solid';
<KeyboardMap highlight={['mod+z', 'mod+shift+z']} caption="Undo and redo" />
<KeyboardMap layout="ansi" platform="win" highlight="alt+f4" />import { KeyboardMap } from '@arclux/arc-ui-preact';
<KeyboardMap highlight={['mod+z', 'mod+shift+z']} caption="Undo and redo" />
<KeyboardMap layout="ansi" platform="win" highlight="alt+f4" />API
layout'compact' | 'ansi''compact'- Board shape: "compact" (default, a 60%-style block) or "ansi" (adds the F-row and nav cluster). Unknown values fall back to compact.
highlightstring|string[]''- Key chords to light up: an array property (e.g. ["mod+z", "mod+shift+z"]) or a comma- or space-separated attribute string. Each chord joins keys with "+" ("mod+shift+p");
modresolves to Cmd on mac and Ctrl on win, mirroring arc-hotkey's aliases (cmd/command → meta, option → alt, control → ctrl). Single keys are fine ("g", "escape"). Unknown key names are ignored. labelsbooleantrue- Whether keys render their legends. Default true; disable from markup with either
no-labelsorlabels="false". platform'auto' | 'mac' | 'win''auto'- Which platform's modifier legends and
modresolution to use: "auto" (default, detected in the browser, mac on the server), "mac", or "win". captionstring''- Optional caption rendered below the board in muted text.