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" >
-