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: hide overlay if position target element is hidden (#7454) (CP: 24.4) #7456

Merged
merged 1 commit into from
May 28, 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
5 changes: 5 additions & 0 deletions packages/overlay/src/vaadin-overlay-position-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ export const PositionMixin = (superClass) =>

const targetRect = this.positionTarget.getBoundingClientRect();

if (targetRect.width === 0 && targetRect.height === 0 && this.opened) {
this.opened = false;
return;
}

// Detect the desired alignment and update the layout accordingly
const shouldAlignStartVertically = this.__shouldAlignStartVertically(targetRect);
this.style.justifyContent = shouldAlignStartVertically ? 'flex-start' : 'flex-end';
Expand Down
12 changes: 12 additions & 0 deletions packages/overlay/test/position-mixin.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ describe('position mixin', () => {
expect(overlay.$.overlay.scrollTop).to.equal(100);
});

it('should close overlay if element is hidden', async () => {
target.style.display = 'none';
await nextRender();
expect(overlay.opened).to.be.false;
});

it('should close overlay if parent element is hidden', async () => {
target.parentElement.style.display = 'none';
await nextRender();
expect(overlay.opened).to.be.false;
});

describe('vertical align top', () => {
beforeEach(() => {
overlay.verticalAlign = TOP;
Expand Down
Loading