fix(geschichte): restore focus to item remove button after failed DELETE rollback (#795)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -102,6 +102,10 @@ async function handleRemove(item: JourneyItemView) {
|
||||
});
|
||||
if (!res.ok) {
|
||||
items = prev;
|
||||
await tick();
|
||||
sectionEl
|
||||
?.querySelector<HTMLElement>(`[data-item-id="${CSS.escape(item.id)}"] [data-remove-btn]`)
|
||||
?.focus();
|
||||
errorMessage = await failureMessage(res);
|
||||
return;
|
||||
}
|
||||
@@ -109,6 +113,10 @@ async function handleRemove(item: JourneyItemView) {
|
||||
} catch (e) {
|
||||
console.error('Story document remove failed', e);
|
||||
items = prev;
|
||||
await tick();
|
||||
sectionEl
|
||||
?.querySelector<HTMLElement>(`[data-item-id="${CSS.escape(item.id)}"] [data-remove-btn]`)
|
||||
?.focus();
|
||||
errorMessage = m.journey_mutation_error_reload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,4 +309,43 @@ describe('StoryDocumentPanel — remove', () => {
|
||||
m.geschichte_documents_removed_announce({ title: 'Brief von Eugenie' })
|
||||
);
|
||||
});
|
||||
|
||||
it('returns focus to the item remove button when DELETE fails with !res.ok', async () => {
|
||||
stubFetch([], { ok: false, status: 500, body: {} });
|
||||
render(
|
||||
StoryDocumentPanel,
|
||||
defaultProps({ items: [makeItem('i1', 10, docSummary('d1', 'Brief von Eugenie'))] })
|
||||
);
|
||||
|
||||
await userEvent.click(
|
||||
page.getByRole('button', {
|
||||
name: m.geschichte_documents_remove_label({ title: 'Brief von Eugenie' })
|
||||
})
|
||||
);
|
||||
|
||||
expect(document.activeElement?.getAttribute('aria-label')).toBe(
|
||||
m.geschichte_documents_remove_label({ title: 'Brief von Eugenie' })
|
||||
);
|
||||
});
|
||||
|
||||
it('returns focus to the item remove button when DELETE throws a network error', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(() => Promise.reject(new Error('Network error')))
|
||||
);
|
||||
render(
|
||||
StoryDocumentPanel,
|
||||
defaultProps({ items: [makeItem('i1', 10, docSummary('d1', 'Brief von Eugenie'))] })
|
||||
);
|
||||
|
||||
await userEvent.click(
|
||||
page.getByRole('button', {
|
||||
name: m.geschichte_documents_remove_label({ title: 'Brief von Eugenie' })
|
||||
})
|
||||
);
|
||||
|
||||
expect(document.activeElement?.getAttribute('aria-label')).toBe(
|
||||
m.geschichte_documents_remove_label({ title: 'Brief von Eugenie' })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user