diff --git a/components/calendar/__tests__/calendar-app.test.tsx b/components/calendar/__tests__/calendar-app.test.tsx index 6b231359e..d3ad5e264 100644 --- a/components/calendar/__tests__/calendar-app.test.tsx +++ b/components/calendar/__tests__/calendar-app.test.tsx @@ -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' }); diff --git a/components/calendar/calendar-app.tsx b/components/calendar/calendar-app.tsx index f584a8340..f626b4e4e 100644 --- a/components/calendar/calendar-app.tsx +++ b/components/calendar/calendar-app.tsx @@ -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);