No conditional overlay
An overlay that is unmounted on close can't animate out, and focus doesn't return to the button that opened it. Keep it mounted and pass the condition to open.
12345{ "rules": { "systomic/no-conditional-overlay": "error" }}See the difference
{open && <ConfirmDialog />}
<ConfirmDialog open={open} onOpenChange={setOpen} />What doesn't work
2 findings12345678910import { Dialog } from "radix-ui";
export function Settings({ confirming }: { confirming: boolean }) { return ( <div> {confirming && <ConfirmDialog />} {confirming ? <Dialog.Root /> : null} </div> );}systomic/no-conditional-overlay <ConfirmDialog> is rendered conditionally, so it can't animate out or return focus. Always render it and pass the condition to open (with onOpenChange).
systomic/no-conditional-overlay <Dialog.Root> is rendered conditionally, so it can't animate out or return focus. Always render it and pass the condition to open (with onOpenChange).
What works
No findings12345678910import { Dialog } from "radix-ui";
export function Settings({ confirming, setConfirming }: { confirming: boolean; setConfirming: (open: boolean) => void }) { return ( <div> <ConfirmDialog open={confirming} onOpenChange={setConfirming} /> <Dialog.Root open={confirming} onOpenChange={setConfirming} /> </div> );}Details
Overlays stay mounted and are opened through open / onOpenChange. Rendering them conditionally unmounts them on close, so they can’t animate out, and focus isn’t returned to the trigger.
1234567{confirming && <ConfirmDialog />} // reported<ConfirmDialog open={confirming} onOpenChange={setConfirming} /> // fine
function Details({ open }) { if (!open) return null; // reported return <Sheet open={open} />;}Reported:
cond && <Overlay />,cond ? <Overlay /> : null(also inside a fragment), for roots and parts ({open && <Dialog.Content />}loses the exit animation too).- Early returns that render nothing, before a component returns an overlay, when the condition reads the overlay’s
openvalue or something named like open state (openStatePattern:is…,show…,…open,…visible,selected…,active…,editing…).
Not reported:
- Feature gating: the overlay contains its own trigger (
{canEdit && <DropdownMenu.Root><DropdownMenu.Trigger />…}), also when an app component renders the overlay together with its trigger ({pumps.length > 0 && <PumpsDialog />}, wherePumpsDialogrendersDialog.Rootwith aDialog.Trigger). App components are followed into their definition, in the same file or in imported local modules. The trigger has to belong to the overlay (Dialog.Trigger/DialogTriggerfor a dialog, Headless UI’sMenuButtonfor aMenu); aSelect.Triggerinside the dialog’s form doesn’t count. A component that opens its overlay through its own state that starts closed (const [open, setOpen] = useState(false), opened by a button next to it) counts as well. - Picking an overlay:
isMobile ? <Drawer /> : <Dialog />. - Early returns on data (
if (!user) return null).
What is an overlay is decided by where a component comes from, not by its name:
- Roots and parts imported from overlay libraries: Radix (
radix-ui,@radix-ui/*), Base UI (@base-ui/*,@base-ui-components/*), Vaul, Headless UI, Ark UI, Ariakit and React Aria Components (Dialog,AlertDialog.Root,Popover.Popup,DropdownMenu.Content,Menu.Popup,Tooltip,Select, …, also through namespace imports likeDialogPrimitive.Content). - App components declared in the file or in a local module (relative or aliased import) that return one of those (at the top, or inside a provider or
Form), whatever their name. A page that contains a controlled dialog somewhere isn’t an overlay itself:PumpDetailsrendering<Dialog>from a shadcn-styleui/dialogthat wraps Radix counts; a chart’s ownHoverCardthat renders a<div>doesn’t. - Home-made overlays: app components that return an element with
role="dialog"/aria-modal(also throughcreatePortal), or that returncreatePortal(…)and are named like an overlay (ConfirmModal; aToastPortalisn’t). Annotate others or list them inoverlays. - Components annotated with
@systomic-overlay, and names inoverlays:
12/** @systomic-overlay */export function Confirm(props: ConfirmProps) {}When the source can’t be seen (no declaration, or a component from another package), the name decides: library overlay names (Dialog, Sheet, Popover.Popup, …) and app components ending in Dialog, Modal, Sheet, Drawer or Popover (ConfirmDialog).
overlays adds names that always count as overlays, wherever they come from (["Lightbox"], or a local HoverCard that really is one).
overlayPattern is the escape hatch that replaces the built-in names: names it matches count as overlays wherever they come from, and library imports and components whose source can’t be seen count only when they match it. Use it to leave library overlays out, or for an overlay library the rule doesn’t know:
1{ "systomic/no-conditional-overlay": ["error", { "overlayPattern": "^(Dialog|AlertDialog|Sheet|Drawer)(\\.?(Root|Portal|Content|Popup))?$|[a-z0-9](Dialog|Sheet)$" }] }For {open && <ConfirmDialog />} with a plain identifier, a quick-fix renders it always with open={open}. It’s offered for overlay names only, not for app components that are overlays because of what they render, which may not take open.
| Option | Default |
|---|---|
overlayPattern |
names that count as overlays, replacing the built-in library names and the name fallback (default: library overlay names and …Dialog/…Modal/…Sheet/…Drawer/…Popover) |
overlays |
[] |
openStatePattern |
(^is|^show|open|visible|shown|^selected|^active|^editing) |