Skip to content

Popover Component: Add nested popover detection with context management#74179

Closed
SirLouen wants to merge 4 commits intoWordPress:trunkfrom
SirLouen:patch/74154
Closed

Popover Component: Add nested popover detection with context management#74179
SirLouen wants to merge 4 commits intoWordPress:trunkfrom
SirLouen:patch/74154

Conversation

@SirLouen
Copy link
Member

@SirLouen SirLouen commented Dec 23, 2025

What?

Closes: #74154
When there is a nested popover that should be closed along with its parent on blur, it's not happening.
The simplest example is when clicking on the Color Palette (select colors on a paragraph block, for example).

Why?

The culprit is here:
Commit: 8501118
PR: #72376

Because of this PR, it's generating a side effect. When there is a parent/child connected relationship, both should close. In the case of PR #72376 the filter popover should be disconnected, hence, it should not close the popover.

Testing Instructions

There are two scenarios:

  1. The one that is being tested in Fix Popover closing unexpectedly when a Menu inside it is closed. #72376 -> If we enable the Media Modal experiments
  2. Add any image to a post
  3. Click Replace button in the image
  4. Click on the filter button
  5. And then click outside
  6. The Media modal popover should stick while the filter popover should close.

And at the same time

  1. If we follow instructions in Selecting a custom color might prevent the color palette from closing. #74154 -> Create a new paragraph
  2. Set the background, or the color
  3. The click on Custom Color Palette
  4. Click any color inside the custom color palette
  5. And click outside
  6. Both popovers should close.

Screenshots or screencast

74154.mp4

@SirLouen SirLouen requested a review from ajitbohra as a code owner December 23, 2025 01:34
@SirLouen SirLouen self-assigned this Dec 23, 2025
@github-actions github-actions bot added the [Package] Components /packages/components label Dec 23, 2025
@github-actions
Copy link

github-actions bot commented Dec 23, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

Nice catch @SirLouen and thanks for getting the PR up.

I did some manual testing and it fixes the custom color popover bug, and preserves the parent behaviour from #72376 🎉

I mostly left questions, which might not help, mainly to help my own understanding 😄

I'd lean on @tellthemachines and @mirka for a more learned opinion!


let current: Element | null = closestPopover;
while ( current ) {
const parentId = current.getAttribute( PARENT_POPOVER_ID_ATTR );
Copy link
Member

Choose a reason for hiding this comment

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

Just checking: here we look whether the reference element is inside the parent's floating element. Is that right?

Might be a dumb question, but could a nested popover's trigger ever be outside a parent's floating element, in the DOM at least?

Copy link
Member Author

@SirLouen SirLouen Dec 24, 2025

Choose a reason for hiding this comment

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

Yep, I feel it's quite complex to catch all popover scenarios. I'm not sure if we should be now hunting for each of them, or just wait for them to appear (just the one referenced in the report to this PR). The thing is that I don't have a massive knowledge of all the popover cases in GB, so I'm not sure if there could be additional patterns that could trigger this (and looking at #72376, I doubt that anyone has)

@tellthemachines
Copy link
Contributor

Thanks for the PR @SirLouen ! This is a very big changeset though, so I thought I'd try finding a smaller fix. I put up #74340 and copied over the unit test from this PR to check that it satisfies the same conditions. Let me know what you think!

@SirLouen SirLouen closed this Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Regression Related to a regression in the latest release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selecting a custom color might prevent the color palette from closing.

3 participants