mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 08:13:50 +00:00
fix: keep the welcome tips when Escape is pressed elsewhere in the app
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user