From a2cf911ce155d700685cffb80f5396c5beb4741d Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 2 Dec 2026 14:49:52 +0100 Subject: [PATCH] fix(dashboard): respect pointer type when focusing trip titles Mark the title through the existing dialog focus mechanism so a mouse can type right away and touch keeps focus on the dialog. Cover creating and editing a trip in the dashboard tests. --- client/src/components/Trips/TripFormModal.tsx | 6 +---- client/src/components/shared/DialogShell.tsx | 13 ++++------ client/src/pages/DashboardPage.test.tsx | 24 +++++++++++++------ client/src/pages/DashboardPage.tsx | 1 - 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/client/src/components/Trips/TripFormModal.tsx b/client/src/components/Trips/TripFormModal.tsx index 1cbfc314f..81954f8bf 100644 --- a/client/src/components/Trips/TripFormModal.tsx +++ b/client/src/components/Trips/TripFormModal.tsx @@ -52,7 +52,6 @@ interface TripFormModalProps { onSave: (data: TripCreateRequest & { date_shift_mode?: DateShiftMode }) => Promise<{ trip?: Trip } | void> | void; trip: Trip | null; onCoverUpdate?: (tripId: number, coverUrl: string | null) => void; - focusTitle?: boolean; /** * Drawn inside the trip settings rather than as a dialog of its own (#2811): no * frame and no Cancel, the settings around it close it. One column there, since @@ -69,14 +68,12 @@ export default function TripFormModal({ onSave, trip, onCoverUpdate, - focusTitle = false, embedded = false, onReviewChange, }: TripFormModalProps) { const isEditing = !!trip; const labelId = useId(); const fileRef = useRef(null); - const titleRef = useRef(null); const toast = useToast(); const { t } = useTranslation(); const currentUser = useAuthStore((s) => s.user); @@ -524,7 +521,7 @@ export default function TripFormModal({ {t('dashboard.tripTitle')} * canEditTrip && update('title', e.target.value)} @@ -799,7 +796,6 @@ export default function TripFormModal({ return ( header: ReactNode footer?: ReactNode /** Makes the scrolling body a form. */ @@ -92,7 +90,7 @@ export function DialogShell({ open = true, ...frame }: DialogShellProps) { return open ? : null } -function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false, align = 'center', blocked = false, covered = false, initialFocusRef, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit) { +function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false, align = 'center', blocked = false, covered = false, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit) { const { t } = useTranslation() const panelRef = useRef(null) const pressedOn = useRef(null) @@ -124,15 +122,12 @@ function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false const focusedInside = !!panel && panel.contains(document.activeElement) const opener = focusedInside ? focusedBefore : document.activeElement const release = lockBodyScroll() - if (!focusedInside && panel) { - if (initialFocusRef) (initialFocusRef.current ?? panel).focus() - else focusDialog(panel) - } + if (!focusedInside && panel) focusDialog(panel) return () => { release() if (opener instanceof HTMLElement) opener.focus() } - }, [focusedBefore, initialFocusRef]) + }, [focusedBefore]) const bodyClass = bodyClassName ?? BODY const body = children == null ? null : onSubmit diff --git a/client/src/pages/DashboardPage.test.tsx b/client/src/pages/DashboardPage.test.tsx index 93a80a477..e12e9d44e 100644 --- a/client/src/pages/DashboardPage.test.tsx +++ b/client/src/pages/DashboardPage.test.tsx @@ -42,8 +42,17 @@ beforeEach(() => { afterEach(() => { vi.useRealTimers(); + vi.unstubAllGlobals(); }); +function mockFinePointer() { + const matchMedia = window.matchMedia.bind(window); + vi.stubGlobal('matchMedia', (query: string) => { + const result = matchMedia(query); + return query === '(pointer: fine)' ? { ...result, matches: true } : result; + }); +} + describe('DashboardPage', () => { describe('FE-PAGE-DASH-001: Unauthenticated user is redirected', () => { it('does not render dashboard content when not authenticated', () => { @@ -100,7 +109,8 @@ describe('DashboardPage', () => { }); describe('FE-PAGE-DASH-005: Create Trip button opens TripFormModal', () => { - it('clicking New Trip button opens the trip form modal', async () => { + it.each(['mouse', 'touch'])('PR-3305: opening the trip form sets the right focus for %s', async (pointer) => { + if (pointer === 'mouse') mockFinePointer(); const user = userEvent.setup(); render(); @@ -110,10 +120,9 @@ describe('DashboardPage', () => { await user.click(screen.getAllByRole('button', { name: /new trip/i })[0]); - // TripFormModal opens — "Create New Trip" appears in heading and submit button - await waitFor(() => { - expect(screen.getAllByText(/create new trip/i).length).toBeGreaterThan(0); - }); + const dialog = await screen.findByRole('dialog', { name: 'Create New Trip' }); + const target = pointer === 'mouse' ? within(dialog).getByPlaceholderText(/summer in japan/i) : dialog; + expect(target).toHaveFocus(); }); }); @@ -253,7 +262,8 @@ describe('DashboardPage', () => { }); describe('FE-PAGE-DASH-012: Edit trip opens form with pre-filled data', () => { - it('clicking edit on a trip card opens TripFormModal with trip title pre-filled', async () => { + it('PR-3305: focuses the prefilled title when editing a trip', async () => { + mockFinePointer(); const user = userEvent.setup(); render(); @@ -266,7 +276,7 @@ describe('DashboardPage', () => { await waitFor(() => { const titleInput = screen.getByDisplayValue('Paris Adventure'); - expect(titleInput).toBeInTheDocument(); + expect(titleInput).toHaveFocus(); }); }); }); diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx index e67149720..c71cae65e 100644 --- a/client/src/pages/DashboardPage.tsx +++ b/client/src/pages/DashboardPage.tsx @@ -297,7 +297,6 @@ function DashboardPageDesktop(): React.ReactElement { {showForm && ( { setShowForm(false); setEditingTrip(null) }} onSave={editingTrip ? handleUpdate : handleCreate}