"use client"; import { useEffect, useRef } from "react"; import { cn } from "@/lib/utils"; // A modal on the NATIVE : the browser owns the focus trap, Escape, the // top layer and the inert page behind it, so there is nothing here to get // wrong. `open` drives showModal()/close(); `onClose` hears every way it closes // (Escape, a form with method="dialog", the backdrop is NOT one -- a stray click // should not throw away a half-typed reason). export function Dialog({ open, onClose, title, className, children, ...props }: Omit, "open" | "title"> & { open: boolean; onClose: () => void; title: React.ReactNode; }) { const ref = useRef(null); useEffect(() => { const d = ref.current; if (!d) return; if (open && !d.open) { d.showModal(); // The browser's focusing steps read the `autofocus` ATTRIBUTE, which // React's autoFocus never writes: a field that should take the focus // says so with data-autofocus. d.querySelector("[data-autofocus]")?.focus(); } if (!open && d.open) d.close(); }, [open]); return (

{title}

{children}
); }