This commit is contained in:
tamaina 2023-08-03 02:11:27 +00:00
parent 718021f15c
commit 225eabb19d
3 changed files with 27 additions and 15 deletions

View File

@ -39,7 +39,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSwitchButton :class="$style.switchButton" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)" /> <MkSwitchButton :class="$style.switchButton" :checked="item.ref" :disabled="item.disabled" @toggle="switchItem(item)" />
<span :class="$style.switchText">{{ item.text }}</span> <span :class="$style.switchText">{{ item.text }}</span>
</button> </button>
<div v-else-if="item.type === 'parent'" role="menuitem" :tabindex="i" :class="[$style.item, $style.parent, { [$style.childShowing]: childShowingItem === item }]" @mousedown.stop="showChildren(item, $event)"> <div v-else-if="item.type === 'parent'" role="menuitem" :tabindex="i" :class="[$style.item, $style.parent, { [$style.childShowing]: childShowingItem === item }]" @mouseenter="showChildren(item, $event)" @click.stop="showChildren(item, $event)">
<i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i> <i v-if="item.icon" class="ti-fw" :class="[$style.icon, item.icon]"></i>
<span>{{ item.text }}</span> <span>{{ item.text }}</span>
<span :class="$style.caret"><i class="ti ti-chevron-right ti-fw"></i></span> <span :class="$style.caret"><i class="ti ti-chevron-right ti-fw"></i></span>
@ -135,8 +135,12 @@ function childActioned() {
close(true); close(true);
} }
function onGlobalMousedown(event: MouseEvent) { const onGlobalMousedown = (event: MouseEvent) => {
console.log('globalmousedown') console.log('globalmousedown', itemsEl);
if (!itemsEl || !document.body.contains(itemsEl)) {
document.removeEventListener('mousedown', onGlobalMousedown);
return;
}
if (childTarget && (event.target === childTarget || childTarget.contains(event.target))) return; if (childTarget && (event.target === childTarget || childTarget.contains(event.target))) return;
if (child && child.checkHit(event)) return; if (child && child.checkHit(event)) return;
closeChild(); closeChild();
@ -186,10 +190,6 @@ async function showChildren(item: MenuParent, ev: MouseEvent) {
} }
} }
function onmousedown(ev: MouseEvent) {
ev.stopImmediatePropagation();
}
function clicked(fn: MenuAction, ev: MouseEvent) { function clicked(fn: MenuAction, ev: MouseEvent) {
fn(ev); fn(ev);
close(true); close(true);

View File

@ -296,7 +296,6 @@ const onOpened = () => {
// //
const el = content!.children[0]; const el = content!.children[0];
el.addEventListener('mousedown', ev => { el.addEventListener('mousedown', ev => {
ev.stopPropagation();
console.log('mousedown'); console.log('mousedown');
contentClicking = true; contentClicking = true;
window.addEventListener('mouseup', ev => { window.addEventListener('mouseup', ev => {
@ -306,7 +305,7 @@ const onOpened = () => {
contentClicking = false; contentClicking = false;
}, 100); }, 100);
}, { passive: true, once: true }); }, { passive: true, once: true });
}, { passive: true, capture: true }); }, { passive: true });
}; };
const alignObserver = new ResizeObserver((entries, observer) => { const alignObserver = new ResizeObserver((entries, observer) => {

View File

@ -4,8 +4,8 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<MkModal ref="modal" v-slot="{ type, maxHeight }" :manualShowing="manualShowing" :zPriority="'high'" :src="src" :transparentBg="true" @click="click" @close="emit('closing')" @closed="emit('closed')"> <MkModal ref="modal" v-slot="{ type, maxHeight }" :manualShowing="manualShowing" :zPriority="'high'" :src="src" :transparentBg="true" @click="click" @close="onModalClose" @closed="closed">
<MkMenu :items="items" :align="align" :width="width" :max-height="maxHeight" :asDrawer="type === 'drawer'" :class="{ [$style.drawer]: type === 'drawer' }" @close="_close" @hide="manualShowing = false"/> <MkMenu :items="items" :align="align" :width="width" :max-height="maxHeight" :asDrawer="type === 'drawer'" :class="{ [$style.drawer]: type === 'drawer' }" @close="onMenuClose" @hide="manualShowing = false"/>
</MkModal> </MkModal>
</template> </template>
@ -15,7 +15,7 @@ import MkModal from './MkModal.vue';
import MkMenu from './MkMenu.vue'; import MkMenu from './MkMenu.vue';
import { MenuItem } from '@/types/menu'; import { MenuItem } from '@/types/menu';
defineProps<{ const props = defineProps<{
items: MenuItem[]; items: MenuItem[];
align?: 'center' | string; align?: 'center' | string;
width?: number; width?: number;
@ -28,20 +28,33 @@ const emit = defineEmits<{
(ev: 'closing'): void; (ev: 'closing'): void;
}>(); }>();
console.log('popup menu modal setup', props.items);
let modal = $shallowRef<InstanceType<typeof MkModal>>(); let modal = $shallowRef<InstanceType<typeof MkModal>>();
const manualShowing = ref(true); const manualShowing = ref(true);
function click() { function click() {
console.log('popup menu click'); console.log('popup menu modal click', props.items);
close(); close();
} }
function _close() { function onModalClose() {
console.log('popup menu close event'); console.log('popup menu modal close', props.items);
emit('closing');
}
function onMenuClose() {
console.log('popup menu menu click', props.items);
close(); close();
} }
function closed() {
console.log('popup menu modal closed', props.items);
emit('closed');
}
function close() { function close() {
console.log('popup menu close', props.items);
if (!modal) return; if (!modal) return;
manualShowing.value = false; manualShowing.value = false;
modal.close(); modal.close();