diff --git a/.changeset/early-candles-warn.md b/.changeset/early-candles-warn.md new file mode 100644 index 00000000..309bf21c --- /dev/null +++ b/.changeset/early-candles-warn.md @@ -0,0 +1,5 @@ +--- +'@tanstack/hotkeys': patch +--- + +fix: normalizeKeyName null check diff --git a/docs/reference/variables/KEY_DISPLAY_SYMBOLS.md b/docs/reference/variables/KEY_DISPLAY_SYMBOLS.md index 5812bd1c..3e7a1715 100644 --- a/docs/reference/variables/KEY_DISPLAY_SYMBOLS.md +++ b/docs/reference/variables/KEY_DISPLAY_SYMBOLS.md @@ -9,7 +9,7 @@ title: KEY_DISPLAY_SYMBOLS const KEY_DISPLAY_SYMBOLS: object; ``` -Defined in: [constants.ts:589](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L589) +Defined in: [constants.ts:592](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L592) Special key symbols for display formatting. diff --git a/docs/reference/variables/LINUX_MODIFIER_LABELS.md b/docs/reference/variables/LINUX_MODIFIER_LABELS.md index 4f5a3a04..ccd7bb39 100644 --- a/docs/reference/variables/LINUX_MODIFIER_LABELS.md +++ b/docs/reference/variables/LINUX_MODIFIER_LABELS.md @@ -9,4 +9,4 @@ title: LINUX_MODIFIER_LABELS const LINUX_MODIFIER_LABELS: Record; ``` -Defined in: [constants.ts:556](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L556) +Defined in: [constants.ts:559](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L559) diff --git a/docs/reference/variables/MAC_MODIFIER_LABELS.md b/docs/reference/variables/MAC_MODIFIER_LABELS.md index 9c07ae51..4d2dd13b 100644 --- a/docs/reference/variables/MAC_MODIFIER_LABELS.md +++ b/docs/reference/variables/MAC_MODIFIER_LABELS.md @@ -9,7 +9,7 @@ title: MAC_MODIFIER_LABELS const MAC_MODIFIER_LABELS: Record; ``` -Defined in: [constants.ts:522](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L522) +Defined in: [constants.ts:525](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L525) Modifier key labels for macOS display. diff --git a/docs/reference/variables/MAC_MODIFIER_SYMBOLS.md b/docs/reference/variables/MAC_MODIFIER_SYMBOLS.md index 33472299..66f0949f 100644 --- a/docs/reference/variables/MAC_MODIFIER_SYMBOLS.md +++ b/docs/reference/variables/MAC_MODIFIER_SYMBOLS.md @@ -9,7 +9,7 @@ title: MAC_MODIFIER_SYMBOLS const MAC_MODIFIER_SYMBOLS: Record; ``` -Defined in: [constants.ts:499](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L499) +Defined in: [constants.ts:502](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L502) Modifier key symbols for macOS display. diff --git a/docs/reference/variables/PUNCTUATION_KEY_DISPLAY_LABELS.md b/docs/reference/variables/PUNCTUATION_KEY_DISPLAY_LABELS.md index 95b19f55..5891854c 100644 --- a/docs/reference/variables/PUNCTUATION_KEY_DISPLAY_LABELS.md +++ b/docs/reference/variables/PUNCTUATION_KEY_DISPLAY_LABELS.md @@ -9,7 +9,7 @@ title: PUNCTUATION_KEY_DISPLAY_LABELS const PUNCTUATION_KEY_DISPLAY_LABELS: object; ``` -Defined in: [constants.ts:562](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L562) +Defined in: [constants.ts:565](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L565) ## Type Declaration diff --git a/docs/reference/variables/WINDOWS_MODIFIER_LABELS.md b/docs/reference/variables/WINDOWS_MODIFIER_LABELS.md index 559cef99..fb85e6c1 100644 --- a/docs/reference/variables/WINDOWS_MODIFIER_LABELS.md +++ b/docs/reference/variables/WINDOWS_MODIFIER_LABELS.md @@ -9,7 +9,7 @@ title: WINDOWS_MODIFIER_LABELS const WINDOWS_MODIFIER_LABELS: Record; ``` -Defined in: [constants.ts:545](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L545) +Defined in: [constants.ts:548](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/constants.ts#L548) Modifier key labels for Windows/Linux display. diff --git a/packages/hotkeys/src/constants.ts b/packages/hotkeys/src/constants.ts index 5eb21911..f89628ed 100644 --- a/packages/hotkeys/src/constants.ts +++ b/packages/hotkeys/src/constants.ts @@ -455,6 +455,9 @@ export function isSingleLetterKey(key: string): boolean { * ``` */ export function normalizeKeyName(key: string): string { + // key can be undefined in rare cases + // (browser extensions synthesizing key events, accessibility tools, certain OS/browser combinations). + if (!key) return '' // Check aliases first if (key in KEY_ALIASES) { return KEY_ALIASES[key]! diff --git a/packages/hotkeys/tests/parse.test.ts b/packages/hotkeys/tests/parse.test.ts index c4bd2bdb..40b8c8e6 100644 --- a/packages/hotkeys/tests/parse.test.ts +++ b/packages/hotkeys/tests/parse.test.ts @@ -267,6 +267,13 @@ describe('isModifierKey', () => { }) }) +describe('normalizeKeyName', () => { + it('returns empty string for falsy input (undefined coerced, empty string)', () => { + expect(normalizeKeyName('')).toBe('') + expect(normalizeKeyName(undefined as unknown as string)).toBe('') + }) +}) + describe('rawHotkeyToParsedHotkey', () => { it('should convert minimal RawHotkey (key only)', () => { const result = rawHotkeyToParsedHotkey({ key: 'Escape' })