Skip to content

Commit

Permalink
fix: wait for updateComplete before setting positionTarget (#7524)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Jul 10, 2024
1 parent 8213c50 commit b46746e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions packages/menu-bar/src/vaadin-menu-bar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,14 +878,11 @@ export const MenuBarMixin = (superClass) =>
subMenu.items = items;
subMenu.listenOn = button;
const overlay = subMenu._overlayElement;
// Unset old positioning to prevent flashing.
overlay.removeAttribute('style');
overlay.positionTarget = undefined;
overlay.noVerticalOverlap = true;

this._expandedButton = button;

requestAnimationFrame(() => {
requestAnimationFrame(async () => {
button.dispatchEvent(
new CustomEvent('opensubmenu', {
detail: {
Expand All @@ -896,6 +893,14 @@ export const MenuBarMixin = (superClass) =>
this._hideTooltip(true);

this._setExpanded(button, true);

// Delay setting position target until overlay is rendered
// to correctly measure item content in Lit based version.
if (overlay.updateComplete) {
await overlay.updateComplete;
}

overlay.positionTarget = button;
});

this.style.pointerEvents = 'auto';
Expand All @@ -915,11 +920,6 @@ export const MenuBarMixin = (superClass) =>
if (!keydown) {
overlay.$.overlay.focus();
}

// Delay setting position target until overlay is rendered
// to correctly measure item content in Lit based version.
overlay.positionTarget = button;
overlay._updatePosition();
},
{ once: true },
);
Expand Down

0 comments on commit b46746e

Please sign in to comment.