From c148dcc71838b3747c025e2301e98153bb14e63e Mon Sep 17 00:00:00 2001 From: InstaZDLL Date: Fri, 16 Oct 2026 12:45:56 +0200 Subject: [PATCH] fix(ui): keep a clicked row ringless after leaving and coming back to the window Minimising or leaving the window took focus from the clicked row, which dropped its pointer-focus mark; on return it took focus again, and with a key as the last input it came back unmarked and ringed. The mark is now dropped only once focus has moved elsewhere in the page, and focus that returns from outside the page keeps the mark it had. Refs #866 --- src/lib/inputModality.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib/inputModality.ts b/src/lib/inputModality.ts index c3b990f4..7b16f670 100644 --- a/src/lib/inputModality.ts +++ b/src/lib/inputModality.ts @@ -53,8 +53,17 @@ if (typeof window !== "undefined") { (event) => { const target = event.target; if (!(target instanceof HTMLElement)) return; - if (last === "pointer") target.dataset[MARK] = ""; - else delete target.dataset[MARK]; + if (last === "pointer") { + target.dataset[MARK] = ""; + } else if (event.relatedTarget !== null) { + // Focus moved here from another element by a key: a keyboard + // focus, ring and all. With no `relatedTarget` it came back from + // outside the page — the window was minimised or left — onto + // the element that had it, which keeps whatever mark it had: the + // last key pressed before leaving says nothing about how it was + // focused. + delete target.dataset[MARK]; + } }, true, ); @@ -62,7 +71,14 @@ if (typeof window !== "undefined") { "focusout", (event) => { const target = event.target; - if (target instanceof HTMLElement) delete target.dataset[MARK]; + if (!(target instanceof HTMLElement)) return; + // Only once focus has really gone elsewhere in the page. When the + // whole window loses focus, the element stays the active one and + // gets it back on return; dropping the mark here is what put the + // ring on a clicked row after minimising and restoring (#866). + setTimeout(() => { + if (document.activeElement !== target) delete target.dataset[MARK]; + }, 0); }, true, );