Skip to content

feat(modal): dismiss only the topmost overlay on back or escape - #5127

Open
konstmar wants to merge 8 commits into
callstack:mainfrom
konstmar:overlay-dismiss-stack
Open

konstmar wants to merge 8 commits into
callstack:mainfrom
konstmar:overlay-dismiss-stack

Conversation

@konstmar

Copy link
Copy Markdown
Contributor

Motivation

Some of our overlay components have their own dismiss logic (back on native, Escape on web), and none of them route it to the topmost overlay. This PR creates a shareable hook, useOverlayDismiss, that routes those events to the topmost overlay.

  • Modal is the first to use it. Other overlay components will adopt it separately.
  • One press closes one overlay, whether or not it lives in a portal.

Stacked on #5126 - the first three commits belong to that PR.

Related issue

Notion

Screenshots / Videos

No visual change.

Test plan

yarn test covers the hook (ranking, one press per overlay, absorbed presses, Escape) and a back-press test on Modal.

Konstantin Marushchak added 3 commits September 15, 2026 10:07
Re-provide `ReduceMotionContext` in `Portal`, alongside the settings, locale and
theme contexts already forwarded across the portal boundary, so portal content
stops falling back to the context default of `false`.
Compare the key when looking up the queued `mount` to replace, so an update that
arrives before the `PortalManager` ref is attached no longer overwrites an
unrelated queued portal.
Add an opt-in `overlay` prop to `Portal` that hides every layer below it -- the
app content and any portal mounted earlier -- from assistive technology and from
the web focus order, while portals mounted on top stay reachable.
@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

Konstantin Marushchak added 5 commits September 17, 2026 15:17
Address review feedback on callstack#5126:

- rename the `overlay` prop to `modal`
- rename `PortalManager`'s `pageContent` prop to `children` and make it
  required, since a portal host doesn't render a page
- move the `collapsable` comment onto the prop it explains
- rewrite the `modal` prop documentation
A `Modal` is an overlay, so it always needs a `Portal` with `modal` set
to hide the content behind it. Render one itself instead of asking every
call site to wrap the modal and pass the prop.

BREAKING CHANGE: `Modal` and `Dialog` no longer need to be wrapped in a
`Portal`.
Every dialog now hides the content behind it, so the dedicated "Inert
background" example no longer has anything of its own to show.
`Dialog` renders itself in a `Portal`, so the examples no longer need to
wrap it in one.
@konstmar
konstmar force-pushed the overlay-dismiss-stack branch from 26f1f8e to 4ce304d Compare September 17, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant