@m3ui-vue/m3ui-vue 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,259 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onMounted, onUnmounted, provide, ref } from 'vue'
2
+ import { computed, Fragment, inject, nextTick, onMounted, onUnmounted, provide, ref, useSlots, watch, type VNode } from 'vue'
3
+ import MIcon from './MIcon.vue'
4
+ import MMenuDivider from './MMenuDivider.vue'
3
5
 
4
6
  const props = withDefaults(
5
7
  defineProps<{
6
8
  /** Which edge of the trigger the dropdown aligns to. */
7
9
  align?: 'left' | 'right'
10
+ /**
11
+ * How items with a `#children` slot behave.
12
+ * `'flyout'` opens a hover-positioned side panel (desktop).
13
+ * `'push'` replaces the panel's own content with the submenu and a
14
+ * back header — no positioning math, works with touch. Useful for mobile.
15
+ */
16
+ submenuMode?: 'flyout' | 'push'
17
+ /**
18
+ * `'standard'` is M3's baseline menu — square-ish 4dp corners
19
+ * (`MenuTokens.ContainerShape`/`CornerExtraSmall`).
20
+ * `'expressive'` is M3's rounder "vertical menu" styling — 16dp corners
21
+ * (`SegmentedMenuTokens.ContainerShape`/`CornerLarge`). Combine with
22
+ * `<MMenuDivider gap />` to split the panel into independently-rounded
23
+ * groups with a visible gap between them, instead of a plain line.
24
+ */
25
+ variant?: 'standard' | 'expressive'
8
26
  }>(),
9
- { align: 'right' },
27
+ { align: 'right', submenuMode: 'flyout', variant: 'standard' },
10
28
  )
11
29
 
