Repository navigation
[charts] Hide focus indicator when the chart loses focus - #23213
Conversation
…le element `focusout` only cleared the keyboard focus state when `relatedTarget` was a Node. Clicking outside the chart on a non-focusable element gives a null `relatedTarget`, so the focus indicator stayed visible.
Deploy previewBundle size
PerformanceTotal duration: 1,605.01 ms -83.76 ms(-5.0%, p<0.001) | Renders: 63 (+0) | Paint: 2,162.18 ms -319.30 ms(-12.9%)
…and 2 more (+19 within noise) — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
LukasTy
left a comment
There was a problem hiding this comment.
Nice fix. 👍
A side note: WDYT about introducing an initially focused element?
Currently, if you focus on a chart, there is no visual indicator in it to indicate that it happened until you start navigating the chart.
Could be a good idea. We are generally improving the accessibility, so it makes sense. There is this PR #23195 that addes "clicking to focus". I'll keep it in mind |
Problem
When navigating a chart with the keyboard, clicking outside the chart on a non-focusable element (empty page area, a plain
div, ...) left the focus indicator visible.focusoutclears the keyboard focus state only whenrelatedTargetis aNode:A click on a non-focusable element gives
relatedTarget === null, so the condition was never met andkeyboardNavigation.isFocusedstayedtrue. The bug was invisible in the existing test because it clicks a<button>, which is focusable and therefore provides arelatedTarget.Fix
Invert the guard: bail out only when focus stays inside the chart. Every other case, including a
nullrelatedTarget, clears the focus state.Tests
Added a browser test that clicks a non-focusable element outside the chart and asserts the focus indicator is gone. It fails on
masterand passes with the fix.