Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shortcut-keydown-without-key.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions packages/core/src/foundation/platform/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/test/shortcuts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading