Repository navigation
Fix dcc.Dropdown Shift+Tab focus trap on hidden focus-target input - #4207
SalmanBarkat wants to merge 4 commits into
Conversation
T4rk1n
left a comment
There was a problem hiding this comment.
Setting the hidden input to tabIndex=-1 when the trigger gets focus covers the click, Escape and pick-an-option cases from #4191. I checked the focus order in headless Chrome: Shift+Tab now goes straight to the previous element, and Tab still goes through the dropdown normally both ways.
One ask before merge: the jest tests fire synthetic focus/blur events, so they never run the browser's actual Tab order, which is where this bug lives. See the inline comment.
Small cleanup, not blocking: now that the button's onFocus sets tabIndex = -1, the same line in the input's onFocus handler is redundant and can go.
| expect(focusTarget.tabIndex).toBe(0); | ||
|
|
||
| // Simulates clicking the trigger or Radix returning focus after Escape/selection. | ||
| fireEvent.focus(trigger); |
There was a problem hiding this comment.
fireEvent.focus only calls the handler. It doesn't show that a real Shift+Tab skips the hidden input. These assertions would pass even if the browser chose where focus goes after the blur restores tabIndex=0, and that ordering is what this bug is about. Can you add an integration test in tests/integration/dropdown/test_a11y.py next to test_a11y012c? Click the dropdown, press Escape, Shift+Tab, then assert document.activeElement.id == "before". A second case that picks an option with Enter before the Shift+Tab would cover the other path in the issue. That test should fail on dev and pass here.
…ant focus handler assignment
…m/SalmanBarkat/dash into fix/4191-dropdown-shift-tab-focus
|



Fixes #4191
Root Cause
\Dropdown\ renders a hidden <input className=dash-dropdown-focus-target aria-hidden=true>\ with \ abIndex={0}\ right before the trigger <button tabIndex={-1}>\ so Safari includes the dropdown in the \Tab\ order.
Previously, \dummyInput.tabIndex = -1\ was only cleared inside the hidden input's own \onFocus\ handler, while the trigger button's \onBlur\ always restored \dummyInput.tabIndex = 0. Whenever focus landed directly on the trigger <button>\ without first passing through the hidden input (for example after clicking the trigger, closing the popover with \Escape, or selecting an option with \closeOnSelect), the hidden input remained at \ abIndex={0}. Pressing \Shift+Tab\ from the trigger <button>\ then moved focus back onto the hidden \�ria-hidden\ input (with
elatedTarget === dropdownContainerRef.current), trapping keyboard focus there.
What Changed
Verification
pm run test:jest\ in \components/dash-core-components: 10 passed test suites, 96 passed tests (93 existing + 3 new tests in \ocusTarget.test.tsx).
px eslint src/fragments/Dropdown.tsx tests/unit/dropdown/focusTarget.test.tsx: 0 errors.
Contributor Checklist
ext\ (feature, new API, breaking change), see Which branch to target