fix(editor): never drop a refused draft silently on a read-only flip

Drop slot is tile-local state; the edit view cleanup reports every pending
field (FIELDS order) only when some are pending. The tile shows a warning
note and says it once in the live region; it ends on toggle, Terminer or a
newer drop. LeaveGuard returns all refused fields (forced panel close names
them all). Pin follows editingKey through read-only; reset re-pins it.
Read-only toggle ends edit and collapses. Flip focus goes to the tile header.

R-24 mapping:
- view test "keeps its index ... read-only (M3)": renamed, same assertion
- view test "is suspended in read-only ...": rewritten as "stays pinned in
  read-only" (pin kept, tile still shown after a search); toggle test added
- reset test extended: tile in edit stays pinned through the reset
- new editor-references-flip.test.tsx covers (a)-(g); (h) is a stated limit
This commit is contained in:
bchanot committed 2026-11-13 11:11:51 +01:00
1 parent 52aac41472
commit 3303530717
15 files changed
+543 -94

No files matched your search

+17 -4
View File
@@ -162,16 +162,29 @@ export function heldElement(): HTMLElement | null {
: null
}
/** The disclosure button of the reference tile that holds `element`, if any. */
export function tileHeaderOf(element: HTMLElement | null): HTMLElement | null {
const tile = element?.closest('[data-reference-tile]')
return tile?.querySelector<HTMLElement>('[data-tile-header]') ?? null
}
/**
* After the render that hides parts: `held` (taken before) that left the page or sits in a
* hidden part hands its focus to the shown tab; one still shown gets its focus back when
* the commit blurred it (never `body`), and the tab takes it if the element refuses.
* hidden part hands its focus to `home` (the header of the tile it was in) when that is
* still shown, else to the shown tab; one still shown gets its focus back when the commit
* blurred it (never `body`), and the tab takes it if the element refuses.
*/
export function refocusIfHidden(held: HTMLElement | null): void {
export function refocusIfHidden(
held: HTMLElement | null,
home: HTMLElement | null = null,
): void {
if (!held) return
const gone = !held.isConnected || held.closest('[hidden]')
if (!gone && document.activeElement !== held) held.focus()
if (gone || document.activeElement !== held) focusActiveTab()
if (!gone && document.activeElement === held) return
const homeShown = home?.isConnected && !home.closest('[hidden]')
if (homeShown) home.focus()
if (!homeShown || document.activeElement !== home) focusActiveTab()
}
/**
+10 -2
View File
@@ -1,5 +1,10 @@
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { commitFocusedField, heldElement, refocusIfHidden } from './focusRequest'
import {
commitFocusedField,
heldElement,
refocusIfHidden,
tileHeaderOf,
} from './focusRequest'
import { MIN_EDIT_WIDTH } from './mode'
/** The tab lists of board 05: all, the five of 640 px and over, the two below. */
@@ -22,6 +27,7 @@ export function useTabTier(): TabTier {
const [tier, setTier] = useState<TabTier>(() => tierOf(window.innerWidth))
const previous = useRef(tier)
const held = useRef<HTMLElement | null>(null)
const home = useRef<HTMLElement | null>(null)
useEffect(() => {
const update = () => {
const next = tierOf(window.innerWidth)
@@ -29,6 +35,7 @@ export function useTabTier(): TabTier {
// after the hide would be too late, a hidden field keeps no focus event.
if (crossesEditWidth(previous.current, next)) {
held.current = heldElement()
home.current = tileHeaderOf(held.current)
commitFocusedField()
}
previous.current = next
@@ -40,8 +47,9 @@ export function useTabTier(): TabTier {
}, [])
// The new tier is rendered: a focus left in a hidden part goes to the shown tab.
useLayoutEffect(() => {
refocusIfHidden(held.current)
refocusIfHidden(held.current, home.current)
held.current = null
home.current = null
}, [tier])
return tier
}