You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Spike] Investigate a feasible programmatic focus detection #9549
The purpose of this task is to investigate whether we can easily detect if focus was made programmatically (.focus()) or through user interaction (mouse, keyboard).
Context
Current behavior
Focus return triggers unwanted tooltips. Closing a modal or popover returns focus to the trigger, which unconditionally fires the tooltip. When an overlay closes and the browser returns focus to the trigger, the tooltip fires immediately. Disorienting after confirmation modals.
Expected behavior
Focus return does not trigger tooltips. Closing a modal, flyout, or popover does not re-show the tooltip on the trigger element.
Notes
For modal, popover, etc. we know what the trigger is and when we are closing these components. How do we return focus to the trigger while communicating not to show the tooltip?
Acceptance criteria
The real question is answered: is it really a problem? What cases are these? Do we always want to not show the tooltip on return focus?... That's 3 questions.
Both of these are valid conclusions:
there's a feasible solution that addressed the problem,
the solutions are too complex for the value they offer.
changed the title [-][Spike] Investigate if there's a feasible way to detect programatic return focus[/-][+][Spike] Investigate a feasible programmatic focus detection[/+]on Apr 1, 2026
toolTipManager.registerTooltip() calls all previously registered hideToolTip callbacks before registering the new one; previously raised on e.g. #5883
Keyboard-focused + mouse moves out → tooltip stays
✅ Yes, 1.4.13 Persistent (focus trigger still active)
Yes
onMouseOut checks !this.state.hasFocus before calling hideToolTip()
Mouse over + Tab away → tooltip closes
⚠️ Violation, SC 1.4.13 Persistent requires content to remain visible while the hover trigger is active; Tab removes focus but the mouse is still over the trigger
Rarely implemented, not an expected behavior
onBlur → setState({ hasFocus: false }) → hideToolTip() unconditionally, regardless of mouse position
"A mechanism is available to dismiss the additional content without moving pointer hover or keyboard focus, unless the additional content communicates an input error or does not obscure or replace other content."
"If pointer hover can trigger the additional content, then the pointer can be moved over the additional content without the additional content disappearing."
These requirements are not about hover/focus interactions but are still required to conform with a11y guidelines:
Requirement
Source
Met?
Notes
Tooltip must not contain interactive content (links, buttons)
WAI-ARIA APG
⚠️ Not enforced
EUI does not restrict what content prop accepts; consumers can pass interactive elements, which would be inaccessible; we can enforce with ESLint rule
Tooltip must not receive keyboard focus
WAI-ARIA APG
✅ Yes
EuiToolTipPopover has no tabIndex; portalled but not in the tab order
Color contrast of tooltip text must meet 4.5:1 (normal text) or 3:1 (large text)
SC 1.4.3 (Level AA)
✅ Yes
-
The tooltip must not obscure the trigger element it describes
SC 1.4.13 Dismissible intent
⚠️ Not guaranteed
Position is calculated via findPopoverPosition with a default offset of 16px but edge cases near viewport boundaries may cause overlap
What we are trying to fix
Tooltip should not re-open when focus is programmatically returned to the trigger
When a modal, flyout, popover or any focus trap closes, focus is typically returned to the element that triggered it. If that element has a tooltip, the tooltip currently re-opens even though the user did not intentionally navigate to it. This is disruptive for mouse users who clicked to open an overlay, then closed it.
WCAG SC 1.4.13 does not explicitly address programmatic focus return. The requirement to show on focus applies to intentional keyboard navigation; suppressing the tooltip for programmatic returns is a UX improvement that does not conflict with any normative criterion, provided it is not suppressed for keyboard users who deliberately navigate to the trigger (e.g. Tab).
WCAG requirements relevant to the fix
Requirement
Impact on fix
SC 1.4.13 Persistent
Fix must not suppress tooltip for keyboard-navigated focus
SC 1.4.13 Dismissible
Any solution must preserve Escape-to-dismiss behavior
ARIA - Keyboard focus triggers tooltip
Any solution must continue showing the tooltip when the user tabs to the trigger intentionally
Potential solutions
Viable candidates
1. relatedTarget detached node check
In onFocus check whether event.relatedTarget is no longer in the document. If the overlay unmounted before returning focus, the previous active element is detached and isConnected is false.
Covers: Any overlay, EUI or third-party, that unmounts its DOM before returning focus (EuiModal, most EuiPopover usages).
Does not cover:
EuiFlyout with includeFixedHeadersInFocusTrap or unmounted-but-kept-in-tree patterns, relatedTarget is still connected.
First-ever page focus - relatedTarget is null, which also passes the check (tooltip shows), so no special handling needed there.
Race condition: if React returns focus synchronously during cleanup but the overlay's DOM is removed asynchronously (e.g. after a state flush), isConnected may still be true at the moment onFocus fires.
2. Tab keydown tracking
Add a module-level flag in tool_tip_manager.ts driven by a single document keydown listener. Set true on Tab/Shift+Tab, reset to false after the next focus event is consumed.
// onFocus in EuiToolTipconstonFocus=()=>{if(consumeLastKeyWasTab())showToolTip();};
Covers: All overlays for mouse users (no Tab pressed → tooltip suppressed). Keyboard users who Tab to the trigger always get the tooltip.
Does not cover: Keyboard user presses Escape to close a modal → focus returns to trigger → last key was Escape, not Tab → tooltip suppressed. The user navigated to the trigger via keyboard at some earlier point but no Tab immediately preceded focus return. Suboptimal for keyboard-only users, though WCAG does not require re-showing on programmatic return.
3. isMouseOver + Tab keydown combo (BEST)
Combines the isMouseOver ref (from mouseenter/mouseleave on the anchor) with the lastKeyWasTab flag above. Show the tooltip in onFocus only if either signal is active. Also fix onBlur to only hide when the mouse is not over the trigger, this simultaneously fixes the SC 1.4.13 Persistent violation.
Mouse user hovers → focus returns programmatically → isMouseOver is false → tooltip suppressed ✅
Keyboard user Tabs to trigger → lastKeyWasTab is true → tooltip shows ✅
Mouse user hovers + Tabs away → isMouseOver is true in onBlur → tooltip stays (fixes SC 1.4.13 Persistent) ✅
Does not cover: Keyboard user presses Escape to close a modal → lastKeyWasTab is false, isMouseOver is false → tooltip suppressed. Same trade-off as solution 2 — acceptable, WCAG does not require re-showing on programmatic return.
4. :focus-visible check (ACCEPTABLE)
Works for mouse users but fails for keyboard navigation. When a keyboard user presses Escape to close a modal, the browser's input modality is still "keyboard", so :focus-visible is true on the programmatically returned focus - the tooltip shows. Browser handling of :focus-visible on programmatic .focus() calls is also not normatively specified and differs across browsers.
EDIT: After further investigation this can be absolutely acceptable. Checked in Chrome (which has a tooltip re-open issue), Safari (which doesn't have this issue with or without the fix) and Firefox (which has a tooltip re-open issue). For mouse users, the tooltip doesn't show on focus return, for keyboard users it does.
Requires coordinated changes
5. Shared flag from EUI overlay components
Before returning focus, each EUI overlay sets a module-level isFocusReturnPending flag. EuiToolTip.onFocus checks and clears it.
The most reliable and explicit approach - no heuristics, no race conditions but requires changes to EuiModal, EuiFlyout, EuiPopover, EuiFocusTrap, and any other component that manages focus return. Does not cover third-party focus traps. Creates coupling between overlay components and tooltip that would need to be maintained as new overlay components are added.
Ruled out
6. Mouse position tracking alone
Cannot work standalone. A keyboard user Tabbing to the trigger has the mouse somewhere unrelated on the screen - isMouseOver would be false on focus - tooltip never shows. This is a WCAG violation (keyboard focus must trigger the tooltip). Only valid as part of solution 3.
7. triggerOnFocus prop
Not a solution - a manual escape hatch. Requires updating every EuiButtonIcon + overlay callsite individually. Any site that omits it retains the broken behavior. Setting it globally to false would violate the WCAG keyboard focus requirement.
Summary
There is an existing unaddressed WCAG gap: SC 1.4.13 Persistent is currently violated when the user has the mouse over the trigger and presses Tab to move focus elsewhere — the tooltip closes unconditionally in onBlur.
The best solution is solution 3 (isMouseOver + Tab keydown tracking) because:
It fixes UX-3 for both mouse and keyboard users without touching any overlay component.
It simultaneously fixes the SC 1.4.13 Persistent gap (mouse over + Tab away) at no extra cost.
It works for any focus trap, EUI or third-party.
We might get away with :focus-visible check which is the simplest if we can accept the trade-off that the tooltip is still showing on keyboard navigation (e.g. pressing Escape to exit the modal/flyout).
Activity
[-][Spike] Investigate if there's a feasible way to detect programatic return focus[/-][+][Spike] Investigate a feasible programmatic focus detection[/+]ghudgins commentedon Apr 7, 2026
thanks @weronikaolejniczak - this is exactly what i'm hoping we can fix broadly. it'd close a bunch of age old papercuts if we can. i'm hopeful!
weronikaolejniczak commentedon Apr 7, 2026
@ghudgins if you have them handy, could you drop them here in the comment? 🙏🏻 Thank you, Graham!
ghudgins commentedon Apr 7, 2026
oh I don't have any issues to link, but I've seen this issue forever and I think the date picker pushed me over the edge.
weronikaolejniczak commentedon Apr 8, 2026
Current behavior
focusevent → tooltip showsonFocus→setState({ hasFocus: true })→showToolTip()→setTimeout(250ms)→setState({ visible: true })+toolTipManager.registerTooltip()onMouseOver→showToolTip()→ same timeout flowtoolTipManager.registerTooltip()calls all previously registeredhideToolTipcallbacks before registering the new one; previously raised on e.g. #5883onMouseOutchecks!this.state.hasFocusbefore callinghideToolTip()onBlur→setState({ hasFocus: false })→hideToolTip()unconditionally, regardless of mouse positiononEscapeKey→setState({ hasFocus: false })→hideToolTip()hasFocus: true;onMouseOutchecks!hasFocus→ does not callhideToolTip()onFocusflow, no distinction between intentional keyboard focus and programmatic focus returnWCAG requirements
role="tooltip"set onEuiToolTipPopovercloneElementwhenisVisible && idonEscapeKeyhandles thisWCAG references
Additional notes
These requirements are not about hover/focus interactions but are still required to conform with a11y guidelines:
contentprop accepts; consumers can pass interactive elements, which would be inaccessible; we can enforce with ESLint ruleEuiToolTipPopoverhas notabIndex; portalled but not in the tab orderfindPopoverPositionwith a default offset of16pxbut edge cases near viewport boundaries may cause overlapWhat we are trying to fix
Tooltip should not re-open when focus is programmatically returned to the trigger
When a modal, flyout, popover or any focus trap closes, focus is typically returned to the element that triggered it. If that element has a tooltip, the tooltip currently re-opens even though the user did not intentionally navigate to it. This is disruptive for mouse users who clicked to open an overlay, then closed it.
WCAG SC 1.4.13 does not explicitly address programmatic focus return. The requirement to show on focus applies to intentional keyboard navigation; suppressing the tooltip for programmatic returns is a UX improvement that does not conflict with any normative criterion, provided it is not suppressed for keyboard users who deliberately navigate to the trigger (e.g. Tab).
WCAG requirements relevant to the fix
Potential solutions
Viable candidates
1.
relatedTargetdetached node checkIn
onFocuscheck whetherevent.relatedTargetis no longer in the document. If the overlay unmounted before returning focus, the previous active element is detached andisConnectedisfalse.Covers: Any overlay, EUI or third-party, that unmounts its DOM before returning focus (
EuiModal, mostEuiPopoverusages).Does not cover:
EuiFlyoutwithincludeFixedHeadersInFocusTrapor unmounted-but-kept-in-tree patterns,relatedTargetis still connected.relatedTargetisnull, which also passes the check (tooltip shows), so no special handling needed there.isConnectedmay still betrueat the momentonFocusfires.2.
Tabkeydown trackingAdd a module-level flag in
tool_tip_manager.tsdriven by a singledocumentkeydown listener. SettrueonTab/Shift+Tab, reset tofalseafter the nextfocusevent is consumed.Covers: All overlays for mouse users (no Tab pressed → tooltip suppressed). Keyboard users who Tab to the trigger always get the tooltip.
Does not cover: Keyboard user presses Escape to close a modal → focus returns to trigger → last key was Escape, not Tab → tooltip suppressed. The user navigated to the trigger via keyboard at some earlier point but no Tab immediately preceded focus return. Suboptimal for keyboard-only users, though WCAG does not require re-showing on programmatic return.
3.
isMouseOver+Tabkeydown combo (BEST)Combines the
isMouseOverref (frommouseenter/mouseleaveon the anchor) with thelastKeyWasTabflag above. Show the tooltip inonFocusonly if either signal is active. Also fixonBlurto only hide when the mouse is not over the trigger, this simultaneously fixes the SC 1.4.13 Persistent violation.Covers:
isMouseOveris false → tooltip suppressed ✅lastKeyWasTabis true → tooltip shows ✅isMouseOveris true inonBlur→ tooltip stays (fixes SC 1.4.13 Persistent) ✅Does not cover: Keyboard user presses Escape to close a modal →
lastKeyWasTabis false,isMouseOveris false → tooltip suppressed. Same trade-off as solution 2 — acceptable, WCAG does not require re-showing on programmatic return.4.
:focus-visiblecheck (ACCEPTABLE)Works for mouse users but fails for keyboard navigation. When a keyboard user presses Escape to close a modal, the browser's input modality is still "keyboard", so
:focus-visibleistrueon the programmatically returned focus - the tooltip shows. Browser handling of:focus-visibleon programmatic.focus()calls is also not normatively specified and differs across browsers.EDIT: After further investigation this can be absolutely acceptable. Checked in Chrome (which has a tooltip re-open issue), Safari (which doesn't have this issue with or without the fix) and Firefox (which has a tooltip re-open issue). For mouse users, the tooltip doesn't show on focus return, for keyboard users it does.
Requires coordinated changes
5. Shared flag from EUI overlay components
Before returning focus, each EUI overlay sets a module-level
isFocusReturnPendingflag.EuiToolTip.onFocuschecks and clears it.The most reliable and explicit approach - no heuristics, no race conditions but requires changes to
EuiModal,EuiFlyout,EuiPopover,EuiFocusTrap, and any other component that manages focus return. Does not cover third-party focus traps. Creates coupling between overlay components and tooltip that would need to be maintained as new overlay components are added.Ruled out
6. Mouse position tracking alone
Cannot work standalone. A keyboard user Tabbing to the trigger has the mouse somewhere unrelated on the screen -
isMouseOverwould befalseon focus - tooltip never shows. This is a WCAG violation (keyboard focus must trigger the tooltip). Only valid as part of solution 3.7.
triggerOnFocuspropNot a solution - a manual escape hatch. Requires updating every
EuiButtonIcon+ overlay callsite individually. Any site that omits it retains the broken behavior. Setting it globally tofalsewould violate the WCAG keyboard focus requirement.Summary
There is an existing unaddressed WCAG gap: SC 1.4.13 Persistent is currently violated when the user has the mouse over the trigger and presses Tab to move focus elsewhere — the tooltip closes unconditionally in
onBlur.The best solution is solution 3 (
isMouseOver+Tabkeydown tracking) because:We might get away with
:focus-visiblecheck which is the simplest if we can accept the trade-off that the tooltip is still showing on keyboard navigation (e.g. pressingEscapeto exit the modal/flyout).