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

@@ -157,6 +157,25 @@ describe('AvatarSection', () => {
expect(screen.queryByRole('img')).toBeNull()
})
it('keeps the confirmation open until the removal settles, then focuses the photo control', async () => {
useAuthStore.setState({ avatarUrl: 'blob:current', avatar: { clean: fakeAssetRow(), inFlight: null, lastRejected: null } })
let settle: (value: { data: number; error: null }) => void = () => {}
vi.spyOn(fake.client, 'rpc').mockImplementationOnce(
() => new Promise((resolve) => (settle = resolve)) as unknown as ReturnType<typeof fake.client.rpc>,
)
render(<AvatarSection />)
await userEvent.click(screen.getByRole('button', { name: fr['account.avatar.remove'] }))
const dialog = await screen.findByRole('dialog', { name: fr['account.avatar.remove_title'] })
await userEvent.click(screen.getByRole('button', { name: fr['account.avatar.remove_confirm'] }))
fireEvent.keyDown(dialog, { key: 'Escape' })
await userEvent.click(screen.getByRole('button', { name: fr['common.cancel'] }))
expect(dialog).toBeInTheDocument()
await act(async () => settle({ data: 1, error: null }))
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(screen.queryByRole('button', { name: fr['account.avatar.remove'] })).toBeNull()
await waitFor(() => expect(screen.getByRole('button', { name: fr['account.avatar.change'] })).toHaveFocus())
})
it('resumes the processing state for a row in flight at mount', async () => {
useAuthStore.setState({ avatar: { clean: null, inFlight: fakeAssetRow({ status: 'uploaded' }), lastRejected: null } })
render(<AvatarSection />)