fix(app): crossing focus for any element in a hidden part

Focus held by any element that a crossing hides or unmounts (button, tool,
canvas, link) goes to the shown tab, decided by the element leaving the page,
not by tag; a field still commits first; visible focus stays.
History pair: remembered field must be connected, and a pointer-down off a
field keeps it. TextField.commit compares with the latest committed value.
Open-panel axe settles and checks dialogs like the other places.

R-24: no assertion rewritten or deleted; one Chromium case and three unit
tests added.
This commit is contained in:
bchanot committed 2026-11-08 20:43:27 +01:00
1 parent a474ddaa40
commit 606f7ba268
8 files changed
+81 -18

No files matched your search

@@ -49,7 +49,7 @@ function usePress(
if (!pair?.contains(event.relatedTarget as Node | null)) forget()
}
const onPointerDown = () => {
left.current = asField(document.activeElement)
left.current = asField(document.activeElement) ?? left.current
commitFocusedField()
}
const onFocus = (event: FocusEvent<HTMLElement>) => {
@@ -58,7 +58,7 @@ function usePress(
const onClick = () => {
const field = left.current
forget()
if (field?.getAttribute('aria-invalid') === 'true') {
if (field?.isConnected && field.getAttribute('aria-invalid') === 'true') {
field.focus()
return
}
@@ -75,7 +75,7 @@ function EditableText({
const commit = () => {
const next = trim ? draft.trim() : draft
if (next !== draft) setDraft(next)
if (next === value) return
if (next === latest.current.value) return
// The unmount cleanup runs before a render brings the new value: it must not commit twice.
latest.current.value = next
onCommit(next)