From a17d55b4da7f850f5d84990aa0978d6c2814bc27 Mon Sep 17 00:00:00 2001 From: Melloware Date: Tue, 13 Feb 2024 11:53:08 -0500 Subject: [PATCH] Fix #5942: Dropdown tabbing (#5952) --- components/lib/dropdown/Dropdown.js | 42 ++++++++++++------------ components/lib/dropdown/DropdownPanel.js | 2 ++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/components/lib/dropdown/Dropdown.js b/components/lib/dropdown/Dropdown.js index ab35d4bef2..41d4d4d5cc 100644 --- a/components/lib/dropdown/Dropdown.js +++ b/components/lib/dropdown/Dropdown.js @@ -19,7 +19,7 @@ export const Dropdown = React.memo( const [filterState, setFilterState] = React.useState(''); const [clicked, setClicked] = React.useState(false); const [focusedState, setFocusedState] = React.useState(false); - const [focusedOptionIndex, setFocusedOptionIndex] = React.useState(null); + const [focusedOptionIndex, setFocusedOptionIndex] = React.useState(-1); const [overlayVisibleState, setOverlayVisibleState] = React.useState(false); const elementRef = React.useRef(null); const overlayRef = React.useRef(null); @@ -479,8 +479,8 @@ export const Dropdown = React.memo( const onTabKey = (event, pressedInInputText = false) => { if (!pressedInInputText) { - if (overlayVisibleState && hasFocusableElements()) { - DomHandler.focus($refs.firstHiddenFocusableElementOnOverlay); + if (overlayVisibleState && !hasFocusableElements()) { + DomHandler.focus(firstHiddenFocusableElementOnOverlay.current); event.preventDefault(); } else { @@ -1014,7 +1014,7 @@ export const Dropdown = React.memo( onBlur: onInputBlur, onKeyDown: onInputKeyDown, disabled: props.disabled, - tabIndex: props.tabIndex || 0, + tabIndex: !props.disabled ? props.tabIndex || 0 : -1, ...ariaProps }, ptm('input') @@ -1045,7 +1045,7 @@ export const Dropdown = React.memo( onFocus: onEditableInputFocus, onKeyDown: onInputKeyDown, onBlur: onInputBlur, - tabIndex: !props.disabled ? props.tabIndex : -1, + tabIndex: !props.disabled ? props.tabIndex || 0 : -1, 'aria-haspopup': 'listbox', ...ariaProps }, @@ -1200,7 +1200,6 @@ export const Dropdown = React.memo( {labelElement} {clearIcon} {dropdownIcon} - } + lastFocusableElement={} sx={sx} /> - {hasTooltip && } diff --git a/components/lib/dropdown/DropdownPanel.js b/components/lib/dropdown/DropdownPanel.js index 5bfe4e3eb3..0d5f8e1860 100644 --- a/components/lib/dropdown/DropdownPanel.js +++ b/components/lib/dropdown/DropdownPanel.js @@ -342,9 +342,11 @@ export const DropdownPanel = React.memo( return (
+ {props.firstFocusableElement} {filter} {content} {footer} + {props.lastFocusableElement}
);