mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
fix: let Escape close only the dialog, not also clear the selection behind it
This commit is contained in:
@@ -141,3 +141,19 @@ describe('useFocusTrap', () => {
|
||||
expect(screen.getByTestId('panel')).not.toHaveAttribute('tabindex');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useFocusTrap and the page behind', () => {
|
||||
it('keeps an Escape that closed the dialog from the page', () => {
|
||||
const page = vi.fn();
|
||||
document.addEventListener('keydown', page);
|
||||
try {
|
||||
const onEscape = vi.fn();
|
||||
render(<Page open onEscape={onEscape} />);
|
||||
fireEvent.keyDown(screen.getByLabelText('name'), { key: 'Escape' });
|
||||
expect(onEscape).toHaveBeenCalledTimes(1);
|
||||
expect(page).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
document.removeEventListener('keydown', page);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,7 +70,11 @@ export function useFocusTrap({
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
// Handle Escape
|
||||
if (e.key === 'Escape' && onEscapeRef.current) {
|
||||
if (isTopmost()) onEscapeRef.current();
|
||||
if (!isTopmost()) return;
|
||||
// Escape closes the innermost layer only (R8): the page's own
|
||||
// handlers (Files clears its selection) must not see it too.
|
||||
e.stopPropagation();
|
||||
onEscapeRef.current();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user