Command palette

@yasinsensoy/native

React Native · Components

Kbd

A keyboard key or shortcut (the same notation as web).

3 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Press Control+Shift+P to open commands.

Code

import { Kbd } from "@yasinsensoy/native";

<Kbd keys="Mod+Shift+P" />

Events

  1. Events appear here when you interact with the preview.

Key sequence and hand-written key

Go to dashboard: G, DSend: Control+EnterEsc

Import

import { Kbd } from "@yasinsensoy/native";

Kbd

component

A keyboard key or shortcut (the same notation as web). Shows shortcuts in apps used with tablets and external keyboards, and keys on help screens.

  • The shortcut is given with keys; "⌘K" on iOS/iPadOS, "Ctrl+K" on Android.
  • Screen readers read key names, not symbols ("Meta+K").
  • Bound to the appearance system (appearance.defaults.kbd, custom variants).
Kbd({ ref, keys, children, split, variant: variantProp, size, apple: appleProp, style, testID, }: KbdProps): JSX.Element

Examples

<Kbd keys="Mod+K" />
<Kbd keys="Mod+Shift+P" split />
<Kbd keys="G D" variant="soft" size="sm" />
<Kbd>Enter</Kbd>

Look of the key box (same as web).

  • outline: bordered with a thick bottom edge; looks like a real key.
  • soft: borderless with a muted background; plain in menus and tooltips.
  • ghost: text only; inside buttons.
type KbdVariant = "outline" | "soft" | "ghost"

KbdProps

interface

Props of the Kbd component.

NameTypeDefaultDescription
ref?Ref<ViewRef>Reference to the root view.
keys?stringShortcut to show: "Mod+K", "Mod+Shift+P", "Alt+Enter", "Esc". Mod is written as ⌘ on iOS/iPadOS and Ctrl on Android. Separate key sequences (e.g. G then D) with a space: "G D". If omitted children is shown as is.
children?ReactNodeHand-written content instead of keys (e.g. "Enter").
split?booleanfalseShow each key in its own box? With false the whole shortcut is in one box (e.g. "⇧⌘P" or "Ctrl+Shift+P").
variant?KbdVariant | (string & {})"outline"Variant: a built-in one (KbdVariant) or a custom variant added with defineAppearance. Defaults to UIProvider appearance.defaults.kbd.variant.
size?"sm" | "md""md"Size.
apple?booleanWhether the shortcut is written in Apple style (⌘, ⇧). Defaults to true on iOS/iPadOS and false on Android.
style?StyleProp<ViewStyle>Root style.
testID?stringTest id.