Skip to content

Commit 49d1e17

Browse files
DiegoCardosovaadin-bot
authored andcommitted
fix: hide overlay if position target element is hidden (#7454)
* fix: hide overlay if position target element is hidden If the target element is hidden, either by having `display: none` set to itself of any of its parents, a resize observer for that element is triggered. This change adds a check for the target element size on the resize observer callback and closes the overlay in case the element is hidden. Fixes #7437
1 parent 8311891 commit 49d1e17

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/overlay/src/vaadin-overlay-position-mixin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ export const PositionMixin = (superClass) =>
220220

221221
const targetRect = this.positionTarget.getBoundingClientRect();
222222

223+
if (targetRect.width === 0 && targetRect.height === 0 && this.opened) {
224+
this.opened = false;
225+
return;
226+
}
227+
223228
// Detect the desired alignment and update the layout accordingly
224229
const shouldAlignStartVertically = this.__shouldAlignStartVertically(targetRect);
225230
this.style.justifyContent = shouldAlignStartVertically ? 'flex-start' : 'flex-end';

packages/overlay/test/position-mixin.common.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ describe('position mixin', () => {
9393
expect(overlay.$.overlay.scrollTop).to.equal(100);
9494
});
9595

96+
it('should close overlay if element is hidden', async () => {
97+
target.style.display = 'none';
98+
await nextRender();
99+
expect(overlay.opened).to.be.false;
100+
});
101+
102+
it('should close overlay if parent element is hidden', async () => {
103+
target.parentElement.style.display = 'none';
104+
await nextRender();
105+
expect(overlay.opened).to.be.false;
106+
});
107+
96108
describe('vertical align top', () => {
97109
beforeEach(() => {
98110
overlay.verticalAlign = TOP;

0 commit comments

Comments
 (0)