From 7a66a54e669e3581bba8fa63608be1396e7f56e2 Mon Sep 17 00:00:00 2001 From: Luffy <52o@qq52o.cn> Date: Wed, 2 Dec 2026 18:00:36 +0800 Subject: [PATCH] fix(dashboard): focus the title in desktop trip forms --- client/src/components/Trips/TripFormModal.tsx | 5 +++++ client/src/components/shared/DialogShell.tsx | 13 +++++++++---- client/src/pages/DashboardPage.tsx | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/client/src/components/Trips/TripFormModal.tsx b/client/src/components/Trips/TripFormModal.tsx index 01dde9e49..1cbfc314f 100644 --- a/client/src/components/Trips/TripFormModal.tsx +++ b/client/src/components/Trips/TripFormModal.tsx @@ -52,6 +52,7 @@ 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 @@ -68,12 +69,14 @@ 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); @@ -521,6 +524,7 @@ export default function TripFormModal({ {t('dashboard.tripTitle')} * canEditTrip && update('title', e.target.value)} @@ -795,6 +799,7 @@ export default function TripFormModal({ return ( header: ReactNode footer?: ReactNode /** Makes the scrolling body a form. */ @@ -90,7 +92,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, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit) { +function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false, align = 'center', blocked = false, covered = false, initialFocusRef, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit) { const { t } = useTranslation() const panelRef = useRef(null) const pressedOn = useRef(null) @@ -122,12 +124,15 @@ 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) focusDialog(panel) + if (!focusedInside && panel) { + if (initialFocusRef) (initialFocusRef.current ?? panel).focus() + else focusDialog(panel) + } return () => { release() if (opener instanceof HTMLElement) opener.focus() } - }, [focusedBefore]) + }, [focusedBefore, initialFocusRef]) const bodyClass = bodyClassName ?? BODY const body = children == null ? null : onSubmit diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx index c71cae65e..e67149720 100644 --- a/client/src/pages/DashboardPage.tsx +++ b/client/src/pages/DashboardPage.tsx @@ -297,6 +297,7 @@ function DashboardPageDesktop(): React.ReactElement { {showForm && ( { setShowForm(false); setEditingTrip(null) }} onSave={editingTrip ? handleUpdate : handleCreate}