kgabryje commented on PR #41100:
URL: https://github.com/apache/superset/pull/41100#issuecomment-4767249136
Thanks for picking this up! I pulled the branch and tested it — the fix does
stop the cursor theft, but the guard as written introduces a first-open
regression worth addressing before merge.
**The Results search box no longer auto-focuses when the pane is opened via
its tab.**
The guard auto-focuses only when `document.activeElement` is
`null`/`<body>`/`<html>`. But opening the Results pane by clicking the
**Results** tab leaves that tab focused — it's an rc-tabs `<div role="tab">`,
which is focusable and keeps focus through the async results load. So by the
time `FilterInput` mounts, `document.activeElement` is the tab (not `<body>`),
and the auto-focus is skipped — the exact "auto-focus on first open" the test
plan calls out.
Repro (Explore, any chart that returns rows):
1. Open Explore with the Results pane closed.
2. Click the **Results** tab to open it.
3. The search box mounts but doesn't receive focus.
Reading `document.activeElement` the moment the search input mounts:
- on this branch → `div#rc-tabs-0-tab-results` (the tab) → search never
focuses
- with the narrower guard below → `input[placeholder="Search"]` → focuses as
intended
**Suggested tweak** — skip auto-focus only when an *editable* element holds
focus (which matches the PR description). The legend-margin control is an
`<input>`, so it stays protected; a focused tab/button isn't editable, so
first-open focus is restored:
```js
const activeEl = document.activeElement;
const editableFocused =
activeEl instanceof HTMLElement &&
(activeEl.tagName === 'INPUT' ||
activeEl.tagName === 'TEXTAREA' ||
activeEl.isContentEditable);
if (!editableFocused) {
inputRef.current.focus();
}
```
And a test idea: the new test covers the "don't steal focus" case nicely —
it'd be worth also asserting auto-focus *does* fire when nothing (or a
non-editable opener like a `button`/`[role="tab"]`) has focus, to lock in the
first-open behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]