Skip to content

Commit

Permalink
Fix overflow menu flickering on mobile (#31484)
Browse files Browse the repository at this point in the history
The overflow menu button was incorrectly included in the measurement of
the width of the items. As a result, it could get stuck in a loop
alternating between different measurements as the button appears and
disappears.
  • Loading branch information
brechtvl authored Jun 25, 2024
1 parent 24f4ebb commit 4af97cf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions web_src/js/webcomponents/overflow-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
}

const itemFlexSpace = this.menuItemsEl.querySelector('.item-flex-space');
const itemOverFlowMenuButton = this.querySelector('.overflow-menu-button');

// move items in tippy back into the menu items for subsequent measurement
for (const item of this.tippyItems || []) {
Expand All @@ -72,7 +73,9 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
}

// measure which items are partially outside the element and move them into the button menu
// flex space and overflow menu are excluded from measurement
itemFlexSpace?.style.setProperty('display', 'none', 'important');
itemOverFlowMenuButton?.style.setProperty('display', 'none', 'important');
this.tippyItems = [];
const menuRight = this.offsetLeft + this.offsetWidth;
const menuItems = this.menuItemsEl.querySelectorAll('.item, .item-flex-space');
Expand All @@ -89,6 +92,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
}
}
itemFlexSpace?.style.removeProperty('display');
itemOverFlowMenuButton?.style.removeProperty('display');

// if there are no overflown items, remove any previously created button
if (!this.tippyItems?.length) {
Expand Down

0 comments on commit 4af97cf

Please sign in to comment.