2022-07-17 21:06:33 +09:00
|
|
|
<template>
|
|
|
|
<div ref="el" class="sfhdhdhr">
|
2023-02-13 11:56:01 +09:00
|
|
|
<FocusTrap v-bind:active="isActive">
|
|
|
|
<MkMenu ref="menu" :items="items" :align="align" :width="width" :as-drawer="false" @close="onChildClosed"/>
|
|
|
|
</FocusTrap>
|
2022-07-17 21:06:33 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { on } from 'events';
|
|
|
|
import { nextTick, onBeforeUnmount, onMounted, onUnmounted, ref, watch } from 'vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkMenu from './MkMenu.vue';
|
2022-07-17 21:06:33 +09:00
|
|
|
import { MenuItem } from '@/types/menu';
|
2023-02-13 11:56:01 +09:00
|
|
|
import { FocusTrap } from 'focus-trap-vue';
|
2022-07-17 21:06:33 +09:00
|
|
|
import * as os from '@/os';
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
items: MenuItem[];
|
|
|
|
targetElement: HTMLElement;
|
2022-07-17 23:18:05 +09:00
|
|
|
rootElement: HTMLElement;
|
2022-07-17 21:06:33 +09:00
|
|
|
width?: number;
|
|
|
|
viaKeyboard?: boolean;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'closed'): void;
|
|
|
|
(ev: 'actioned'): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const el = ref<HTMLElement>();
|
|
|
|
const align = 'left';
|
|
|
|
|
|
|
|
function setPosition() {
|
2022-07-17 23:18:05 +09:00
|
|
|
const rootRect = props.rootElement.getBoundingClientRect();
|
2022-07-17 21:06:33 +09:00
|
|
|
const rect = props.targetElement.getBoundingClientRect();
|
2022-07-17 23:18:05 +09:00
|
|
|
const left = props.targetElement.offsetWidth;
|
|
|
|
const top = (rect.top - rootRect.top) - 8;
|
2022-07-17 21:06:33 +09:00
|
|
|
el.value.style.left = left + 'px';
|
|
|
|
el.value.style.top = top + 'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
function onChildClosed(actioned?: boolean) {
|
|
|
|
if (actioned) {
|
|
|
|
emit('actioned');
|
|
|
|
} else {
|
|
|
|
emit('closed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
setPosition();
|
|
|
|
nextTick(() => {
|
|
|
|
setPosition();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
checkHit: (ev: MouseEvent) => {
|
|
|
|
return (ev.target === el.value || el.value.contains(ev.target));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.sfhdhdhr {
|
2022-07-17 23:18:05 +09:00
|
|
|
position: absolute;
|
2022-07-17 21:06:33 +09:00
|
|
|
}
|
|
|
|
</style>
|