diff --git a/src/renderer/src/components/ui/Modal.tsx b/src/renderer/src/components/ui/Modal.tsx index 90a8cfd..49b7f69 100644 --- a/src/renderer/src/components/ui/Modal.tsx +++ b/src/renderer/src/components/ui/Modal.tsx @@ -1,13 +1,19 @@ /** * Modal Component * - * A reusable modal dialog component. + * A compatibility wrapper around shadcn Dialog. + * Provides the same API as the previous custom Modal. */ -import React, { useRef, useMemo, useState } from 'react' +import React from 'react' import { X } from 'lucide-react' -import FocusLock from 'react-focus-lock' -import { useDialogFocus } from '../../hooks/useDialogFocus' +import { + Dialog, + DialogContent, + DialogTitle, + DialogClose +} from './shadcn/dialog' +import { cn } from '@renderer/lib/utils' interface ModalProps { isOpen: boolean @@ -55,78 +61,62 @@ export function Modal({ isAlertDialog = false, disableEscapeKey = false, disableBackdropClick = false -}: ModalProps): React.JSX.Element | null { - const dialogRef = useRef(null) - const [generatedId] = useState( - () => `modal-title-${Date.now().toString(36)}-${Math.random().toString(36).substr(2, 9)}` - ) - - // Use provided titleId or generated one - const generatedTitleId = useMemo((): string => { - return titleId || generatedId - }, [titleId, generatedId]) - - // Setup focus management (includes Escape key handling) - const { focusLockProps } = useDialogFocus({ - isOpen, - dialogRef, - onClose, - triggerRef, - initialFocusSelector, - shouldCloseOnEscape: !disableEscapeKey - }) - - if (!isOpen) return null - +}: ModalProps): React.JSX.Element { return ( - -
{ if (!open) onClose() }}> + e.preventDefault() : undefined} + onInteractOutside={disableBackdropClick ? (e) => e.preventDefault() : undefined} + onOpenAutoFocus={ + initialFocusSelector + ? (e) => { + e.preventDefault() + const el = document.querySelector(initialFocusSelector) as HTMLElement + el?.focus() + } + : undefined + } + onCloseAutoFocus={ + triggerRef?.current + ? (e) => { + e.preventDefault() + triggerRef.current?.focus() + } + : undefined + } > - {/* Backdrop */} -