Placement internals of the menu/popover/dialog/bottom-sheet primitives. A repository rule for apps/ui/src/renderer/components/ui/menu.tsx, apps/ui/src/renderer/components/ui/popover.tsx, apps/ui/src/renderer/components/ui/dialog.tsx, apps/ui/src/renderer/components/ui/context-menu.tsx, apps/ui/src/renderer/components/ui/bottom-sheet.tsx; read it before editing a file there.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Rule Renderer Overlay Primitives?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/geniro-io-rule-renderer-overlay-primitives)
---
name: rule-renderer-overlay-primitives
description: "Placement internals of the menu/popover/dialog/bottom-sheet primitives. A repository rule for apps/ui/src/renderer/components/ui/menu.tsx, apps/ui/src/renderer/components/ui/popover.tsx, apps/ui/src/renderer/components/ui/dialog.tsx, apps/ui/src/renderer/components/ui/context-menu.tsx, apps/ui/src/renderer/components/ui/bottom-sheet.tsx; read it before editing a file there."
---
<!-- GENERATED by scripts/sync-agent-rules.mjs from .claude/rules/renderer-overlay-primitives.md. DO NOT EDIT: edit the source, then run `pnpm sync:agent-rules`. -->
# Overlay primitives — placement contracts
- `menu` keeps its panel inside the window the way `popover` does: for top/bottom it measures the room around the trigger (`triggerRef`, else the panel's wrapper), keeps the requested side if the natural height fits, flips only to a side with more room, and caps what fits on neither to that room with no floor (rows scroll inside); the flip drives the viewport offset and the ancestor classes alike, and the natural height is measured with any cap lifted.
- `menu` submenus shift up before they shrink: clamp only what is left after the shift, and bound it by the window.
- `menu` submenus (`side="right"`, floating only) open right of the panel that holds their row when that is inside the window and clear of every panel above it; else left of it under the same test. When neither fits (a phone), a submenu opened from a menu panel is laid over that panel, which hides itself (`invisible`), and leads with a back row naming the row that opened it; such a row opens its level on a press or Enter only, never on hover, since on a touch screen the hover comes from the same tap. One held by a popover takes the roomier side, pulled into the window. A submenu never shows beside or under a visible panel it came from.
- A `menu` panel is never wider than the window less both margins (`max-w-[min(384px,calc(100vw-16px))]`).
- A floating panel is placed in two commits, and the first is unplaced. Any new correction in the placement effect must skip that commit, or it freezes a measurement of a panel that was never there (`maxHeight` is never lowered again until close).
- `popover` keeps its panel inside the window: keep the requested side if it fits, flip only to a side with more room, scroll a panel too tall for either, clamp the cross-axis offset. An unmeasured height means "not known yet", not "fits nowhere". In a phone-width window (`narrowViewportQuery()`, the stylesheet's `sm` breakpoint) a `viewport` panel ignores its caller's width and alignment and spans the window between 12px margins; a caller never adds its own phone width.
- `menu` and `popover` also close through `closeOnFrameFocus` (`frame-focus.ts`): a press inside a frame never reaches this document, so a panel with its own outside-press listener calls it too.
- `dialog` Escape closes only the top dialog. A control whose Escape means "abandon this edit" must call `preventDefault()` + `stopPropagation()` (as `menu.tsx`'s `consume()` does), or it closes the dialog underneath and loses its draft.
- `popover`'s `viewport` panel, every `Dialog` overlay and the `tooltip` are shown in the top layer (`components/ui/top-layer.ts`, `popover="manual"`), so no `z-index` or stacking context of an ancestor can paint over them; a dialog opened from a viewport popover lands over it, and the tooltip is raised again for every tip, so it lands over a panel opened before it. A `Menu` or a `context-menu` is still painted inside its ancestors' stacking contexts.
- A scrolling container that clips declares it by providing `MenuAnchorContext` as `viewport` (as `dialog` does), so menus inside go `fixed`. `Popover` takes the same choice per call site via `anchor="viewport"`.
- A `fixed` panel undoes any CSS `zoom` above it (`counterZoomStyle` in `css-zoom.ts`, read off the trigger for `menu`/`popover`; `context-menu` divides its cursor anchor's offsets by the zoom it was raised in): inside a zoomed ancestor (a command-center card scaled with the graph) its fixed offsets and size would otherwise be scaled too. At zoom 1 it adds nothing.
- `dialog` portals its overlay to `document.body`, so no ancestor's `overflow`, `transform` or `zoom` reaches it. A `menu` or `popover` treats a press, or focus entering a frame, inside a modal dialog that does not hold its panel as inside (`modal-above.ts`): such a dialog was opened above it, often from its own content.
- A dismissible viewer — a full-screen `dialog`, or a card marked `viewer` (the image viewer, What's new, the run waterfall) — and any dismissible `dialog` opened inside one holds a browser history entry while open (`usePhoneBackEntry`, owner `full-screen-dialog`): Back closes the top one, and its ✕, Escape and backdrop pop that entry, so `onClose` runs once, on the popstate. A viewer sits inside the safe area and its ✕ is `size-[44px]` (pixels, since the root font size is not 16px).
- `bottom-sheet` is a phone surface on the dialog's terms: portalled to `document.body`, shown in the top layer (`popover="manual"`), closed by the top Escape layer (`pushEscapeLayer`) and by a press on its scrim, and holding a browser history entry while open (`usePhoneBackEntry`, owner `bottom-sheet`), so Back closes it and every way out runs `onClose` once. It stays mounted while it leaves (`use-presence.ts`).