Skip to content

Commit

Permalink
fix: only close popover on mouseleave if it is the last one (#7664)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Aug 19, 2024
1 parent aed2f31 commit f0d2e1b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/popover/src/vaadin-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,12 @@ class Popover extends PopoverPositionMixin(

/** @private */
__onTargetMouseLeave(event) {
// Do not close the popover on target focusout if the overlay is not the last one.
// This happens e.g. when opening the nested popover that uses non-modal overlay.
if (!isLastOverlay(this._overlayElement)) {
return;
}

if (this._overlayElement.contains(event.relatedTarget)) {
return;
}
Expand Down Expand Up @@ -794,6 +800,13 @@ class Popover extends PopoverPositionMixin(

/** @private */
__onOverlayMouseLeave(event) {
// Do not close the popover on overlay focusout if it's not the last one.
// This happens when opening the nested component that uses "modal" overlay
// setting `pointer-events: none` on the body (combo-box, date-picker etc).
if (!isLastOverlay(this._overlayElement)) {
return;
}

if (event.relatedTarget === this.target) {
return;
}
Expand Down
39 changes: 39 additions & 0 deletions packages/popover/test/nested.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from '@vaadin/chai-plugins';
import { esc, fixtureSync, nextRender, nextUpdate, outsideClick } from '@vaadin/testing-helpers';
import './not-animated-styles.js';
import '../vaadin-popover.js';
import { mouseenter, mouseleave } from './helpers.js';

describe('nested popover', () => {
let popover, target, secondPopover, secondTarget;
Expand Down Expand Up @@ -122,4 +123,42 @@ describe('nested popover', () => {
expect(popover.opened).to.be.true;
});
});

describe('hover', () => {
beforeEach(async () => {
popover.trigger = ['hover'];
await nextUpdate(popover);
});

it('should not close when mouse leaves the target if popover is not the last one', async () => {
mouseenter(target);
await nextRender();

mouseleave(target, secondTarget);
secondTarget.click();
await nextRender();

mouseleave(secondTarget, target);

mouseenter(target);
mouseleave(target);
await nextUpdate(popover);

expect(popover.opened).to.be.true;
});

it('should not close when mouse leaves the overlay if popover is not the last one', async () => {
mouseenter(target);
await nextRender();

mouseleave(target, secondTarget);
secondTarget.click();
await nextRender();

mouseleave(secondTarget);
await nextUpdate(popover);

expect(popover.opened).to.be.true;
});
});
});

0 comments on commit f0d2e1b

Please sign in to comment.