📱 Trigger section context menu on long-press (#586)

This commit is contained in:
Alicia Sykes 2022-03-31 15:52:11 +01:00
parent d077b1b9c9
commit 1187787ef3
2 changed files with 16 additions and 10 deletions

View File

@ -12,7 +12,8 @@
tabIndex="-1" tabIndex="-1"
> >
<label :for="sectionKey" class="lbl-toggle" tabindex="-1" <label :for="sectionKey" class="lbl-toggle" tabindex="-1"
@mouseup.right="openContextMenu" @contextmenu.prevent> @mouseup.right="openContextMenu" @contextmenu.prevent
@long-press="openContextMenu" v-longPress="500">
<Icon v-if="icon" :icon="icon" size="small" :url="title" class="section-icon" /> <Icon v-if="icon" :icon="icon" size="small" :url="title" class="section-icon" />
<h3>{{ title }}</h3> <h3>{{ title }}</h3>
<EditModeIcon v-if="isEditMode" @click="openEditModal" <EditModeIcon v-if="isEditMode" @click="openEditModal"
@ -29,7 +30,7 @@
</template> </template>
<script> <script>
import longPress from '@/directives/LongPress';
import { localStorageKeys } from '@/utils/defaults'; import { localStorageKeys } from '@/utils/defaults';
import Icon from '@/components/LinkItems/ItemIcon.vue'; import Icon from '@/components/LinkItems/ItemIcon.vue';
import EditModeIcon from '@/assets/interface-icons/interactive-editor-edit-mode.svg'; import EditModeIcon from '@/assets/interface-icons/interactive-editor-edit-mode.svg';
@ -53,6 +54,9 @@ export default {
EditModeIcon, EditModeIcon,
OpenIcon, OpenIcon,
}, },
directives: {
longPress,
},
computed: { computed: {
isEditMode() { isEditMode() {
return this.$store.state.editMode; return this.$store.state.editMode;

View File

@ -11,6 +11,7 @@
:cutToHeight="displayData.cutToHeight" :cutToHeight="displayData.cutToHeight"
@openEditSection="openEditSection" @openEditSection="openEditSection"
@openContextMenu="openContextMenu" @openContextMenu="openContextMenu"
:id="`section-outer-${groupId}`"
> >
<!-- If no items, show message --> <!-- If no items, show message -->
<div v-if="isEmpty" class="no-items"> <div v-if="isEmpty" class="no-items">
@ -294,13 +295,14 @@ export default {
}, },
/* Open custom context menu, and set position */ /* Open custom context menu, and set position */
openContextMenu(e) { openContextMenu(e) {
this.contextMenuOpen = true; this.contextMenuOpen = true; // Open context menu
if (e && window) { // If mouse position not set, use section coordinates
const sectionOuterId = `section-outer-${this.groupId}`;
const sectionPosition = document.getElementById(sectionOuterId).getBoundingClientRect();
this.contextPos = { this.contextPos = {
posX: e.clientX + window.pageXOffset, posX: (e.clientX || sectionPosition.right - 10) + window.pageXOffset,
posY: e.clientY + window.pageYOffset, posY: (e.clientY || sectionPosition.top + 30) + window.pageYOffset,
}; };
}
}, },
/* Hide the right-click context menu */ /* Hide the right-click context menu */
closeContextMenu() { closeContextMenu() {