'use client' import { useEffect, useState } from 'react' /** * Whether something is open over the page. * * A modal that leaves the page behind it in the accessibility tree is not a * modal: the links under it are still reachable by a screen reader and by the * tab key, under an overlay that has already stopped a mouse from touching * them. So the same destination has two names in one document — one a person * can click and one they cannot — which is exactly the shape of a trap. * * Watched rather than lifted into state, because dialogs on a surface like this * are opened by half a dozen unrelated components and threading a flag through * all of them would put one fact in six places. What the document is showing is * a property of the document, and this asks it. */ export function useAside(): boolean { const [open, setOpen] = useState(false) useEffect(() => { const look = () => setOpen(Boolean(document.querySelector('[role="dialog"]'))) look() const eye = new MutationObserver(look) eye.observe(document.body, { childList: true, subtree: true }) return () => eye.disconnect() }, []) return open }