fix(ui): keep the photo confirmation open until the removal settles

The dialog closed before the request, focus went back to the remove button, then the button vanished and focus fell on the page. The confirmation now closes with the photo gone, Escape and Cancel wait for it, and ModalDialog restores focus after the commit so its fallback sees the opener removed. The sr-only file input leaves the tab order: it was an invisible tab stop.
This commit is contained in:
bchanot committed 2026-10-25 22:46:18 +01:00
1 parent 72ee9f9971
commit 8371aa0a2a
3 files changed
+50 -8

No files matched your search

+13 -4
View File
@@ -17,15 +17,20 @@ export interface ModalDialogProps {
children: ReactNode
}
/** Controls that can take focus: the first one on open, a fallback when the opener is gone. */
/**
* Controls in the tab order: the first one takes focus on open, and serves as a
* fallback when the opener is gone.
*/
const FOCUSABLE = [
'a[href]',
'button:not([disabled])',
'input:not([disabled]):not([type="hidden"])',
'select:not([disabled])',
'textarea:not([disabled])',
'[tabindex]:not([tabindex="-1"])',
].join(', ')
'[tabindex]',
]
.map((selector) => `${selector}:not([tabindex="-1"])`)
.join(', ')
/** Full-viewport transparent container: the consumer draws its own backdrop and panel. */
const SURFACE =
@@ -94,7 +99,11 @@ export default function ModalDialog({
dialog.querySelector<HTMLElement>(FOCUSABLE)?.focus()
return () => {
if (dialog.open) dialog.close()
restoreFocus(opener, ancestors)
// After the commit: the render that closes the dialog may remove the opener
// too. A dialog still on screen was only remounted (React StrictMode).
queueMicrotask(() => {
if (!dialog.isConnected) restoreFocus(opener, ancestors)
})
}
}, [])