From 8371aa0a2a9b783e19244d9e5d3d9ba73af3b53f Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 25 Oct 2026 22:46:18 +0100 Subject: [PATCH] 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. --- .../src/components/account/AvatarSection.tsx | 22 +++++++++++++++---- apps/app/src/components/ui/ModalDialog.tsx | 17 ++++++++++---- .../unit/components.AvatarSection.test.tsx | 19 ++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/apps/app/src/components/account/AvatarSection.tsx b/apps/app/src/components/account/AvatarSection.tsx index 04a8a3d3..d93923d0 100644 --- a/apps/app/src/components/account/AvatarSection.tsx +++ b/apps/app/src/components/account/AvatarSection.tsx @@ -90,6 +90,7 @@ export default function AvatarSection() { avatar?.inFlight ? { kind: 'processing', long: false } : { kind: 'idle' }, ) const [confirmOpen, setConfirmOpen] = useState(false) + const [removing, setRemoving] = useState(false) const inputRef = useRef(null) const pollRef = useRef(null) @@ -171,16 +172,27 @@ export default function AvatarSection() { } } + const closeConfirm = () => !removing && setConfirmOpen(false) + + // The confirmation stays open until the removal settles: it closes with the + // photo gone, so focus moves past the vanished button (ModalDialog fallback). async function onRemove() { const client = getSupabaseClient() - setConfirmOpen(false) - if (!client) return + if (removing) return + if (!client) { + setConfirmOpen(false) + return + } + setRemoving(true) try { await removeAvatar(client) clearAvatar() setPhase({ kind: 'removed' }) } catch (error) { setPhase({ kind: 'failed', failure: classifyAssetError(error) }) + } finally { + setRemoving(false) + setConfirmOpen(false) } } @@ -211,6 +223,8 @@ export default function AvatarSection() { accept={ACCEPT} onChange={onPick} className="sr-only" + // Opened by the visible button: an invisible tab stop would hide the focus. + tabIndex={-1} aria-label={t('account.avatar.change')} disabled={busy} /> @@ -258,13 +272,13 @@ export default function AvatarSection() { {rejected && {t(`account.avatar.rejected.${rejected}`)}} setConfirmOpen(false)} + onClose={closeConfirm} title={t('account.avatar.remove_title')} description={

{t('account.avatar.remove_body')}

} size="sm" >
-