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

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

sissbruecker
Copy link
Contributor

@sissbruecker sissbruecker commented Nov 22, 2024

Currently a popover is immediately closed when it is disconnected from the DOM. That can be an issue in a Flow dialog when the popover is opened right away after adding it to the dialog. Here the element is first added as a child of the dialog, then opened, and afterwards moved to the dialog overlay by the renderer function. The last step causes the popover to close again.

This fixes the issue by delaying closing and checking if the element has been added to the DOM again. This is similar to what we are doing in other components such as dialog or notification.

Fixes vaadin/flow-components#6840

Copy link

sonarcloud bot commented Nov 22, 2024

Comment on lines +535 to +541
// 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);
}
});
Copy link
Contributor Author

@sissbruecker sissbruecker Nov 22, 2024

Choose a reason for hiding this comment

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

This is adopted from notification:

queueMicrotask(() => {
if (!this.isConnected) {
this.opened = false;
}
});

Other components such as dialog also have logic for restoring the opened state, but I'm not sure if this is necessary at this point.

@web-padawan web-padawan merged commit 94121c0 into main Nov 22, 2024
9 checks passed
@web-padawan web-padawan deleted the fix/popover-dom-move branch November 22, 2024 07:58
web-padawan pushed a commit that referenced this pull request Nov 22, 2024
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.

Dynamically created Popover does not open when used in Dialog
3 participants