From 76c760c2c23a642bdcfb09f4c37ff3d685c76890 Mon Sep 17 00:00:00 2001 From: Johan Lahti Date: Fri, 31 Mar 2023 16:03:11 +0200 Subject: [PATCH] refactor: set tabIndex -1 and leave esc alone --- apis/nucleus/src/components/listbox/ListBoxInline.jsx | 2 +- .../__tests__/list-box-keyboard-navigation.test.js | 4 ++-- .../interactions/listbox-keyboard-navigation.js | 11 +++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/apis/nucleus/src/components/listbox/ListBoxInline.jsx b/apis/nucleus/src/components/listbox/ListBoxInline.jsx index d610a4155..fb01bff6e 100644 --- a/apis/nucleus/src/components/listbox/ListBoxInline.jsx +++ b/apis/nucleus/src/components/listbox/ListBoxInline.jsx @@ -273,7 +273,7 @@ function ListBoxInline({ options, layout }) { { expect(currentTarget.focus).not.toHaveBeenCalled(); expect(currentTarget.blur).not.toHaveBeenCalled(); - expect(event.preventDefault).toHaveBeenCalledTimes(1); + expect(event.preventDefault).not.toHaveBeenCalled; }); test('should change focus with Escape on a listbox', () => { const currentTarget = { @@ -374,7 +374,7 @@ describe('keyboard navigation', () => { expect(currentTarget.blur).not.toHaveBeenCalled(); expect(currentTarget.focus).not.toHaveBeenCalled(); - expect(event.preventDefault).toHaveBeenCalledTimes(1); + expect(event.preventDefault).not.toHaveBeenCalled; }); test('not matched key should not call event methods', () => { const element = createElement(0); diff --git a/apis/nucleus/src/components/listbox/interactions/listbox-keyboard-navigation.js b/apis/nucleus/src/components/listbox/interactions/listbox-keyboard-navigation.js index 24b5b8169..5a3d973f7 100644 --- a/apis/nucleus/src/components/listbox/interactions/listbox-keyboard-navigation.js +++ b/apis/nucleus/src/components/listbox/interactions/listbox-keyboard-navigation.js @@ -230,7 +230,7 @@ export function getListboxInlineKeyboardNavigation({ if (!keyboard.enabled) { // Other keys should not be handled unless keyboard is enabled. - return undefined; + return; } const container = event.currentTarget.closest('.listbox-container'); @@ -247,29 +247,24 @@ export function getListboxInlineKeyboardNavigation({ } else if (shiftKey) { keyboard.blur(true); } else { - focusSearch(container) || focusRow(container); + break; } prevent(); break; case KEYS.ENTER: case KEYS.SPACE: if (!event.target.classList.contains('listbox-container')) { - return undefined; // don't mess with keydown handlers within the listbox (e.g. row seletion) + break; // don't mess with keydown handlers within the listbox (e.g. row seletion) } keyboard.focus(); prevent(); break; case KEYS.ESCAPE: blur(event); - prevent(); break; - case KEYS.ARROW_LEFT: - case KEYS.ARROW_RIGHT: - return undefined; // let it propagate to top-level default: break; } - return undefined; }; const focusOnHoverDisabled = () => {