An open source design system that's fully customizable and agent ready
TypeScript
fix(Kbd): meta shows ⌘ on Apple platforms (#10528)
Cindy Zhang8e526d661ae3
diff --git a/.changeset/kbd-meta-command.md b/.changeset/kbd-meta-command.mdnew file mode 100644index 0000000000..0a57414615--- /dev/null+++ b/.changeset/kbd-meta-command.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[feat] `Kbd` shows `meta` as ⌘ on Apple platforms, where it showed "META".++@cixzhangdiff --git a/docs/specs/components/Kbd/Kbd.spec.md b/docs/specs/components/Kbd/Kbd.spec.mdindex 633c8730f7..8b6c11a255 100644--- a/docs/specs/components/Kbd/Kbd.spec.md+++ b/docs/specs/components/Kbd/Kbd.spec.md@@ -83,12 +83,12 @@ Consumer migration instructions belong in consumer docs and release notes.## Behavioral and layout contract-| ID | Invariant | Basis |-| --- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |-| FR1 | The current render contains one shortcut group and one painted key badge for every parsed key segment. `keys` splits on `+`; each segment is trimmed and lowercased, `esc` reads as `escape` and `return` as `enter`, and a repeated key gets its own badge. Each badge is at least the `--spacing-5` size and MUST grow with a set text size so its glyph never clips (`spec:AST-102` FR4). | Current source, docs, and tests; `spec:AST-102` FR4 |-| FR2 | The shortcut group carries the current `kbd` target; individual key badges currently carry no public target (OQ1). | Current source, docs, and tests |-| FR3 | Each badge shows a glyph: `mod` is ⌘ on Apple platforms and the catalog's short Control text ("Ctrl" in English) elsewhere and before hydration; `ctrl`, `alt`, and `shift` follow the same rule, ⌃ ⌥ ⇧ on Apple platforms and the catalog's short text ("Ctrl", "Alt", "Shift" in English) elsewhere and before hydration; `meta` shows the catalog's short Windows-key text ("Win" in English) elsewhere and before hydration; spoken names are unchanged; `escape` shows the catalog's short Escape text ("Esc"); `enter`, `backspace`, `tab`, and the arrows show their symbols; `plus` shows "+"; any other key shows uppercased. | `architecture:internationalization` INV1a; current source and tests |-| FR4 | The group has `role="img"` and an `aria-label` built from each key's spoken name, taken from the Astryx catalog (`mod` is "Command" on Apple platforms and "Control" elsewhere and before hydration; an unknown key is spoken uppercased), joined pairwise through the catalog's shortcut message (" + " in English, for example "Command + K"); every badge is `aria-hidden`. A caller's `role` and `aria-label` never replace the computed ones; other caller ARIA props, such as `aria-labelledby` and `aria-hidden`, still reach the group. | `architecture:internationalization` INV1, INV1a; current source and tests |+| ID | Invariant | Basis |+| --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |+| FR1 | The current render contains one shortcut group and one painted key badge for every parsed key segment. `keys` splits on `+`; each segment is trimmed and lowercased, `esc` reads as `escape` and `return` as `enter`, and a repeated key gets its own badge. Each badge is at least the `--spacing-5` size and MUST grow with a set text size so its glyph never clips (`spec:AST-102` FR4). | Current source, docs, and tests; `spec:AST-102` FR4 |+| FR2 | The shortcut group carries the current `kbd` target; individual key badges currently carry no public target (OQ1). | Current source, docs, and tests |+| FR3 | Each badge shows a glyph: `mod` is ⌘ on Apple platforms and the catalog's short Control text ("Ctrl" in English) elsewhere and before hydration; `ctrl`, `alt`, and `shift` follow the same rule, ⌃ ⌥ ⇧ on Apple platforms and the catalog's short text ("Ctrl", "Alt", "Shift" in English) elsewhere and before hydration; `meta` shows ⌘ on Apple platforms and the catalog's short Windows-key text ("Win" in English) elsewhere and before hydration; spoken names are unchanged; `escape` shows the catalog's short Escape text ("Esc"); `enter`, `backspace`, `tab`, and the arrows show their symbols; `plus` shows "+"; any other key shows uppercased. | `architecture:internationalization` INV1a; current source and tests |+| FR4 | The group has `role="img"` and an `aria-label` built from each key's spoken name, taken from the Astryx catalog (`mod` is "Command" on Apple platforms and "Control" elsewhere and before hydration; an unknown key is spoken uppercased), joined pairwise through the catalog's shortcut message (" + " in English, for example "Command + K"); every badge is `aria-hidden`. A caller's `role` and `aria-label` never replace the computed ones; other caller ARIA props, such as `aria-labelledby` and `aria-hidden`, still reach the group. | `architecture:internationalization` INV1, INV1a; current source and tests |### Allowed variationdiff --git a/packages/core/src/Kbd/Kbd.doc.mjs b/packages/core/src/Kbd/Kbd.doc.mjsindex c1dc306e01..a1c271ea5d 100644--- a/packages/core/src/Kbd/Kbd.doc.mjs+++ b/packages/core/src/Kbd/Kbd.doc.mjs@@ -67,7 +67,7 @@ export const docs = {name: 'keys',type: 'string',description:- 'Keyboard shortcut string. Use "+" to separate keys. Special keys: mod (⌘ on Apple platforms, Ctrl elsewhere), ctrl, alt and shift (Apple symbols on Apple platforms, Ctrl, Alt and Shift text elsewhere), meta (Win elsewhere and before hydration), enter, backspace, escape, tab, up, down, left, right, plus. Aliases: esc for escape and return for enter.',+ 'Keyboard shortcut string. Use "+" to separate keys. Special keys: mod (⌘ on Apple platforms, Ctrl elsewhere), ctrl, alt and shift (Apple symbols on Apple platforms, Ctrl, Alt and Shift text elsewhere), meta (⌘ on Apple platforms, Win elsewhere and before hydration), enter, backspace, escape, tab, up, down, left, right, plus. Aliases: esc for escape and return for enter.',required: true,},{@@ -114,7 +114,7 @@ export const docsZh = {name: 'keys',type: 'string',description:- '键盘快捷键字符串。使用 "+" 分隔各按键。特殊按键:mod(Apple 平台上为 ⌘,其他平台为 Ctrl)、ctrl、alt 和 shift(Apple 平台上为符号,其他平台为 Ctrl、Alt、Shift 文字)、meta(其他平台及水合前为 Win)、enter、backspace、escape、tab、up、down、left、right、plus。别名:esc 等同于 escape,return 等同于 enter。',+ '键盘快捷键字符串。使用 "+" 分隔各按键。特殊按键:mod(Apple 平台上为 ⌘,其他平台为 Ctrl)、ctrl、alt 和 shift(Apple 平台上为符号,其他平台为 Ctrl、Alt、Shift 文字)、meta(Apple 平台上为 ⌘,其他平台及水合前为 Win)、enter、backspace、escape、tab、up、down、left、right、plus。别名:esc 等同于 escape,return 等同于 enter。',required: true,},{@@ -163,7 +163,7 @@ export const docsDense = {bestPractices,},propDescriptions: {- keys: 'Shortcut string. "+" separates keys. Special: mod (⌘ on Apple, Ctrl elsewhere), ctrl, alt, shift (Apple symbols on Apple, text elsewhere), meta (Win elsewhere and before hydration), enter, backspace, escape, tab, up, down, left, right, plus. Aliases: esc for escape, return for enter.',+ keys: 'Shortcut string. "+" separates keys. Special: mod (⌘ on Apple, Ctrl elsewhere), ctrl, alt, shift (Apple symbols on Apple, text elsewhere), meta (⌘ on Apple platforms, Win elsewhere and before hydration), enter, backspace, escape, tab, up, down, left, right, plus. Aliases: esc for escape, return for enter.',xstyle:'StyleX styles for layout customization. Must be stylex.create() value.',className:diff --git a/packages/core/src/Kbd/Kbd.test.tsx b/packages/core/src/Kbd/Kbd.test.tsxindex bd67db3dd8..ff664d354c 100644--- a/packages/core/src/Kbd/Kbd.test.tsx+++ b/packages/core/src/Kbd/Kbd.test.tsx@@ -58,6 +58,17 @@ describe('Kbd', () => {expect(screen.getByText('\u2318')).toBeInTheDocument(); // \u2318});+ it('shows ⌘ for meta on Apple platforms', () => {+ Object.defineProperty(navigator, 'platform', {+ value: 'MacIntel',+ configurable: true,+ });+ render(<Kbd keys="meta+k" />);+ expect(screen.getByText('\u2318')).toBeInTheDocument();+ expect(screen.queryByText('META')).not.toBeInTheDocument();+ expect(screen.queryByText('Win')).not.toBeInTheDocument();+ });+it('shows Apple modifier symbols for ctrl, alt and shift on Apple platforms', () => {Object.defineProperty(navigator, 'platform', {value: 'MacIntel',diff --git a/packages/core/src/Kbd/Kbd.tsx b/packages/core/src/Kbd/Kbd.tsxindex 445219ba84..a71ae2eaaa 100644--- a/packages/core/src/Kbd/Kbd.tsx+++ b/packages/core/src/Kbd/Kbd.tsx@@ -81,6 +81,7 @@ const KEY_DISPLAY = new Map<string, string>([const APPLE_MODIFIER_DISPLAY = new Map<string, string>([['mod', '\u2318'], // ⌘+ ['meta', '\u2318'], // ⌘ — the Command key['ctrl', '\u2303'], // ⌃['alt', '\u2325'], // ⌥['shift', '\u21E7'], // ⇧@@ -157,8 +158,8 @@ export interface KbdProps extends BaseProps<HTMLSpanElement> {/*** Keyboard shortcut string. Use "+" to separate keys.* Special keys: mod, ctrl, alt and shift (Apple symbols on Apple platforms,- * short text such as "Ctrl" elsewhere and before hydration), meta ("Win"- * text elsewhere and before hydration), enter, backspace, escape, tab, up, down, left, and right.+ * short text such as "Ctrl" elsewhere and before hydration), meta (⌘ on+ * Apple platforms, "Win" text elsewhere and before hydration), enter, backspace, escape, tab, up, down, left, and right.* Aliases: "esc" for "escape" and "return" for "enter".* Use "plus" to render a literal "+" key (e.g. "shift+plus").*