diff options
Diffstat (limited to 'packages/frontend/src/components/MkMenu.vue')
| -rw-r--r-- | packages/frontend/src/components/MkMenu.vue | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/packages/frontend/src/components/MkMenu.vue b/packages/frontend/src/components/MkMenu.vue index 736f48ea3c..951a0b2815 100644 --- a/packages/frontend/src/components/MkMenu.vue +++ b/packages/frontend/src/components/MkMenu.vue @@ -62,7 +62,7 @@ SPDX-License-Identifier: AGPL-3.0-only </template> <script lang="ts"> -import { Ref, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'; +import { Ref, computed, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'; import { focusPrev, focusNext } from '@/scripts/focus.js'; import MkSwitchButton from '@/components/MkSwitch.button.vue'; import { MenuItem, InnerMenuItem, MenuPending, MenuAction, MenuSwitch, MenuParent } from '@/types/menu'; @@ -90,19 +90,19 @@ const emit = defineEmits<{ (ev: 'hide'): void; }>(); -let itemsEl = $shallowRef<HTMLDivElement>(); +const itemsEl = shallowRef<HTMLDivElement>(); -let items2: InnerMenuItem[] = $ref([]); +const items2 = ref<InnerMenuItem[]>([]); -let child = $shallowRef<InstanceType<typeof XChild>>(); +const child = shallowRef<InstanceType<typeof XChild>>(); -let keymap = $computed(() => ({ +const keymap = computed(() => ({ 'up|k|shift+tab': focusUp, 'down|j|tab': focusDown, 'esc': close, })); -let childShowingItem = $ref<MenuItem | null>(); +const childShowingItem = ref<MenuItem | null>(); let preferClick = isTouchUsing || props.asDrawer; @@ -115,22 +115,22 @@ watch(() => props.items, () => { if (item && 'then' in item) { // if item is Promise items[i] = { type: 'pending' }; item.then(actualItem => { - items2[i] = actualItem; + items2.value[i] = actualItem; }); } } - items2 = items as InnerMenuItem[]; + items2.value = items as InnerMenuItem[]; }, { immediate: true, }); const childMenu = ref<MenuItem[] | null>(); -let childTarget = $shallowRef<HTMLElement | null>(); +const childTarget = shallowRef<HTMLElement | null>(); function closeChild() { childMenu.value = null; - childShowingItem = null; + childShowingItem.value = null; } function childActioned() { @@ -139,8 +139,8 @@ function childActioned() { } const onGlobalMousedown = (event: MouseEvent) => { - if (childTarget && (event.target === childTarget || childTarget.contains(event.target))) return; - if (child && child.checkHit(event)) return; + if (childTarget.value && (event.target === childTarget.value || childTarget.value.contains(event.target))) return; + if (child.value && child.value.checkHit(event)) return; closeChild(); }; @@ -177,10 +177,10 @@ async function showChildren(item: MenuParent, ev: MouseEvent) { }); emit('hide'); } else { - childTarget = ev.currentTarget ?? ev.target; + childTarget.value = ev.currentTarget ?? ev.target; // これでもリアクティビティは保たれる childMenu.value = children; - childShowingItem = item; + childShowingItem.value = item; } } @@ -209,7 +209,7 @@ function switchItem(item: MenuSwitch & { ref: any }) { onMounted(() => { if (props.viaKeyboard) { nextTick(() => { - if (itemsEl) focusNext(itemsEl.children[0], true, false); + if (itemsEl.value) focusNext(itemsEl.value.children[0], true, false); }); } |