Skip to content

fix(popover): dismiss inline popover when its parent is removed - #31868

Merged
thetaPC merged 2 commits into
ionic-team:mainfrom
Ultranmus:fix/popover-parent-removed
Dec 5, 2026
Merged

thetaPC merged 2 commits into
ionic-team:mainfrom
Ultranmus:fix/popover-parent-removed

Conversation

@Ultranmus

Copy link
Copy Markdown
Contributor

Issue number: resolves #31858


What is the current behavior?

An inline ion-popover is moved to the app root while it's presented. If the element it was declared in gets removed (an @if turning false, for example), the popover stays open over the page, with its backdrop and backdrop-no-scroll on body, until the user taps the backdrop.

What is the new behavior?

  • The popover caches its original parent and, while presented, dismisses itself with the parent-removed role when that parent is removed. This is the same thing ion-modal does since fix(modal): dismiss modal when parent element is removed from DOM #30544.
  • The observer is set up at the end of present() and again if the presented popover is moved, and is cleaned up on dismiss and disconnect.
  • Controller popovers and popovers whose parent is body or ion-app are skipped, as in modal.

Does this introduce a breaking change?

  • Yes
  • No

Other information

Added an e2e test in popover/test/inline that opens a popover, removes its container and checks it's dismissed with the right role and that body no longer has backdrop-no-scroll. It fails without the change. The popover, modal, select and datetime-button e2e suites pass locally on Mobile Chrome, along with the popover spec tests and lint.

@Ultranmus
Ultranmus requested a review from a team as a code owner December 3, 2026 14:31
@Ultranmus
Ultranmus requested a review from ShaneK December 3, 2026 14:31
@vercel

vercel Bot commented Dec 3, 2026

Copy link
Copy Markdown

@Ultranmus is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

The approach matches what ion-modal does, and checking isConnected alone is an improvement: unlike the modal, the popover stays open when its parent is only moved. A couple of changes below, the first one for nested popovers.

Comment thread core/src/components/popover/popover.tsx Resolved
Comment thread core/src/components/popover/popover.tsx Resolved
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-framework Ready Ready Preview Dec 5, 2026 12:34am UTC

Request Review

@Ultranmus

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Made all three changes: passing false so a submenu doesn't close its parent, your moved-popover test plus a nested one (removes the submenu's container and checks the parent stays open, and fails without the false), and the comments on the observer and the guard.

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thetaPC

thetaPC commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Congrats on your first contribution to Ionic Framework, and thanks for the quick turnaround on the review! The fix will be in the upcoming release.

@thetaPC
thetaPC added this pull request to the merge queue Dec 5, 2026
Merged via the queue into ionic-team:main with commit dd78ea4 Dec 5, 2026
55 checks passed

This branch was successfully deployed

1 active deployment
Preview — b523c478 Deployed Dec 5, 2026 by vercel[bot]
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.

bug: inline popover stays presented after the component that holds it is removed

2 participants