1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-07-26 11:25:05 +02:00
Files
misskey/packages/frontend/src/components/MkMenu.child.vue
syuilo 38be94b2a3 enhance(frontend): improve nested popup menu ux (#17187)
* wip

* Update MkMenu.vue

* wip

* wip

* Update MkMenu.vue

* wip

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue

* 💢

* Update MkMenu.vue

* Update MkMenu.vue

* Update MkMenu.vue
2026-04-07 16:52:30 +09:00

105 lines
2.3 KiB
Vue

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div ref="el" :class="$style.root">
<MkMenu
:items="items"
:align="align"
:width="width"
:asDrawer="false"
:debugDisablePredictionCone="debugDisablePredictionCone"
:debugShowPredictionCone="debugShowPredictionCone"
@close="onChildClosed"
/>
</div>
</template>
<script lang="ts" setup>
import { nextTick, onMounted, onUnmounted, provide, useTemplateRef, watch } from 'vue';
import MkMenu from './MkMenu.vue';
import type { MenuItem } from '@/types/menu.js';
const props = defineProps<{
items: MenuItem[];
anchorElement: HTMLElement;
rootElement: HTMLElement;
width?: number;
debugDisablePredictionCone?: boolean;
debugShowPredictionCone?: boolean;
}>();
const emit = defineEmits<{
(ev: 'closed'): void;
(ev: 'actioned'): void;
}>();
provide('isNestingMenu', true);
const el = useTemplateRef('el');
const align = 'left';
const SCROLLBAR_THICKNESS = 16;
function setPosition() {
if (el.value == null) return;
const rootRect = props.rootElement.getBoundingClientRect();
const parentRect = props.anchorElement.getBoundingClientRect();
const myRect = el.value.getBoundingClientRect();
let left = props.anchorElement.offsetWidth;
let top = (parentRect.top - rootRect.top) - 8;
if (rootRect.left + left + myRect.width >= (window.innerWidth - SCROLLBAR_THICKNESS)) {
left = -myRect.width;
}
if (rootRect.top + top + myRect.height >= (window.innerHeight - SCROLLBAR_THICKNESS)) {
top = top - ((rootRect.top + top + myRect.height) - (window.innerHeight - SCROLLBAR_THICKNESS));
}
el.value.style.left = left + 'px';
el.value.style.top = top + 'px';
}
function onChildClosed(actioned?: boolean) {
if (actioned) {
emit('actioned');
} else {
emit('closed');
}
}
watch(() => props.anchorElement, () => {
setPosition();
});
const ro = new ResizeObserver((entries, observer) => {
setPosition();
});
onMounted(() => {
if (el.value) ro.observe(el.value);
setPosition();
nextTick(() => {
setPosition();
});
});
onUnmounted(() => {
ro.disconnect();
});
defineExpose({
rootElement: el,
checkHit: (ev: MouseEvent) => {
return (ev.target === el.value || el.value?.contains(ev.target as Node));
},
});
</script>
<style lang="scss" module>
.root {
position: absolute;
}
</style>