Skip to content

Commit dd0fb2e

Browse files
committed
fix(files): open menu on right click position
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 89ee859 commit dd0fb2e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

apps/files/src/components/FileEntry.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ export default defineComponent({
353353
return this.actionsMenuStore.opened === this.uniqueId
354354
},
355355
set(opened) {
356+
// Only reset when opening a new menu
357+
if (opened) {
358+
// Reset any right click position override on close
359+
// Wait for css animation to be done
360+
const root = this.$root.$el as HTMLElement
361+
root.style.removeProperty('--mouse-pos-x')
362+
root.style.removeProperty('--mouse-pos-y')
363+
}
364+
356365
this.actionsMenuStore.opened = opened ? this.uniqueId : null
357366
},
358367
},
@@ -390,6 +399,13 @@ export default defineComponent({
390399
return
391400
}
392401
402+
const root = this.$root.$el as HTMLElement
403+
const contentRect = root.getBoundingClientRect()
404+
// Using Math.min/max to prevent the menu from going out of the AppContent
405+
// 200 = max width of the menu
406+
root.style.setProperty('--mouse-pos-x', Math.max(contentRect.left, Math.min(event.clientX, event.clientX - 200)) + 'px')
407+
root.style.setProperty('--mouse-pos-y', Math.max(contentRect.top, event.clientY - contentRect.top) + 'px')
408+
393409
// If the clicked row is in the selection, open global menu
394410
const isMoreThanOneSelected = this.selectedFiles.length > 1
395411
this.actionsMenuStore.opened = this.isSelected && isMoreThanOneSelected ? 'global' : this.uniqueId

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,24 @@ export default Vue.extend({
327327
})
328328
</script>
329329

330-
<style lang="scss" scoped>
330+
<style lang="scss">
331+
// Allow right click to define the position of the menu
332+
// only if defined
333+
.app-content[style*="mouse-pos-x"] .v-popper__popper {
334+
transform: translate3d(var(--mouse-pos-x), var(--mouse-pos-y), 0px) !important;
335+
336+
// If the menu is too close to the bottom, we move it up
337+
&[data-popper-placement="top"] {
338+
transform: translate3d(var(--mouse-pos-x), calc(var(--mouse-pos-y) - 50vh), 0px) !important;
339+
}
340+
// Hide arrow if floating
341+
.v-popper__arrow-container {
342+
display: none;
343+
}
344+
}
345+
</style>
331346

347+
<style lang="scss" scoped>
332348
:deep(.button-vue--icon-and-text, .files-list__row-action-sharing-status) {
333349
.button-vue__text {
334350
color: var(--color-primary-element);

0 commit comments

Comments
 (0)