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} );