fix: keep the welcome tips when Escape is pressed elsewhere in the app

This commit is contained in:
Linus Rath
2026-10-28 03:22:05 +01:00
parent b099c8a2db
commit 86ff6f5bb2
2 changed files with 19 additions and 9 deletions
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import React from 'react';
@@ -35,3 +35,18 @@ describe('WelcomeBanner tips', () => {
expect(screen.queryByText('tip_shortcuts')).toBeNull();
});
});
describe('WelcomeBanner and Escape', () => {
beforeEach(() => {
useSettingsStore.setState({ onboardingCompleted: false });
});
it('stays when Escape is pressed elsewhere, and is not marked as seen', () => {
device.isMobile = false;
render(<WelcomeBanner />);
fireEvent.keyDown(window, { key: 'Escape' });
fireEvent.keyDown(document.body, { key: 'Escape' });
expect(screen.getByRole('complementary')).toBeInTheDocument();
expect(useSettingsStore.getState().onboardingCompleted).toBe(false);
});
});
+3 -8
View File
@@ -59,14 +59,9 @@ export function WelcomeBanner() {
} catch { /* localStorage unavailable */ }
}, [updateSetting]);
useEffect(() => {
if (!visible) return;
const handle = (e: KeyboardEvent) => {
if (e.key === "Escape") dismiss();
};
window.addEventListener("keydown", handle);
return () => window.removeEventListener("keydown", handle);
}, [visible, dismiss]);
// No Escape handler: Escape closes whatever has the focus (a message, a
// dialog, a selection) and must not hide these tips for good (R8). The X
// and "Got it" dismiss them.
if (!visible) return null;