Skip to content

Commit 26756ea

Browse files
authored
Merge pull request #51872 from nextcloud/backport/51863/stable30
[stable30] fix(files): right click actions menu flicker
2 parents fb4781c + 8f70742 commit 26756ea

4 files changed

Lines changed: 42 additions & 22 deletions

File tree

apps/files/src/components/FileEntry/FileEntryActions.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
type="tertiary"
2323
:force-menu="enabledInlineActions.length === 0 /* forceMenu only if no inline actions */"
2424
:inline="enabledInlineActions.length"
25-
:open.sync="openedMenu"
26-
@close="openedSubmenu = null">
25+
:open="openedMenu"
26+
@close="onMenuClose"
27+
@closed="onMenuClosed">
2728
<!-- Default actions list-->
2829
<NcActionButton v-for="action, index in enabledMenuActions"
2930
:key="action.id"
@@ -242,7 +243,7 @@ export default defineComponent({
242243
},
243244
244245
watch: {
245-
// Close any submenu when the menu is closed
246+
// Close any submenu when the menu state changes
246247
openedMenu() {
247248
this.openedSubmenu = null
248249
},
@@ -335,6 +336,20 @@ export default defineComponent({
335336
})
336337
},
337338
339+
onMenuClose() {
340+
// We reset the submenu state when the menu is closing
341+
this.openedSubmenu = null
342+
},
343+
344+
onMenuClosed() {
345+
// TODO: remove timeout once https://github.com/nextcloud-libraries/nextcloud-vue/pull/6683 is merged
346+
// and updated on server.
347+
setTimeout(() => {
348+
// We reset the actions menu state when the menu is finally closed
349+
this.openedMenu = false
350+
}, 100)
351+
},
352+
338353
t,
339354
},
340355
})

apps/files/src/components/FileEntryMixin.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,16 @@ export default defineComponent({
176176
return this.actionsMenuStore.opened === this.uniqueId.toString()
177177
},
178178
set(opened) {
179-
this.actionsMenuStore.opened = opened ? this.uniqueId.toString() : null
179+
// If the menu is opened on another file entry, we ignore closed events
180+
if (opened === false && this.actionsMenuStore.opened !== this.uniqueId.toString()) {
181+
return
182+
}
183+
184+
// If opened, we specify the current file id
185+
// else we set it to null to close the menu
186+
this.actionsMenuStore.opened = opened
187+
? this.uniqueId.toString()
188+
: null
180189
},
181190
},
182191

@@ -243,21 +252,16 @@ export default defineComponent({
243252
},
244253

245254
openedMenu() {
246-
if (this.openedMenu === false) {
247-
// TODO: This timeout can be removed once `close` event only triggers after the transition
248-
// ref: https://github.com/nextcloud-libraries/nextcloud-vue/pull/6065
249-
window.setTimeout(() => {
250-
if (this.openedMenu) {
251-
// was reopened while the animation run
252-
return
253-
}
254-
// Reset any right menu position potentially set
255-
const root = document.getElementById('app-content-vue')
256-
if (root !== null) {
257-
root.style.removeProperty('--mouse-pos-x')
258-
root.style.removeProperty('--mouse-pos-y')
259-
}
260-
}, 300)
255+
// Checking if the menu is really closed and not
256+
// just a change in the open state to another file entry.
257+
if (this.actionsMenuStore.opened === null) {
258+
// Reset any right menu position potentially set
259+
logger.debug('All actions menu closed, resetting right menu position...')
260+
const root = this.$el?.closest('main.app-content') as HTMLElement
261+
if (root !== null) {
262+
root.style.removeProperty('--mouse-pos-x')
263+
root.style.removeProperty('--mouse-pos-y')
264+
}
261265
}
262266
},
263267
},
@@ -298,6 +302,7 @@ export default defineComponent({
298302
const contentRect = root.getBoundingClientRect()
299303
// Using Math.min/max to prevent the menu from going out of the AppContent
300304
// 200 = max width of the menu
305+
logger.debug('Setting actions menu position...')
301306
root.style.setProperty('--mouse-pos-x', Math.max(0, event.clientX - contentRect.left - 200) + 'px')
302307
root.style.setProperty('--mouse-pos-y', Math.max(0, event.clientY - contentRect.top) + 'px')
303308
} else {

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)