30
+ const slots = useSlots()
31
+
32
+ function flattenVNodes(vnodes: VNode[]): VNode[] {
33
+ const out: VNode[] = []
34
+ for (const vnode of vnodes) {
35
+ if (vnode.type === Fragment && Array.isArray(vnode.children)) {
36
+ out.push(...flattenVNodes(vnode.children as VNode[]))
37
+ } else {
38
+ out.push(vnode)
39
+ }
40
+ }
41
+ return out
42
+ }
43
+
44
+ function isGapDivider(vnode: VNode): boolean {
45
+ if (vnode.type !== MMenuDivider) return false
46
+ const gap = (vnode.props as { gap?: unknown } | null)?.gap
47
+ return gap === '' || gap === true || gap === 'true'
48
+ }
49
+
50
+ // Splits the default slot's content into groups at each `<MMenuDivider gap />`
51
+ // — only used by the 'expressive' variant to render independently-rounded
52
+ // group boxes. A plain `<MMenuDivider />` (no `gap`) stays a normal in-line
53
+ // divider inside a single group, same as 'standard'.
54
+ const groups = computed(() => {
55
+ if (props.variant !== 'expressive') return null
56
+ const raw = flattenVNodes((slots.default?.({ close }) ?? []) as VNode[])
57
+ const result: VNode[][] = [[]]
58
+ for (const vnode of raw) {
59
+ if (isGapDivider(vnode)) result.push([])
60
+ else result[result.length - 1]!.push(vnode)
61
+ }
62
+ return result.filter(g => g.length > 0)
63
+ })
64
+ const isGrouped = computed(() => !!groups.value && groups.value.length > 1)
65
+
66
+ type NavEntry = { icon?: string, header?: () => any, content?: () => any }
67
+ const navStack = ref<NavEntry[]>([])
68
+ const currentNav = computed(() => navStack.value[navStack.value.length - 1])
69
+ const navDirection = ref<'forward' | 'backward'>('forward')
70
+
71
+ // Driven by the Web Animations API rather than Vue's CSS-class transition
72
+ // hooks — with dynamic (direction-dependent) enter/leave classes on a
73
+ // Transition with no `mode`, Vue's from->active->to class swap unreliably
74
+ // never completed (elements got stuck straddling from/active with the
75
+ // animation never actually running), so this drives it directly instead.
76
+ const slideDuration = 220
77
+ function navSlideEnter(el: Element, done: () => void) {
78
+ const dir = navDirection.value === 'forward' ? 1 : -1
79
+ const anim = (el as HTMLElement).animate(
80
+ [
81
+ { transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
82
+ { transform: 'translateX(0%)', opacity: 1 },
83
+ ],
84
+ { duration: slideDuration, easing: 'cubic-bezier(0.05,0.7,0.1,1)' },
85
+ )
86
+ anim.onfinish = done
87
+ }
88
+ function navSlideLeave(el: Element, done: () => void) {
89
+ const dir = navDirection.value === 'forward' ? -1 : 1
90
+ const htmlEl = el as HTMLElement
91
+ htmlEl.style.position = 'absolute'
92
+ htmlEl.style.insetInline = '0'
93
+ htmlEl.style.top = '0'
94
+ const anim = htmlEl.animate(
95
+ [
96
+ { transform: 'translateX(0%)', opacity: 1 },
97
+ { transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
98
+ ],
99
+ { duration: slideDuration, easing: 'cubic-bezier(0.3,0,0.8,0.15)' },
100
+ )
101
+ anim.onfinish = done
102
+ }
103
+
104
+ // The real DropdownMenuContent in Menu.kt animates scale (0.8 -> 1) and alpha
105
+ // (0 -> 1) with actual springs (MotionSchemeKeyTokens.FastSpatial/FastEffects
106
+ // on the Standard scheme, StandardMotionTokens: scale dampingRatio 0.9/
107
+ // stiffness 1400, alpha dampingRatio 1.0/stiffness 3800) — not a duration+
108
+ // easing tween, which is why a cubic-bezier stand-in read as an abrupt cut on
109
+ // close (a bezier can't carry a spring's momentum). But running the *close*
110
+ // as its own independent spring toward the opposite target isn't right
111
+ // either: alpha (stiffness 3800) settles much faster than scale (stiffness
112
+ // 1400), so on close the panel fades to invisible well before it finishes
113
+ // shrinking — you never actually see the shrink. On open this isn't a
114
+ // problem (it becomes visible early, *then* you watch it keep growing), but
115
+ // close needs to be the literal time-reverse of open, not a forward
116
+ // simulation toward reversed targets, so the shrink stays visible the whole
117
+ // time and only the fade races ahead right at the very end (mirroring how
118
+ // the fade led at the very start of open). Simulated once (open direction
119
+ // only) and played back forwards for enter, backwards for leave.
120
+ //
121
+ // A damped spring approaches its target exponentially, so it keeps "settling"
122
+ // long after the motion is visually done — with a tight (0.001) tolerance on
123
+ // both position *and* velocity, roughly the last third of the recorded
124
+ // trajectory is values within a fraction of a percent of the target, visually
125
+ // indistinguishable from it. Reversed for close, that flat tail lands at the
126
+ // *start* instead, so nothing visibly happens for the first ~80ms before the
127
+ // close animation actually appears to begin. Trimmed on position alone with a
128
+ // much looser tolerance instead, since that's what's actually visible.
129
+ let cachedTrajectory: { scale: number, alpha: number }[] | null = null
130
+ const trajectoryStep = 1 / 240
131
+ function openTrajectory() {
132
+ if (cachedTrajectory) return cachedTrajectory
133
+ const samples: { scale: number, alpha: number }[] = []
134
+ let scale = 0.8
135
+ let scaleVel = 0
136
+ let alpha = 0
137
+ let alphaVel = 0
138
+ const scaleDamping = 0.9
139
+ const scaleStiffness = 1400
140
+ const alphaDamping = 1.0
141
+ const alphaStiffness = 3800
142
+ for (let t = 0; t < 1; t += trajectoryStep) {
143
+ samples.push({ scale, alpha })
144
+ scaleVel += (-scaleStiffness * (scale - 1) - 2 * scaleDamping * Math.sqrt(scaleStiffness) * scaleVel) * trajectoryStep
145
+ scale += scaleVel * trajectoryStep
146
+ alphaVel += (-alphaStiffness * (alpha - 1) - 2 * alphaDamping * Math.sqrt(alphaStiffness) * alphaVel) * trajectoryStep
147
+ alpha += alphaVel * trajectoryStep
148
+ const visuallySettled = Math.abs(scale - 1) < 0.003 && Math.abs(alpha - 1) < 0.003
149
+ if (visuallySettled) break
150
+ }
151
+ samples.push({ scale: 1, alpha: 1 })
152
+ cachedTrajectory = samples
153
+ return samples
154
+ }
155
+
156
+ // Vue interrupts and reverses this mid-flight when the menu is toggled
157
+ // quickly (close while still opening, or vice versa) — it calls the other
158
+ // hook on the same still-mounted element without waiting for `done()`. Both
159
+ // `currentIdx` (how far along the trajectory we are, so a reversal continues
160
+ // smoothly from wherever it currently is instead of snapping back to a fixed
161
+ // start) and `cancelActive` (so the previous rAF loop actually stops instead
162
+ // of running alongside the new one, fighting over the same style every
163
+ // frame) have to live outside this function to survive that interruption.
164
+ let currentIdx = 0
165
+ let cancelActive: (() => void) | null = null
166
+
167
+ function playTrajectory(el: Element, done: () => void, opening: boolean) {
168
+ cancelActive?.()
169
+ const htmlEl = el as HTMLElement
170
+ const samples = openTrajectory()
171
+ const last = samples.length - 1
172
+ const direction = opening ? 1 : -1
173
+ const target = opening ? last : 0
174
+ let lastTime = 0
175
+ let rafId = 0
176
+ let cancelled = false
177
+
178
+ function apply(idx: number) {
179
+ const sample = samples[Math.round(Math.max(0, Math.min(last, idx)))]!
180
+ htmlEl.style.transform = `scale(${sample.scale})`
181
+ htmlEl.style.opacity = String(Math.min(1, Math.max(0, sample.alpha)))
182
+ }
183
+
184
+ function step(now: number) {
185
+ if (cancelled) return
186
+ const dtSteps = lastTime ? (now - lastTime) / 1000 / trajectoryStep : 1
187
+ lastTime = now
188
+ currentIdx = Math.max(0, Math.min(last, currentIdx + direction * dtSteps))
189
+ apply(currentIdx)
190
+ if ((opening && currentIdx >= target) || (!opening && currentIdx <= target)) {
191
+ cancelActive = null
192
+ done()
193
+ return
194
+ }
195
+ rafId = requestAnimationFrame(step)
196
+ }
197
+
198
+ cancelActive = () => { cancelled = true; cancelAnimationFrame(rafId) }
199
+ apply(currentIdx)
200
+ rafId = requestAnimationFrame(step)
201
+ }
202
+ function panelEnter(el: Element, done: () => void) {
203
+ playTrajectory(el, done, true)
204
+ }
205
+ function panelLeave(el: Element, done: () => void) {
206
+ playTrajectory(el, done, false)
207
+ }
208
+
209
+ function pushNav(entry: NavEntry) {
210
+ navDirection.value = 'forward'
211
+ navStack.value.push(entry)
212
+ nextTick(() => focusFirstItem())
213
+ }
214
+
215
+ function popNav() {
216
+ navDirection.value = 'backward'
217
+ navStack.value.pop()
218
+ nextTick(() => focusFirstItem())
219
+ }
220
+
12
221
  const open = ref(false)
13
222
  const triggerEl = ref<HTMLElement | null>(null)
14
223
  const dropdownEl = ref<HTMLElement | null>(null)
15
224
  const dropStyle = ref<Record<string, string>>({})
16
225
 
226
+ // A menu can be nested inside another MMenu/MContextMenu's slot (e.g. a
227
+ // "Language" picker menu inside a "More options" overflow menu) — since both
228
+ // Teleport straight to <body>, the outer one's panel DOM never contains the
229
+ // inner one's, so the outer's outside-click check would otherwise see a click
230
+ // inside the nested menu as "outside" and close (unmount) itself on
231
+ // mousedown, before the inner button's own click can fire. Sharing one
232
+ // registry of open panel elements across the whole logical (not DOM) menu
233
+ // tree via provide/inject fixes that for arbitrary nesting depth.
234
+ const panelRegistry = inject<Set<HTMLElement>>('m-menu-panel-registry', new Set())
235
+ provide('m-menu-panel-registry', panelRegistry)
236
+
237
+ watch(dropdownEl, (el, oldEl) => {
238
+ if (oldEl) panelRegistry.delete(oldEl)
239
+ if (el) panelRegistry.add(el)
240
+ })
241
+
242
+ onUnmounted(() => {
243
+ if (dropdownEl.value) panelRegistry.delete(dropdownEl.value)
244
+ })
245
+
246
+ // Separate from panelRegistry above: that one is shared all the way down the
247
+ // nesting chain so a click inside a descendant menu never closes an ancestor.
248
+ // This one is scoped to just this menu's *direct* children (e.g. "Language"
249
+ // and "Color palette", both nested inside the same "More options" menu) —
250
+ // without it, opening one no longer closes the other (since panelRegistry now
251
+ // treats a click on either as "inside" the shared ancestor), so two sibling
252
+ // pickers could stay open at once. Only one child of the same parent open at
253
+ // a time, like an accordion; doesn't affect unrelated top-level menus.
254
+ const siblingGroup = inject<{ current: (() => void) | null } | null>('m-menu-sibling-group', null)
255
+ provide('m-menu-sibling-group', { current: null })
256
+
17
257
  function computePos() {
18
258
  if (!triggerEl.value) return
19
259
  const rect = triggerEl.value.getBoundingClientRect()
@@ -61,37 +301,57 @@ function moveFocus(dir: 1 | -1) {
61
301
  }
62
302
 
63
303
  function toggle() {
64
- if (!open.value) computePos()
304
+ if (!open.value) {
305
+ if (siblingGroup && siblingGroup.current && siblingGroup.current !== close) {
306
+ siblingGroup.current()
307
+ }
308
+ if (siblingGroup) siblingGroup.current = close
309
+ computePos()
310
+ navStack.value = []
311
+ } else if (siblingGroup?.current === close) {
312
+ siblingGroup.current = null
313
+ }
65
314
  open.value = !open.value
66
315
  if (open.value) focusFirstItem()
67
316
  }
68
317
 
69
318
  function close() {
319
+ if (siblingGroup?.current === close) siblingGroup.current = null
70
320
  open.value = false
71
321
  }
72
322
 
73
323
  provide('m-menu-close', close)
324
+ provide('m-menu-nav', { mode: props.submenuMode, push: pushNav })
74
325
  defineExpose({ close, open })
75
326
 
76
327
  function onOutsideClick(e: MouseEvent) {
77
328
  const t = e.target as Node
78
329
  if (triggerEl.value?.contains(t)) return
79
- if (dropdownEl.value?.contains(t)) return
330
+ for (const panel of panelRegistry) {
331
+ if (panel.contains(t)) return
332
+ }
80
333
  if ((t as Element).closest?.('.m3-submenu')) return
81
334
  close()
82
335
  }
83
336
 
337
+ // Scrolling inside any panel of this menu tree (own, or a nested menu's
338
+ // Teleported panel) isn't an "outside" scroll — same registry as onOutsideClick
84
339
  function onScroll(e: Event) {
85
340
  if (!open.value) return
86
- if (dropdownEl.value?.contains(e.target as Node)) return
87
- if (!triggerEl.value) return
88
- const rect = triggerEl.value.getBoundingClientRect()
89
- if (rect.bottom < 0 || rect.top > window.innerHeight) { close(); return }
90
- computePos()
341
+ const t = e.target as Node
342
+ for (const panel of panelRegistry) {
343
+ if (panel.contains(t)) return
344
+ }
345
+ if ((t as Element).closest?.('.m3-submenu')) return
346
+ close()
91
347
  }
92
348
 
93
349
  function onKeydown(e: KeyboardEvent) {
94
- if (e.key === 'Escape') { close(); return }
350
+ if (e.key === 'Escape') {
351
+ if (navStack.value.length) popNav()
352
+ else close()
353
+ return
354
+ }
95
355
  if (!open.value) return
96
356
  if (e.key === 'ArrowDown') { e.preventDefault(); moveFocus(1) }
97
357
  else if (e.key === 'ArrowUp') { e.preventDefault(); moveFocus(-1) }
@@ -107,6 +367,7 @@ onUnmounted(() => {
107
367
  document.removeEventListener('mousedown', onOutsideClick)
108
368
  document.removeEventListener('keydown', onKeydown)
109
369
  window.removeEventListener('scroll', onScroll, true)
370
+ cancelActive?.()
110
371
  })
111
372
 
112
373
  const origin = computed(() =>
@@ -120,22 +381,55 @@ const origin = computed(() =>
120
381
  </div>
121
382
 
122
383
  <Teleport to="body">
123
- <Transition
124
- enter-active-class="transition-[opacity,transform] duration-150 ease-[cubic-bezier(0.05,0.7,0.1,1)]"
125
- enter-from-class="opacity-0 scale-[0.8]"
126
- enter-to-class="opacity-100 scale-100"
127
- leave-active-class="transition-[opacity,transform] duration-150 ease-[cubic-bezier(0.3,0,0.8,0.15)]"
128
- leave-from-class="opacity-100 scale-100"
129
- leave-to-class="opacity-0 scale-[0.8]"
130
- >
384
+ <Transition :css="false" @enter="panelEnter" @leave="panelLeave">
131
385
  <div
132
386
  v-if="open"
133
387
  ref="dropdownEl"
134
- class="fixed z-500 min-w-48 overflow-hidden rounded-xs bg-surface-container shadow-elevation-2"
388
+ class="fixed z-500 min-w-48"
389
+ :class="[
390
+ variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
391
+ isGrouped ? '' : 'shadow-elevation-2',
392
+ ]"
135
393
  :style="{ ...dropStyle, transformOrigin: origin }"
136
394
  >
137
- <div class="overflow-y-auto py-1" :style="{ maxHeight: dropStyle.maxHeight }">
138
- <slot :close="close" />
395
+ <!-- overflow-hidden (for the rounded-corner clip and to clip the push
396
+ submenu's slide) lives on this inner wrapper, never together with
397
+ shadow-elevation-2 on the same box — overflow-hidden clips an
398
+ element's own box-shadow too, so the two have to be on separate
399
+ elements or the shadow gets cut off -->
400
+ <div
401
+ class="overflow-hidden"
402
+ :class="[
403
+ variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
404
+ isGrouped ? '' : 'bg-surface-container',
405
+ ]"
406
+ >
407
+ <div class="relative overflow-y-auto overscroll-contain py-1" :style="{ maxHeight: dropStyle.maxHeight }">
408
+ <Transition :css="false" @enter="navSlideEnter" @leave="navSlideLeave">
409
+ <div v-if="currentNav" :key="navStack.length">
410
+ <button
411
+ type="button"
412
+ class="flex w-full items-center gap-3 border-b border-outline-variant px-4 py-2.5 text-left text-body-large text-on-surface outline-none transition-colors hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
413
+ @click="popNav"
414
+ >
415
+ <MIcon name="chevron_left" :size="20" class="shrink-0 text-on-surface-variant" />
416
+ <MIcon v-if="currentNav.icon" :name="currentNav.icon" :size="20" class="shrink-0 text-on-surface-variant" />
417
+ <span class="flex-1 truncate"><component :is="() => currentNav?.header?.()" /></span>
418
+ </button>
419
+ <component :is="() => currentNav?.content?.()" />
420
+ </div>
421
+ <div v-else key="root">
422
+ <div v-if="isGrouped" class="flex flex-col gap-1 px-1.5">
423
+ <div v-for="(group, i) in groups" :key="i" class="rounded-lg shadow-elevation-2">
424
+ <div class="overflow-hidden rounded-lg bg-surface-container">
425
+ <component :is="() => group" />
426
+ </div>
427
+ </div>
428
+ </div>
429
+ <slot v-else :close="close" />
430
+ </div>
431
+ </Transition>
432
+ </div>
139
433
  </div>
140
434
  </div>
141
435
  </Transition>
@@ -1,3 +1,19 @@
1
+ <script setup lang="ts">
2
+ withDefaults(
3
+ defineProps<{
4
+ /**
5
+ * Marks this as a group boundary for `MMenu`/`MContextMenu`'s
6
+ * `variant="expressive"` — instead of rendering this divider in place,
7
+ * the parent menu splits its panel into two independently-rounded group
8
+ * boxes with a small gap between them. Has no effect outside an
9
+ * `expressive` menu, where it renders as a normal divider line.
10
+ */
11
+ gap?: boolean
12
+ }>(),
13
+ { gap: false },
14
+ )
15
+ </script>
16
+
1
17
  <template>
2
18
  <hr class="my-1 border-outline-variant" />
3
19
  </template>
@@ -8,9 +8,12 @@ const props = withDefaults(defineProps<{
8
8
  to?: string | Record<string, any>
9
9
  disabled?: boolean
10
10
  danger?: boolean
11
+ /** Keep the menu open after this item is clicked (e.g. checkable/toggle items). */
12
+ keepOpen?: boolean
11
13
  }>(), {
12
14
  disabled: false,
13
15
  danger: false,
16
+ keepOpen: false,
14
17
  })
15
18
 
16
19
  const emit = defineEmits<{ click: [] }>()
@@ -19,19 +22,16 @@ const slots = useSlots()
19
22
  const tag = computed(() => props.to ? 'RouterLink' : 'button')
20
23
  const hasChildren = computed(() => !!slots.children)
21
24
  const menuClose = inject<(() => void) | null>('m-menu-close', null)
25
+ const nav = inject<{
26
+ mode: 'flyout' | 'push'
27
+ push: (entry: { icon?: string, header?: () => any, content?: () => any }) => void
28
+ } | null>('m-menu-nav', null)
22
29
 
23
- function handleClick() {
24
- if (props.disabled || hasChildren.value) return
25
- emit('click')
26
- menuClose?.()
27
- }
28
- const showSub = ref(false)
29
30
  const itemEl = ref<HTMLElement>()
31
+ const showSub = ref(false)
30
32
  const subStyle = ref<Record<string, string>>({})
31
33
 
32
- function onMouseEnter() {
33
- if (!hasChildren.value || props.disabled) return
34
- showSub.value = true
34
+ function positionSub() {
35
35
  if (!itemEl.value) return
36
36
  const rect = itemEl.value.getBoundingClientRect()
37
37
  const right = rect.right + 200 > window.innerWidth
@@ -45,13 +45,49 @@ function onMouseEnter() {
45
45
  }
46
46
  }
47
47
 
48
- function onMouseLeave(e: MouseEvent) {
48
+ function toggleSub() {
49
+ if (showSub.value) {
50
+ showSub.value = false
51
+ return
52
+ }
53
+ positionSub()
54
+ showSub.value = true
55
+ }
56
+
57
+ function handleClick() {
58
+ if (props.disabled) return
59
+
60
+ if (hasChildren.value) {
61
+ if (nav?.mode === 'push') {
62
+ nav.push({ icon: props.icon, header: slots.default, content: slots.children })
63
+ } else {
64
+ toggleSub()
65
+ }
66
+ return
67
+ }
68
+
69
+ emit('click')
70
+ if (!props.keepOpen) menuClose?.()
71
+ }
72
+
73
+ // Desktop hover convenience for the flyout variant — ignored on touch/pen so a
74
+ // tap doesn't fire a spurious pointerleave (relatedTarget is null on touch)
75
+ // and close the submenu before its click event can land.
76
+ function onPointerEnter(e: PointerEvent) {
77
+ if (e.pointerType !== 'mouse' || !hasChildren.value || props.disabled) return
78
+ positionSub()
79
+ showSub.value = true
80
+ }
81
+
82
+ function onPointerLeave(e: PointerEvent) {
83
+ if (e.pointerType !== 'mouse') return
49
84
  const related = e.relatedTarget as Element | null
50
85
  if (related?.closest('.m3-submenu')) return
51
86
  showSub.value = false
52
87
  }
53
88
 
54
- function onSubLeave(e: MouseEvent) {
89
+ function onSubPointerLeave(e: PointerEvent) {
90
+ if (e.pointerType !== 'mouse') return
55
91
  const related = e.relatedTarget as Element | null
56
92
  if (related?.closest('.m3-submenu') || itemEl.value?.contains(related as Node)) return
57
93
  showSub.value = false
@@ -61,8 +97,8 @@ function onSubLeave(e: MouseEvent) {
61
97
  <template>
62
98
  <div
63
99
  ref="itemEl"
64
- @mouseenter="onMouseEnter"
65
- @mouseleave="onMouseLeave"
100
+ @pointerenter="onPointerEnter"
101
+ @pointerleave="onPointerLeave"
66
102
  >
67
103
  <component
68
104
  :is="tag"
@@ -75,6 +111,8 @@ function onSubLeave(e: MouseEvent) {
75
111
  !disabled && !danger ? 'text-on-surface hover:bg-on-surface/8' : '',
76
112
  ]"
77
113
  :disabled="disabled || undefined"
114
+ :aria-haspopup="hasChildren ? 'menu' : undefined"
115
+ :aria-expanded="hasChildren ? showSub : undefined"
78
116
  @click="handleClick"
79
117
  >
80
118
  <MIcon v-if="icon" :name="icon" :size="20" class="shrink-0" :class="danger ? 'text-error' : 'text-on-surface-variant'" />
@@ -83,8 +121,8 @@ function onSubLeave(e: MouseEvent) {
83
121
  <MIcon v-if="hasChildren" name="chevron_right" :size="18" class="shrink-0 text-on-surface-variant" />
84
122
  </component>
85
123
 
86
- <!-- Submenu -->
87
- <Teleport v-if="hasChildren" to="body">
124
+ <!-- Submenu (flyout variant only — "push" mode is rendered by the root MMenu/MContextMenu panel) -->
125
+ <Teleport v-if="hasChildren && nav?.mode !== 'push'" to="body">
88
126
  <Transition
89
127
  enter-active-class="transition-opacity duration-100"
90
128
  enter-from-class="opacity-0"
@@ -93,11 +131,15 @@ function onSubLeave(e: MouseEvent) {
93
131
  >
94
132
  <div
95
133
  v-if="showSub"
96
- class="m3-submenu min-w-44 overflow-hidden rounded-xs bg-surface-container py-1 shadow-elevation-2"
134
+ class="m3-submenu min-w-44 rounded-xs shadow-elevation-2"
97
135
  :style="subStyle"
98
- @mouseleave="onSubLeave"
136
+ @pointerleave="onSubPointerLeave"
99
137
  >
100
- <slot name="children" />
138
+ <!-- overflow-hidden lives here, separate from shadow-elevation-2 above —
139
+ overflow-hidden clips an element's own box-shadow too -->
140
+ <div class="overflow-hidden rounded-xs bg-surface-container py-1">
141
+ <slot name="children" />
142
+ </div>
101
143
  </div>
102
144
  </Transition>
103
145
  </Teleport>
@@ -104,6 +104,12 @@ function scrollToActive() {
104
104
  }
105
105
 
106
106
  function onGlobalKeydown(e: KeyboardEvent) {
107
+ // Every mounted MSpotlightSearch listens for its own hotkey independently —
108
+ // if more than one is mounted at once (e.g. an app-wide instance plus a
109
+ // page-local demo), a single keypress would otherwise open all of them.
110
+ // The first instance to handle it calls preventDefault(), which the rest
111
+ // check for and bail on, so only one ever claims a given keypress.
112
+ if (e.defaultPrevented) return
107
113
  const tag = (e.target as HTMLElement).tagName
108
114
  if (tag === 'INPUT' || tag === 'TEXTAREA' || (e.target as HTMLElement).isContentEditable) return
109
115
  if (e.key === props.hotkey && !e.metaKey && !e.ctrlKey && !e.altKey) {
@@ -9,6 +9,7 @@
9
9
  /* ---------------------------------------------------------------------- */
10
10
  @theme {
11
11
  --font-sans: 'Roboto', system-ui, -apple-system, sans-serif;
12
+ --font-mono: 'Roboto Mono', ui-monospace, 'Fira Code', Consolas, monospace;
12
13
 
13
14
  /* Color roles */
14
15
  --color-primary: #6750a4;