fix(editor): Task 2 review round 1, trace calls, form hooks, keyboard proof

This commit is contained in:
bchanot committed 2026-11-13 19:39:29 +01:00
1 parent c893dec60b
commit b703333b20
15 files changed
+476 -261

No files matched your search

+13 -1
View File
@@ -211,7 +211,19 @@ export function refocusIfHidden(
if (!gone && document.activeElement === held) return
const homeShown = home?.isConnected && !home.closest('[hidden]')
if (homeShown) home.focus()
if (!homeShown || document.activeElement !== home) focusActiveTab()
if (homeShown && document.activeElement === home) return
// Under a modal dialog the tab row is inert: the focus stays in the top dialog.
if (!focusTopDialog()) focusActiveTab()
}
/** The first control of the top open dialog takes the focus; false when none is open. */
function focusTopDialog(): boolean {
const top = [...document.querySelectorAll<HTMLElement>('dialog[open]')].at(-1)
const control = top?.querySelector<HTMLElement>(
'button:not([disabled]), input:not([disabled]), select, textarea, a[href]',
)
control?.focus()
return control !== undefined && document.activeElement === control
}
/**
-2
View File
@@ -258,7 +258,6 @@ export function navigationReducer(
case 'create_finding':
return createFinding(state, { kind: action.kind, parent: action.parent })
case 'close_finding':
console.trace('CLOSE_FINDING')
return { ...state, finding: null }
case 'open_citations':
return openCitations(state, action.citedBy)
@@ -269,7 +268,6 @@ export function navigationReducer(
case 'go_to':
return goTo(state, action.target)
case 'restore_view':
console.trace('RESTORE', JSON.stringify(action.view.finding))
return restoreView(state, action.view)
case 'focus_consumed':
return state.focus?.serial === action.serial
+13 -4
View File
@@ -168,7 +168,7 @@ function useLiveRegion() {
waiting.current()
waiting.current = afterModalsClosed(() => {
const joined = queued.current.splice(0).join('. ')
setLive((previous) => (previous === joined ? `${joined} ` : joined))
setLive((previous) => (previous === joined ? `${joined} ` : joined))
})
}, [])
return { live, announce }
@@ -267,7 +267,12 @@ interface LayerContext {
* own confirmation and the close is cancelled. `replaceFinding` is the move that is no
* Back step: the creation turned into its element, a deletion, an element that vanished.
*/
function useFindingLayer({ dispatch, announce, guards, mark }: LayerContext) {
function useFindingLayer(ctx: LayerContext) {
return { ...useFindingOpening(ctx), ...useFindingClosing(ctx) }
}
/** The moves that add the layer: a dialog for an element, a creation form. */
function useFindingOpening({ dispatch, mark }: LayerContext) {
const openFinding = useCallback(
(key: ElementKey) => {
mark()
@@ -282,9 +287,13 @@ function useFindingLayer({ dispatch, announce, guards, mark }: LayerContext) {
},
[dispatch, mark],
)
return { openFinding, startFinding }
}
/** The moves that take it away: a user close, and the replace that is no Back step. */
function useFindingClosing({ dispatch, announce, guards, mark }: LayerContext) {
const closeFinding = useCallback(
(forced = false) => {
console.trace('closeFinding', forced)
if (!guards.askAll(forced).allowed) return false
mark()
dispatch({ type: 'close_finding' })
@@ -301,7 +310,7 @@ function useFindingLayer({ dispatch, announce, guards, mark }: LayerContext) {
},
[guards, announce, dispatch, mark],
)
return { openFinding, startFinding, closeFinding, replaceFinding }
return { closeFinding, replaceFinding }
}
/** The citations sheet over the finding dialog: opened from a finding node only. */