Skip to content

Commit 8088b6f

Browse files
scheinrieseclaude
authored andcommitted
Fix focus loss in customize popover after Reassign and other state transitions
When the Reassign button (or any focused element inside the feedback banner) was removed from the DOM during a rec-state transition, browser focus fell to document.body. The popover's scoped KeyHandler only receives events that traverse its DOM subtree, so it went deaf to subsequent keypresses — the user saw row flash animations instead of conflict detection. Two fixes: 1. Add a use-effect that re-focuses the popover element whenever rec-state changes and focus has drifted outside the popover. 2. After refresh! reinstalls global shortcut handlers, re-suppress them if a scoped key handler is still active (refcount > 0), preventing the 50ms window where global handlers could intercept keypresses meant for the popover. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ed0d6f0 commit 8088b6f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main/frontend/components/shortcut.cljs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,13 @@
427427
(fn [new-binding]
428428
(let [binding' (if (= binding new-binding) nil new-binding)]
429429
(shortcut/persist-user-shortcut! k binding')
430-
(js/setTimeout #(do (shortcut/refresh!) (saved-cb)) 50)))
430+
(js/setTimeout #(do (shortcut/refresh!)
431+
;; refresh! reinstalls global handlers unconditionally.
432+
;; If a scoped key handler is active (popover open),
433+
;; re-suppress to prevent the new handlers from firing.
434+
(when (pos? @*global-listener-refcount)
435+
(shortcut/unlisten-all! true))
436+
(saved-cb)) 50)))
431437

432438
cancel-fn!
433439
(fn []
@@ -638,6 +644,17 @@
638644
(set-keystroke! #(util/trim-safe (str % kn)))))))))
639645
[*auto-accept-timer *fade-timer])
640646

647+
;; Re-focus the popover when rec-state changes and focus has drifted outside.
648+
;; This handles the case where a focused element (e.g., the Reassign button)
649+
;; is removed from the DOM during a state transition, causing focus to fall
650+
;; to document.body and making the popover deaf to subsequent keypresses.
651+
(hooks/use-effect!
652+
(fn []
653+
(when-let [el (rum/deref *ref-el)]
654+
(when-not (.contains el (.-activeElement js/document))
655+
(js/requestAnimationFrame #(.focus el)))))
656+
[rec-state])
657+
641658
;; === V3 LAYOUT ===
642659
[:div.shortcut-popover
643660
{:tab-index -1

0 commit comments

Comments
 (0)