Skip to content

Hotkey

<quiet-hotkey> stable since 1.0

Hotkeys show keyboard shortcut combinations based on the user's operating system.

<quiet-hotkey keys="$command K"></quiet-hotkey>

Examples Jump to heading

Basic usage Jump to heading

Set the key attribute to a string containing the space-separated keys you want to display in the hotkey. Do not include delimiters, as they will be added automatically.

You can use any of the following keywords to show platform-specific keys.

Keyword Mac Others
$command Ctrl
$control Ctrl
$option Alt
$shift Shift
$escape Esc Esc
$enter
$backspace
$delete
$tab
$up
$down
$left
$right
<quiet-hotkey keys="$option $command B"></quiet-hotkey>

Note that $cmd and $option map to "CTRL" and "ALT" on non-Mac platforms. This is a common practice, but not guaranteed for all keyboard shortcuts.

Platform-specific shortcuts Jump to heading

To show platform-specific hotkeys, use the windows, mac, and linux attributes. These will override the keys attribute, but only on the respective platforms.

<quiet-hotkey
  keys="$command $shift A"
  mac="$shift $command A"
></quiet-hotkey>

Adding a label Jump to heading

By default, screen readers will announce the hotkey text as-is. To set a custom label for assistive devices, use the label attribute.

<quiet-hotkey
  label="Press command or control + Q to quit"
  keys="$command Q"
></quiet-hotkey>

Setting the platform Jump to heading

Use the platform attribute to show hotkeys for a specific platform, regardless of the user's operating system. The default value is auto, which will attempt to automatically detect the user's operating system.

Mac Windows Linux
<div id="hotkeys__platform">
  <p>
    <quiet-hotkey 
      platform="mac"
      mac="$shift $command M"
      windows="$command $shift W"
      linux="$command $shift L"
    ></quiet-hotkey>
  </p>

  <quiet-radio label="Platform" value="mac">
    <quiet-radio-item value="mac">Mac</quiet-radio-item>
    <quiet-radio-item value="windows">Windows</quiet-radio-item>
    <quiet-radio-item value="linux">Linux</quiet-radio-item>
  </quiet-radio>
</div>

<script>
  const container = document.getElementById('hotkeys__platform');
  const hotkey = container.querySelector('quiet-hotkey');
  const radio = container.querySelector('quiet-radio');

  // Update the platform
  radio.addEventListener('quiet-input', () => {
    hotkey.platform = radio.value;
  });
</script>

Customizing the delimiter Jump to heading

By default, the delimiter is automatically determined by the platform (no character for Mac and "+" for others). To change it, set the delimiter attribute to the character you want to insert between each key.

<quiet-hotkey 
  keys="$command $shift A" 
  delimiter="·"
></quiet-hotkey>

Changing the appearance Jump to heading

By default, the keyboard hotkey is styled with <kbd> styles. Set the appearance attribute to unstyled to make it look like plain text. To target individual keys, use the key and keyword parts.

Press to search.
Press 
<quiet-hotkey 
  keys="$command K"
  appearance="unstyled"
></quiet-hotkey>
to search.

Styling keys and keywords Jump to heading

Use the key and keyword parts to change the styles of individual characters.

Press to search.
Press 
<quiet-hotkey 
  keys="$command K"
  id="hotkeys__styling"
></quiet-hotkey>
to search.

<style>
  quiet-hotkey#hotkeys__styling {
    &::part(keyword) {
      color: dodgerblue;
    }

    &::part(key) {
      color: deeppink;
    }
  }
</style>

API Jump to heading

Importing Jump to heading

The autoloader is the recommended way to import components but, if you prefer to do it manually, the following code snippets will be helpful.

CDN npm

To manually import <quiet-hotkey> from the CDN, use the following code.

import 'https://cdn.jsdelivr.net/npm/@quietui/quiet@1.0.0/dist/components/hotkey/hotkey.js';

To manually import <quiet-hotkey> from npm, use the following code.

import '@quietui/quiet/dist/components/hotkey/hotkey.js';

Properties Jump to heading

Hotkey has the following properties that can be set with corresponding attributes. In many cases, the attribute's name is the same as the property's name. If an attribute is different, it will be displayed after the property. Learn more about attributes and properties

Property / Attribute Description Reflects Type Default
keys The primary keys to display in the hotkey, separated by a space. string ''
linux The keys to display on Linux devices, separated by a space. string ''
mac The keys to display on Mac devices, separated by a space. string ''
windows The keys to display on Windows devices, separated by a space. string ''
label Optional label for screen readers. If not provided, the hotkey text will be used. string
delimiter The delimiter to show between each key. When set to auto, the delimiter will be determined by the platform (no character for Mac and "+" for others). 'auto'
string
'auto'
platform Determines the platform to show. When set to auto, the platform will be automatically detected. The linux platform will be used for most Linux, Unix, and BSD operating systems. 'auto'
'linux'
'mac'
'windows'
'auto'
appearance The hotkey's appearance. 'normal'
'unstyled'
'normal'

CSS parts Jump to heading

Hotkey exposes internal elements that can be styled with CSS using the selectors shown below. Learn more about CSS parts

Name Description CSS selector
key The <kbd> elements that wrap keys. ::part(key)
keyword The <kbd> elements that wrap keywords. ::part(keyword)
delimiter The <span> elements that wrap delimiters. ::part(delimiter)
Search this website Toggle dark mode Get the code on GitHub Follow @quietui.org on Bluesky Follow @quiet_ui on X
    No results found