Skip to content

fix: do not delay auto-adding Popover by beforeClientResponse #7563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 5, 2025

Conversation

DiegoCardoso
Copy link
Contributor

Description

If a popover tries to auto-add itself when another modal element is opened, it may end up being added as a child of said element. That can be problematic in case the target element is not part of the parent modal element and, when the modal is closed, the popover instance is removed with its parent and interacting with the target element won't work as expected.

This fix adds a detach listener to popover and tries to reattach it in case of:

  • the popover instance has been auto-added
  • the target element is present
  • the target element is still attached to the page

Fixes #7505

Type of change

  • Bugfix

If a popover tries to auto-add itself when another modal element is
opened, it may end up being added as a child of said element. That can
be problematic in case the target element is not part of the parent
modal element and, when the modal is closed, the popover instance is
removed with its parent and interacting with the target element won't
work as expected.

This fix adds a detach listener to popover and tries to reattach it in
case of:
- the popover instance has been auto-added
- the target element is present
- the target element is still attached to the page

Fixes #7505
Comment on lines 139 to 150
public void openDialogAndSetTarget_closeDialog_popoverOpens() {
// Clear the target and remove the popover first to ensure the popover
// is auto-added when the dialog opens
clickElementWithJs("clear-target");
clickElementWithJs("remove-popover");

clickElementWithJs("open-dialog");
clickElementWithJs("close-dialog");

clickTarget();
checkPopoverIsOpened();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to avoid adding an IT and use a unit test instead, but with no luck. I tried something like:

    @Test
    public void targetAddedToPage_modalElementOpenedAndClosed_popoverAutoAddedToPage() {
        Popover popover = new Popover();
        Div target = new Div();
        popover.setTarget(target);
        ui.add(target);

        Div modalElement = new Div();
        ui.setChildComponentModal(modalElement, true);
        fakeClientResponse();

        Assert.assertEquals(modalElement.getElement(),
                popover.getElement().getParent());

        ui.remove(modalElement);
        modalElement.getElement().removeAllChildren();
        modalElement.getElement().removeFromTree();
        // popover.getElement().removeFromTree();
        fakeClientResponse();

        Assert.assertEquals(ui.getElement(), popover.getElement().getParent());
    }

But the detach listener in the Popover class wasn't being called.

@DiegoCardoso DiegoCardoso changed the title fix: reattach auto-added Popover fix: do not delay auto-adding Popover attachment Jun 5, 2025
@DiegoCardoso DiegoCardoso changed the title fix: do not delay auto-adding Popover attachment fix: do not delay auto-adding Popover by beforeClientResponse Jun 5, 2025
@sissbruecker sissbruecker enabled auto-merge (squash) June 5, 2025 09:46
Copy link

sonarqubecloud bot commented Jun 5, 2025

@sissbruecker sissbruecker merged commit 7a1c46f into main Jun 5, 2025
5 checks passed
@sissbruecker sissbruecker deleted the fix/popover/reattach-popover branch June 5, 2025 09:52
vaadin-bot pushed a commit that referenced this pull request Jun 5, 2025
* fix: reattach auto-added Popover

If a popover tries to auto-add itself when another modal element is
opened, it may end up being added as a child of said element. That can
be problematic in case the target element is not part of the parent
modal element and, when the modal is closed, the popover instance is
removed with its parent and interacting with the target element won't
work as expected.

This fix adds a detach listener to popover and tries to reattach it in
case of:
- the popover instance has been auto-added
- the target element is present
- the target element is still attached to the page

Fixes #7505

* test: add a test scenario for the use-case being fixed

* refactor: auto-add popover to target parent

* test: wait for dialog element to be removed

---------

Co-authored-by: Sascha Ißbrücker <[email protected]>
vaadin-bot pushed a commit that referenced this pull request Jun 5, 2025
* fix: reattach auto-added Popover

If a popover tries to auto-add itself when another modal element is
opened, it may end up being added as a child of said element. That can
be problematic in case the target element is not part of the parent
modal element and, when the modal is closed, the popover instance is
removed with its parent and interacting with the target element won't
work as expected.

This fix adds a detach listener to popover and tries to reattach it in
case of:
- the popover instance has been auto-added
- the target element is present
- the target element is still attached to the page

Fixes #7505

* test: add a test scenario for the use-case being fixed

* refactor: auto-add popover to target parent

* test: wait for dialog element to be removed

---------

Co-authored-by: Sascha Ißbrücker <[email protected]>
DiegoCardoso added a commit that referenced this pull request Jun 5, 2025
… (#7579)

* fix: reattach auto-added Popover

If a popover tries to auto-add itself when another modal element is
opened, it may end up being added as a child of said element. That can
be problematic in case the target element is not part of the parent
modal element and, when the modal is closed, the popover instance is
removed with its parent and interacting with the target element won't
work as expected.

This fix adds a detach listener to popover and tries to reattach it in
case of:
- the popover instance has been auto-added
- the target element is present
- the target element is still attached to the page

Fixes #7505

* test: add a test scenario for the use-case being fixed

* refactor: auto-add popover to target parent

* test: wait for dialog element to be removed

---------

Co-authored-by: Diego Cardoso <[email protected]>
Co-authored-by: Sascha Ißbrücker <[email protected]>
DiegoCardoso added a commit that referenced this pull request Jun 5, 2025
… (#7578)

* fix: reattach auto-added Popover

If a popover tries to auto-add itself when another modal element is
opened, it may end up being added as a child of said element. That can
be problematic in case the target element is not part of the parent
modal element and, when the modal is closed, the popover instance is
removed with its parent and interacting with the target element won't
work as expected.

This fix adds a detach listener to popover and tries to reattach it in
case of:
- the popover instance has been auto-added
- the target element is present
- the target element is still attached to the page

Fixes #7505

* test: add a test scenario for the use-case being fixed

* refactor: auto-add popover to target parent

* test: wait for dialog element to be removed

---------

Co-authored-by: Diego Cardoso <[email protected]>
Co-authored-by: Sascha Ißbrücker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Popover not working after displaying a Dialog
3 participants