Skip to content

Commit 40a0850

Browse files
authored
Merge pull request #7808 from nextcloud-libraries/fix/noid/nc-actions-performance-v2
fix(NcActions): only compute popover maxHeight on demand
2 parents 2ec172e + 726acfd commit 40a0850

1 file changed

Lines changed: 27 additions & 32 deletions

File tree

src/components/NcActions/NcActions.vue

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,7 @@ export default {
918918
</docs>
919919

920920
<script>
921-
import { useElementBounding, useWindowSize } from '@vueuse/core'
922-
import { computed, Fragment, h, mergeProps, ref, toRef, warn } from 'vue'
921+
import { computed, Fragment, h, mergeProps, warn } from 'vue'
923922
import IconDotsHorizontal from 'vue-material-design-icons/DotsHorizontal.vue'
924923
import { useTrapStackControl } from '../../composables/useTrapStackControl.ts'
925924
import { t } from '../../l10n.ts'
@@ -1109,38 +1108,11 @@ export default {
11091108
'update:open',
11101109
],
11111110
1112-
setup(props) {
1111+
setup() {
11131112
const randomId = createElementId()
1114-
const triggerRandomId = `trigger-${randomId}`
1115-
1116-
const triggerButton = ref()
1117-
1118-
const { top, bottom } = useElementBounding(triggerButton)
1119-
const { top: boundaryTop, bottom: boundaryBottom } = useElementBounding(toRef(() => props.boundariesElement))
1120-
const { height: windowHeight } = useWindowSize()
1121-
const maxMenuHeight = computed(() => Math.max(
1122-
// Either expand to the top
1123-
Math.min(
1124-
// max height is the top position of the trigger minus the header height minus the wedge and the padding
1125-
top.value - 84,
1126-
// and also limited to the space in the boundary
1127-
top.value - boundaryTop.value,
1128-
),
1129-
// or expand to the bottom
1130-
Math.min(
1131-
// the max height is the window height minus current position of the trigger minus the wedge and padding
1132-
windowHeight.value - bottom.value - 34,
1133-
// and limit to the available space in the boundary
1134-
boundaryBottom.value - bottom.value,
1135-
),
1136-
))
11371113
11381114
return {
1139-
triggerButton,
1140-
maxMenuHeight,
1141-
11421115
randomId,
1143-
triggerRandomId,
11441116
}
11451117
},
11461118
@@ -1397,17 +1369,18 @@ export default {
13971369
// Get the inner v-popper element that defines the popover height (from floating-vue)
13981370
const inner = this.$refs.menu.closest('.v-popper__inner')
13991371
const height = this.$refs.menu.clientHeight
1372+
const maxMenuHeight = this.getMaxMenuHeight()
14001373
14011374
// If the popover height is limited by the max-height (scrollbars shown) limit the height to half of the last element
1402-
if (height > this.maxMenuHeight) {
1375+
if (height > maxMenuHeight) {
14031376
// sum of action heights
14041377
let currentHeight = 0
14051378
// last action height
14061379
let actionHeight = 0
14071380
for (const action of this.$refs.menuList.children) {
14081381
// If the max height would be overflown by half of the current element,
14091382
// then we limit the height to the half of the previous element
1410-
if ((currentHeight + action.clientHeight / 2) > this.maxMenuHeight) {
1383+
if ((currentHeight + action.clientHeight / 2) > maxMenuHeight) {
14111384
inner.style.height = `${currentHeight - actionHeight / 2}px`
14121385
break
14131386
}
@@ -1420,6 +1393,28 @@ export default {
14201393
}
14211394
},
14221395
1396+
getMaxMenuHeight() {
1397+
const { top, bottom } = this.$refs.triggerButton?.$el.getBoundingClientRect() ?? { top: 0, bottom: 0 }
1398+
const { top: boundaryTop, bottom: boundaryBottom } = this.boundariesElement?.getBoundingClientRect() ?? { top: 0, bottom: window.innerHeight }
1399+
1400+
return Math.max(
1401+
// Either expand to the top
1402+
Math.min(
1403+
// max height is the top position of the trigger minus the header height minus the wedge and the padding
1404+
top - 84,
1405+
// and also limited to the space in the boundary
1406+
top - boundaryTop,
1407+
),
1408+
// or expand to the bottom
1409+
Math.min(
1410+
// the max height is the window height minus current position of the trigger minus the wedge and padding
1411+
window.innerHeight - bottom - 34,
1412+
// and limit to the available space in the boundary
1413+
boundaryBottom - bottom,
1414+
),
1415+
)
1416+
},
1417+
14231418
// MENU KEYS & FOCUS MANAGEMENT
14241419
/**
14251420
* @return {HTMLElement|null}

0 commit comments

Comments
 (0)