Skip to content
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

fix: do not close popover when it is just moved in DOM (#8208) (CP: 24.5) #8209

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/popover/src/vaadin-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,13 @@ class Popover extends PopoverPositionMixin(

document.documentElement.removeEventListener('click', this.__onGlobalClick, true);

this._openedStateController.close(true);
// Automatically close popover when it is removed from DOM
// Avoid closing if the popover is just moved in the DOM
queueMicrotask(() => {
if (!this.isConnected) {
this._openedStateController.close(true);
}
});
}

/**
Expand Down
11 changes: 11 additions & 0 deletions packages/popover/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ describe('popover', () => {
expect(overlay.opened).to.be.false;
});

it('should not close overlay when popover is moved in DOM', async () => {
target.click();
await nextRender();

const parent = popover.parentElement;
popover.remove();
parent.appendChild(popover);
await nextRender();
expect(overlay.opened).to.be.true;
});

it('should remove document click listener when popover is detached', async () => {
const spy = sinon.spy(document.documentElement, 'removeEventListener');
popover.remove();
Expand Down