fix(2054): only calculate dropdown position when opening

Part-of: <https://dev.funkwhale.audio/funkwhale/funkwhale/-/merge_requests/2372>
This commit is contained in:
tobifroe 2023-03-20 22:07:56 +01:00 committed by Kasper Seweryn
parent fe01521c72
commit e258e6f12b
1 changed files with 10 additions and 8 deletions

View File

@ -105,6 +105,7 @@ const openMenu = () => {
// little magic to ensure the menu is always visible in the viewport
// By default, try to display it on the right if there is enough room
const menu = dropdown.value.find('.menu')
if (!menu.classList.includes('visible')) {
const viewportOffset = menu.get(0)?.getBoundingClientRect() ?? { right: 0, left: 0 }
const viewportWidth = document.documentElement.clientWidth
const rightOverflow = viewportOffset.right - viewportWidth
@ -115,6 +116,7 @@ const openMenu = () => {
} else if (leftOverflow > 0) {
menu.css({ cssText: `right: -${leftOverflow + 5}px !important;` })
}
}
}
</script>