Skip to content

Commit bcf5bad

Browse files
committed
chore: add context menu debug logging
1 parent 785558b commit bcf5bad

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/components/common/ContextMenuSurface.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
/* eslint-disable no-console */
23
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue';
34
import { useEventListener } from '@vueuse/core';
45
import { computePosition, flip, offset, platform, shift } from '@floating-ui/dom';
@@ -42,11 +43,18 @@
4243
const floatingReference = ref<HTMLElement | null>(null);
4344
const scrollPosition = reactive({ x: 0, y: 0 });
4445
46+
const logPrefix = '[ContextMenuSurface]';
47+
4548
const updateFloatingPosition = async () => {
4649
if (
4750
!(floatingReference.value instanceof HTMLElement) ||
4851
!(contextMenuPanel.value instanceof HTMLElement)
4952
) {
53+
console.debug(logPrefix, 'Skipping Floating UI computePosition; missing elements', {
54+
hasReference: floatingReference.value instanceof HTMLElement,
55+
hasPanel: contextMenuPanel.value instanceof HTMLElement,
56+
position: { ...contextMenuPosition },
57+
});
5058
floatingStyles.left = `${contextMenuPosition.x}px`;
5159
floatingStyles.top = `${contextMenuPosition.y}px`;
5260
return;
@@ -60,10 +68,12 @@
6068
6169
floatingStyles.left = `${x}px`;
6270
floatingStyles.top = `${y}px`;
71+
console.debug(logPrefix, 'Updated floating position', { x, y });
6372
};
6473
6574
const closeMenu = () => {
6675
if (!isOpen.value) return;
76+
console.debug(logPrefix, 'Closing menu');
6777
isOpen.value = false;
6878
outsideEventsArmed.value = false;
6979
floatingReference.value = null;
@@ -97,6 +107,11 @@
97107
98108
const wasOpen = isOpen.value;
99109
outsideEventsArmed.value = false;
110+
console.debug(logPrefix, 'Opening menu', {
111+
wasOpen,
112+
origin,
113+
targetTag: (target as HTMLElement | null)?.tagName,
114+
});
100115
if (!wasOpen) {
101116
isOpen.value = true;
102117
emit('open');
@@ -107,6 +122,7 @@
107122
108123
await nextTick();
109124
await updateFloatingPosition();
125+
console.debug(logPrefix, 'Arming outside events');
110126
outsideEventsArmed.value = true;
111127
};
112128
@@ -118,6 +134,7 @@
118134
await nextTick();
119135
floatingReference.value = contextMenuAnchor.value;
120136
await updateFloatingPosition();
137+
console.debug(logPrefix, 'Menu opened; updated position after watcher');
121138
},
122139
);
123140
@@ -172,8 +189,19 @@
172189
const isWithinPanelAttribute = targetElement?.closest(`[data-cy="${props.dataCy}"]`);
173190
174191
if (target && (isInsidePanel || isInsideButton || isWithinPanelAttribute)) {
192+
console.debug(logPrefix, 'Outside handler ignored (inside menu/button)', {
193+
targetTag: targetElement?.tagName,
194+
isInsidePanel,
195+
isInsideButton,
196+
isWithinPanelAttribute: Boolean(isWithinPanelAttribute),
197+
});
175198
return;
176199
}
200+
console.debug(logPrefix, 'Outside pointer detected; closing', {
201+
targetTag: targetElement?.tagName,
202+
armed: outsideEventsArmed.value,
203+
closeOnOutside: props.closeOnOutsidePointer,
204+
});
177205
closeMenu();
178206
};
179207

0 commit comments

Comments
 (0)