# @solid-primitives/dismissable
[](https://primitives.solidjs.community/package/dismissable)
[](https://www.npmjs.com/package/@solid-primitives/dismissable)
[](https://github.com/solidjs-community/solid-primitives#contribution-process)
[](https://vitest.dev)
Dismissable layers (dialogs, popovers, menus) that share one layer stack, so Escape and outside presses always close the topmost layer first.
- **`makeDismissableLayer`** — non-reactive layer registration, returns `{ dismiss, cleanup, layer }`.
- **`createDismissableLayer`** — reactive layer, registers when `ref` resolves and unregisters on cleanup.
- **`getLayerStack` / `useLayerStack` / `getTopLayer` / `isTopLayer`** — read the shared stack.
Outside press and outside focus detection is delegated to [`@solid-primitives/interaction`](../interaction#readme) (`makeInteractOutside`, shadow-DOM aware; a touch that turns into a scroll or drag never dismisses); the Escape listener uses [`@solid-primitives/event-listener`](../event-listener#readme).
## Installation
```bash
npm install @solid-primitives/dismissable
# or
yarn add @solid-primitives/dismissable
# or
pnpm add @solid-primitives/dismissable
```
## How the stack works
- Layers are pushed on registration and removed on cleanup, in any order.
- Only the **topmost non-persistent** layer reacts to Escape, an outside pointer press and outside focus. Nested layers therefore close one at a time, even if a handler removes its layer synchronously.
- A press inside any layer opened after a layer (or registered with it as `parent`) is never "outside" that layer, so portaled children do not dismiss their parent.
- A **persistent** layer stays in the stack but is never auto-dismissed and never steals the top position. A layer that turns persistent while a press is being handled (for example in the tapped element's click handler) is not dismissed by that press.
- An outside press is attributed to the layer that was on top when the press started, so a touch tap that closes the layer above (in a click handler) does not also dismiss the layer below.
- When a layer is not `dismissible`, the request goes to `onDismissAttempt` and does **not** fall through to the layer below.
Dismiss reasons: `"escape" | "outside-pointer" | "outside-focus" | "programmatic"`.
### Mouse vs touch ordering
- **Mouse / pen:** an outside press dismisses on `pointerdown`, _before_ the pressed element's own `click` handlers run.
- **Touch:** the outside check is deferred to the tap's `click` (so a scroll or drag never dismisses), which means the dismissal runs _after_ the tapped element's own `click` handler. Whether a layer reacts is decided when the press **starts**: a layer that was the top layer at that moment is still dismissed by the tap even if the tapped trigger opened a new layer in its click handler. The newly opened layer is not dismissed by that same tap.
- A press that lands on a focusable element and the focus move it causes count as **one** interaction: the layer gets a single `outside-pointer` request (and a single `onDismissAttempt` when it is not `dismissible`), not an extra `outside-focus` one. This includes pressing a `