systomic

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.

  • RuleIn recommended.json: breaking it breaks the design-system contract.
  • ErrorOxlint exits with a failure, so CI fails.
  • Quick-fixYour editor offers a one-click fix. oxlint --fix leaves it to you.

See the difference

Before
Project Alpha
12 files · edited 2h ago

 

{open && <ConfirmDialog />}
After
Project Alpha
12 files · edited 2h ago

 

<ConfirmDialog open={open} onOpenChange={setOpen} />

What doesn't work

2 findings

What works

No findings

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.

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 open value 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 />}, where PumpsDialog renders Dialog.Root with a Dialog.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/DialogTrigger for a dialog, Headless UI’s MenuButton for a Menu); a Select.Trigger inside 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 like DialogPrimitive.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: PumpDetails rendering <Dialog> from a shadcn-style ui/dialog that wraps Radix counts; a chart’s own HoverCard that renders a <div> doesn’t.
  • Home-made overlays: app components that return an element with role="dialog"/aria-modal (also through createPortal), or that return createPortal(…) and are named like an overlay (ConfirmModal; a ToastPortal isn’t). Annotate others or list them in overlays.
  • Components annotated with @systomic-overlay, and names in overlays:

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:

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)
Esc