Skip to content

Commit

Permalink
fix: do not measure overlay boundaries when menu is closed (#7311) (#…
Browse files Browse the repository at this point in the history
…7315)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan authored Apr 10, 2024
1 parent 73b6ee3 commit f86e0ec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
40 changes: 40 additions & 0 deletions integration/tests/component-relayout-page.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, nextRender } from '@vaadin/testing-helpers';
import { ContextMenu } from '@vaadin/context-menu';

[{ tagName: ContextMenu.is }].forEach(({ tagName }) => {
describe(`${tagName} re-layout`, () => {
let wrapper;

beforeEach(() => {
wrapper = fixtureSync('<div></div>');
});

function renderChildren() {
if (wrapper.children.length) {
[...wrapper.children].forEach((child) => child.remove());
}

wrapper.appendChild(document.createElement(tagName));

for (let i = 0; i < 100; i++) {
const btn = document.createElement('button');
btn.textContent = `Button ${i}`;
wrapper.appendChild(btn);
wrapper.appendChild(document.createElement('br'));
}
}

it(`should not reset scroll to top when creating a ${tagName}`, async () => {
renderChildren();
await nextRender();

document.documentElement.scrollTop = 1000;

renderChildren();
await nextRender();

expect(document.documentElement.scrollTop).to.equal(1000);
});
});
});
7 changes: 5 additions & 2 deletions packages/context-menu/src/vaadin-context-menu-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ export const ContextMenuMixin = (superClass) =>
* @private
*/
_onOverlayOpened(e) {
this._setOpened(e.detail.value);
this.__alignOverlayPosition();
const opened = e.detail.value;
this._setOpened(opened);
if (opened) {
this.__alignOverlayPosition();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ snapshots["context-menu items nested"] =
dir="ltr"
modeless=""
opened=""
right-aligned=""
start-aligned=""
top-aligned=""
>
Expand Down Expand Up @@ -166,7 +165,6 @@ snapshots["context-menu items overlay class nested"] =
dir="ltr"
modeless=""
opened=""
right-aligned=""
start-aligned=""
top-aligned=""
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ snapshots["menu-bar overlay"] =
`<vaadin-menu-bar-overlay
dir="ltr"
opened=""
right-aligned=""
start-aligned=""
top-aligned=""
>
Expand Down Expand Up @@ -95,7 +94,6 @@ snapshots["menu-bar overlay class"] =
class="custom menu-bar-overlay"
dir="ltr"
opened=""
right-aligned=""
start-aligned=""
top-aligned=""
>
Expand Down

0 comments on commit f86e0ec

Please sign in to comment.