fix: open a new event with n without typing the n into its title

This commit is contained in:
Linus Rath
2026-10-28 06:39:15 +01:00
parent 1d5091f68b
commit 3ff72c2c7f
2 changed files with 11 additions and 1 deletions
@@ -222,6 +222,15 @@ describe('CalendarApp unsaved editor changes', () => {
await waitFor(() => expect(screen.queryByPlaceholderText('form.title')).toBeNull());
});
it('opens the editor on n without typing the n into its title', async () => {
renderApp();
const press = new KeyboardEvent('keydown', { key: 'n', code: 'KeyN', bubbles: true, cancelable: true });
document.body.dispatchEvent(press);
// A key whose keydown is not cancelled goes on to type its character
expect(press.defaultPrevented).toBe(true);
expect(await screen.findByPlaceholderText('form.title')).toHaveValue('');
});
it('closes an untouched editor without asking', () => {
renderApp();
fireEvent.keyDown(document.body, { key: 'n', code: 'KeyN' });
+2 -1
View File
@@ -1552,7 +1552,8 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps =
case "day": setViewMode("day"); break;
case "agenda": setViewMode("agenda"); break;
case "tasks": if (enableCalendarTasks) setViewMode("tasks"); break;
case "new": openCreateForView(); break;
// Kept from typing itself into the title field the editor focuses.
case "new": e.preventDefault(); openCreateForView(); break;
}
};
window.addEventListener("keydown", handleKey);