Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5942: Dropdown tabbing #5952

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -1200,42 +1200,42 @@ export const Dropdown = React.memo(
{labelElement}
{clearIcon}
{dropdownIcon}
<span {...firstHiddenFocusableElementProps}></span>
<DropdownPanel
hostName="Dropdown"
ref={overlayRef}
visibleOptions={visibleOptions}
virtualScrollerRef={virtualScrollerRef}
{...props}
appendTo={appendTo}
onClick={onPanelClick}
onOptionClick={onOptionClick}
focusedOptionIndex={focusedOptionIndex}
setFocusedOptionIndex={setFocusedOptionIndex}
cx={cx}
filterValue={filterState}
hasFilter={hasFilter}
onFilterClearIconClick={onFilterClearIconClick}
resetFilter={resetFilter}
onFilterInputKeyDown={onFilterInputKeyDown}
onFilterInputChange={onFilterInputChange}
getOptionLabel={getOptionLabel}
getOptionRenderKey={getOptionRenderKey}
isOptionDisabled={isOptionDisabled}
focusedOptionIndex={focusedOptionIndex}
getOptionGroupChildren={getOptionGroupChildren}
getOptionGroupLabel={getOptionGroupLabel}
getOptionGroupRenderKey={getOptionGroupRenderKey}
isSelected={isSelected}
getOptionLabel={getOptionLabel}
getOptionRenderKey={getOptionRenderKey}
getSelectedOptionIndex={getSelectedOptionIndex}
hasFilter={hasFilter}
in={overlayVisibleState}
isOptionDisabled={isOptionDisabled}
isSelected={isSelected}
onClick={onPanelClick}
onEnter={onOverlayEnter}
onEntered={onOverlayEntered}
onExit={onOverlayExit}
onExited={onOverlayExited}
onFilterClearIconClick={onFilterClearIconClick}
onFilterInputChange={onFilterInputChange}
onFilterInputKeyDown={onFilterInputKeyDown}
onOptionClick={onOptionClick}
ptm={ptm}
cx={cx}
resetFilter={resetFilter}
setFocusedOptionIndex={setFocusedOptionIndex}
firstFocusableElement={<span {...firstHiddenFocusableElementProps}></span>}
lastFocusableElement={<span {...lastHiddenFocusableElementProps}></span>}
sx={sx}
/>
<span {...lastHiddenFocusableElementProps}></span>
</div>
{hasTooltip && <Tooltip target={elementRef} content={props.tooltip} pt={ptm('tooltip')} {...props.tooltipOptions} />}
</>
Expand Down
2 changes: 2 additions & 0 deletions components/lib/dropdown/DropdownPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,11 @@ export const DropdownPanel = React.memo(
return (
<CSSTransition nodeRef={ref} {...transitionProps}>
<div ref={ref} {...panelProps}>
{props.firstFocusableElement}
{filter}
{content}
{footer}
{props.lastFocusableElement}
</div>
</CSSTransition>
);
Expand Down
Loading