From a11c444b7781c5ac62cacd0c8a048d5c53b9ed5f Mon Sep 17 00:00:00 2001 From: shadcn Date: Thu, 19 Nov 2026 22:48:45 +0000 Subject: [PATCH] fix(core): ignore a keydown with no key when matching shortcuts --- .changeset/shortcut-keydown-without-key.md | 5 +++++ packages/core/src/foundation/platform/platform.ts | 4 ++++ packages/core/test/shortcuts.test.ts | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 .changeset/shortcut-keydown-without-key.md diff --git a/.changeset/shortcut-keydown-without-key.md b/.changeset/shortcut-keydown-without-key.md new file mode 100644 index 000000000..29fff4235 --- /dev/null +++ b/.changeset/shortcut-keydown-without-key.md @@ -0,0 +1,5 @@ +--- +"@ui-sdk/core": patch +--- + +A `keydown` with no `key`, like the one Chrome's autofill sends, no longer throws in the shortcut listener on pages with a `ToastRegion` or any registered shortcut. diff --git a/packages/core/src/foundation/platform/platform.ts b/packages/core/src/foundation/platform/platform.ts index 12aa72337..0015bde18 100644 --- a/packages/core/src/foundation/platform/platform.ts +++ b/packages/core/src/foundation/platform/platform.ts @@ -238,6 +238,10 @@ function matchesShortcut( shortcut: string, apple = isApple() ) { + // Chrome's autofill sends a keydown that isn't a KeyboardEvent, with no key. + if (typeof event.key !== "string") { + return false + } const cache = parsed[+apple] let keys = cache.get(shortcut) if (!keys) { diff --git a/packages/core/test/shortcuts.test.ts b/packages/core/test/shortcuts.test.ts index 19952601b..d339efa9c 100644 --- a/packages/core/test/shortcuts.test.ts +++ b/packages/core/test/shortcuts.test.ts @@ -35,6 +35,12 @@ function key(init: { const plain = (text: string) => text.replace(/[⁦⁩]/g, "") describe("matching shortcuts", () => { + test("a keydown with no key, like Chrome's autofill sends, matches nothing", () => { + const autofill = new Event("keydown") as KeyboardEvent + expect(matchesShortcut(autofill, "f6", true)).toBe(false) + expect(matchesShortcut(autofill, "mod+k", false)).toBe(false) + }) + test("letters match the typed key, case-insensitively", () => { expect( matchesShortcut(