mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
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.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, useState, type ButtonHTMLAttributes, type ClipboardEvent, type CSSProperties, type FormEvent, type KeyboardEvent as ReactKeyboardEvent, type ReactNode, type RefObject } from 'react'
|
||||
import { useEffect, useRef, useState, type ButtonHTMLAttributes, type ClipboardEvent, type CSSProperties, type FormEvent, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { Trash2, X } from 'lucide-react'
|
||||
import { useTranslation } from '../../i18n'
|
||||
@@ -34,8 +34,6 @@ export interface DialogShellProps {
|
||||
blocked?: boolean
|
||||
/** A separate dialog is open in front of this one. */
|
||||
covered?: boolean
|
||||
/** Preferred focus on open. If the ref is empty, focus the panel. */
|
||||
initialFocusRef?: RefObject<HTMLElement | null>
|
||||
header: ReactNode
|
||||
footer?: ReactNode
|
||||
/** Makes the scrolling body a form. */
|
||||
@@ -92,7 +90,7 @@ export function DialogShell({ open = true, ...frame }: DialogShellProps) {
|
||||
return open ? <DialogFrame {...frame} /> : null
|
||||
}
|
||||
|
||||
function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false, align = 'center', blocked = false, covered = false, initialFocusRef, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit<DialogShellProps, 'open'>) {
|
||||
function DialogFrame({ onClose, labelledBy, width = 'detail', fillHeight = false, align = 'center', blocked = false, covered = false, header, footer, onSubmit, children, bodyClassName, onPaste, discardGuard }: Omit<DialogShellProps, 'open'>) {
|
||||
const { t } = useTranslation()
|
||||
const panelRef = useRef<HTMLDivElement>(null)
|
||||
const pressedOn = useRef<EventTarget | null>(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
|
||||
|
||||
Reference in New Issue
Block a user