From fed1b474598ac1c7a8f49000e607a92c7e8f2aed Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Sat, 26 Jan 2019 15:18:04 +1100 Subject: [PATCH 1/2] Fix issue where "Tab" => []. Invalid shortcuts should map to null. --- lib/ui/src/libs/shortcut.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/src/libs/shortcut.ts b/lib/ui/src/libs/shortcut.ts index 61b5588aaf46..ec4fbdeb88b9 100644 --- a/lib/ui/src/libs/shortcut.ts +++ b/lib/ui/src/libs/shortcut.ts @@ -54,7 +54,7 @@ export const eventToShortcut = (e: KeyboardEvent): Shortcut | null => { keys.push('ArrowLeft'); } - return keys; + return keys.length > 0 ? keys : null; }; export const shortcutMatchesShortcut = (inputShortcut: Shortcut, shortcut: Shortcut): boolean => { From cd47bc8c3604fdb2e80ae6db3b3658046726a3b8 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Sat, 26 Jan 2019 20:50:47 +1100 Subject: [PATCH 2/2] Fix up test --- lib/ui/src/libs/shortcut.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ui/src/libs/shortcut.test.ts b/lib/ui/src/libs/shortcut.test.ts index 85510a06cb49..5857517bde45 100644 --- a/lib/ui/src/libs/shortcut.test.ts +++ b/lib/ui/src/libs/shortcut.test.ts @@ -21,7 +21,11 @@ describe('eventToShortcut', () => { }); test('it handles enter key inputs', () => { const output = eventToShortcut(ev({ key: 'Enter' })); - expect(output).toEqual([]); + expect(output).toEqual(null); + }); + test('it handles tab key inputs', () => { + const output = eventToShortcut(ev({ key: 'Tab' })); + expect(output).toEqual(null); }); test('it handles space bar inputs', () => { const output = eventToShortcut(ev({ key: ' ' }));