Skip to content

Commit efc307f

Browse files
authored
Merge pull request #51873 from nextcloud/backport/51863/stable29
[stable29] fix(files): right click actions menu flicker
2 parents 1d9931c + 28102d3 commit efc307f

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
type="tertiary"
4040
:force-menu="enabledInlineActions.length === 0 /* forceMenu only if no inline actions */"
4141
:inline="enabledInlineActions.length"
42-
:open.sync="openedMenu"
43-
@close="openedSubmenu = null">
42+
:open="openedMenu"
43+
@close="onMenuClose"
44+
@closed="onMenuClosed">
4445
<!-- Default actions list-->
4546
<NcActionButton v-for="action, index in enabledMenuActions"
4647
:key="action.id"
@@ -257,7 +258,7 @@ export default defineComponent({
257258
},
258259
259260
watch: {
260-
// Close any submenu when the menu is closed
261+
// Close any submenu when the menu state changes
261262
openedMenu() {
262263
this.openedSubmenu = null
263264
},
@@ -350,6 +351,20 @@ export default defineComponent({
350351
})
351352
},
352353
354+
onMenuClose() {
355+
// We reset the submenu state when the menu is closing
356+
this.openedSubmenu = null
357+
},
358+
359+
onMenuClosed() {
360+
// TODO: remove timeout once https://github.com/nextcloud-libraries/nextcloud-vue/pull/6683 is merged
361+
// and updated on server.
362+
setTimeout(() => {
363+
// We reset the actions menu state when the menu is finally closed
364+
this.openedMenu = false
365+
}, 100)
366+
},
367+
353368
t,
354369
},
355370
})

apps/files/src/components/FileEntryMixin.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,16 @@ export default defineComponent({
183183
return this.actionsMenuStore.opened === this.uniqueId.toString()
184184
},
185185
set(opened) {
186-
this.actionsMenuStore.opened = opened ? this.uniqueId.toString() : null
186+
// If the menu is opened on another file entry, we ignore closed events
187+
if (opened === false && this.actionsMenuStore.opened !== this.uniqueId.toString()) {
188+
return
189+
}
190+
191+
// If opened, we specify the current file id
192+
// else we set it to null to close the menu
193+
this.actionsMenuStore.opened = opened
194+
? this.uniqueId.toString()
195+
: null
187196
},
188197
},
189198

@@ -248,21 +257,16 @@ export default defineComponent({
248257
},
249258

250259
openedMenu() {
251-
if (this.openedMenu === false) {
252-
// TODO: This timeout can be removed once `close` event only triggers after the transition
253-
// ref: https://github.com/nextcloud-libraries/nextcloud-vue/pull/6065
254-
window.setTimeout(() => {
255-
if (this.openedMenu) {
256-
// was reopened while the animation run
257-
return
258-
}
259-
// Reset any right menu position potentially set
260-
const root = document.getElementById('app-content-vue')
261-
if (root !== null) {
262-
root.style.removeProperty('--mouse-pos-x')
263-
root.style.removeProperty('--mouse-pos-y')
264-
}
265-
}, 300)
260+
// Checking if the menu is really closed and not
261+
// just a change in the open state to another file entry.
262+
if (this.actionsMenuStore.opened === null) {
263+
// Reset any right menu position potentially set
264+
logger.debug('All actions menu closed, resetting right menu position...')
265+
const root = this.$el?.closest('main.app-content') as HTMLElement
266+
if (root !== null) {
267+
root.style.removeProperty('--mouse-pos-x')
268+
root.style.removeProperty('--mouse-pos-y')
269+
}
266270
}
267271
},
268272
},
@@ -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)