Layer

Overlay layering primitives including portals, presence, and dismissable layers.

Stable direction
@lattice-ui/layer

Part of the stable direction toward v1.0.

What It Is For

Use layer when you need the shared mechanics behind portals, outside dismissal, and mount-presence transitions.

It is the coordination layer that powers overlays like dialogs, popovers, menus, selects, and tooltips.

TSX Example Preview

Preview the first lines below, or expand to inspect the full source file.

layer.tsx
TSX Preview
import { DismissableLayer, PortalProvider, Presence } from "@lattice-ui/layer";
import React from "@rbxts/react";

type Props = {
	playerGui: PlayerGui;
};
...

Install

Global CLI command: lattice add layer

Monorepo local script

Use your package manager wrapper when running the local lattice command.

pnpm lattice add layer

npm package: @lattice-ui/layer

Peer dependencies

  • @rbxts/react
  • @rbxts/react-roblox

Public Exports

  • DismissableLayer
  • Portal
  • PortalProvider
  • usePortalContext
  • Presence

State Model

  • PortalProvider establishes the overlay container and a display-order base for everything mounted beneath it.
  • DismissableLayer tracks whether outside interactions should dismiss the current surface and whether outside pointer events should be blocked.
  • Presence keeps a subtree mounted long enough for exit work to complete and reports isPresent to the render function.

Key API

PortalProvider

Put this near the UI root with a PlayerGui container so overlay packages share one predictable mounting target.

Portal

Use Portal when content should render outside its logical parent tree but keep the same React ownership.

DismissableLayer

Use outside-interaction callbacks and onDismiss to implement overlay close behavior without manual global input listeners.

Presence

Use present, exitFallbackMs, and onExitComplete to coordinate presence-driven mounting and unmounting.

Composition Patterns

Overlay root setup

Mount one PortalProvider at app root and let all dialog, popover, menu, select, and tooltip content inherit it.

Custom layered surfaces

Compose Portal, DismissableLayer, and Presence directly when you need a custom overlay that does not map cleanly to an existing package.

Cautions / Limits

  • Without a stable PortalProvider, overlays can still work but become harder to reason about and coordinate across the app.
  • DismissableLayer handles outside interaction semantics; it does not provide visuals or positioning by itself.
  • Use motion for animated enter, exit, response, and feedback behavior instead of adding animation policy to layer consumers.

Decision Guides