fix: keep preview retry controls stationary during pointer activation

This commit is contained in:
cesnimda
2026-10-24 23:31:58 +02:00
parent e80815f8df
commit b313e20bad
8 changed files with 79 additions and 4 deletions
@@ -701,6 +701,26 @@ test('profile-backed sections expand, reorder, hide and persist variant-only ove
expect(await screen.findByText('Saved')).toBeInTheDocument();
});
test('focusing a preview retry control keeps its pointer target stationary', async () => {
routeGet(() => Promise.resolve({ data: variant } as any));
mockedApi.post.mockRejectedValueOnce(new Error('preview offline'));
renderAt(3);
const retry = await screen.findByRole('button', { name: 'Retry preview' });
const region = screen.getByRole('region', { name: 'Live preview' });
const scroll = jest.fn();
region.parentElement!.scrollIntoView = scroll;
await act(async () => {
retry.focus();
await new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
});
expect(scroll).not.toHaveBeenCalled();
await act(async () => {
region.focus();
await new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
});
expect(scroll).toHaveBeenCalled();
});
test('preview failure is visible and retryable without leaving the editor', async () => {
routeGet(() => Promise.resolve({ data: variant } as any));
mockedApi.post.mockRejectedValueOnce(new Error('preview offline')).mockResolvedValueOnce({ data: { themeId: 'modern', html: '<p>retry</p>', suggestedFileName: 'cv.pdf' } } as any);
@@ -625,6 +625,8 @@ export default function CvBuilderEditor() {
<Paper variant="outlined" onFocusCapture={(event) => {
setMobilePane("preview");
// Moving a pointer-focused control here can cancel its pending click.
if (event.target !== scrollRef.current) return;
const pane = event.currentTarget;
requestAnimationFrame(() => {
if (pane.contains(document.activeElement)) pane.scrollIntoView?.({ block: "start", inline: "nearest" });