@sentropic/design-system-svelte 0.38.0 → 0.39.0

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.
package/dist/Menu.svelte CHANGED
@@ -1,5 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import type { Component } from "svelte";
3
+ import type { SubMenuSide } from "./menu-cascade.js";
3
4
 
4
5
  export type MenuIconProps = {
5
6
  size?: number | string;
@@ -10,6 +11,13 @@
10
11
 
11
12
  export type MenuIcon = Component<MenuIconProps> | string;
12
13
 
14
+ export type MenuSubmenuSide = SubMenuSide;
15
+
16
+ export interface MenuSelectDetail {
17
+ path: string[];
18
+ item: MenuActionItem;
19
+ }
20
+
13
21
  export interface MenuActionItem {
14
22
  kind?: "item";
15
23
  label: string;
@@ -17,6 +25,8 @@
17
25
  disabled?: boolean;
18
26
  danger?: boolean;
19
27
  icon?: MenuIcon;
28
+ children?: MenuItem[];
29
+ selected?: boolean;
20
30
  }
21
31
 
22
32
  export interface MenuDividerItem {
@@ -30,15 +40,27 @@
30
40
 
31
41
  export type MenuItem = MenuActionItem | MenuDividerItem | MenuGroupItem;
32
42
 
33
- let groupIdCounter = 0;
34
- function nextGroupId(): string {
35
- groupIdCounter += 1;
36
- return `st-menu-group-${groupIdCounter}`;
37
- }
43
+ let menuInstanceCounter = 0;
38
44
  </script>
39
45
 
40
46
  <script lang="ts">
47
+ import { ChevronLeft, ChevronRight } from "@lucide/svelte";
48
+ import { getContext, onDestroy, tick, untrack } from "svelte";
41
49
  import type { HTMLAttributes } from "svelte/elements";
50
+ import {
51
+ CLOSE_DELAY,
52
+ MENU_HOST_CONTEXT,
53
+ OPEN_DELAY,
54
+ SUBMENU_DEFAULT_WIDTH,
55
+ VIEWPORT_MARGIN,
56
+ computeSubMenuPosition,
57
+ pointInSafeTriangle,
58
+ resolvePreferredSide,
59
+ toContainingBlockPosition,
60
+ type CascadePoint,
61
+ type MenuHostContext,
62
+ type ResolvedSubMenuSide
63
+ } from "./menu-cascade.js";
42
64
 
43
65
  type MenuProps = Omit<HTMLAttributes<HTMLDivElement>, "class" | "onselect"> & {
44
66
  label: string;
@@ -47,7 +69,8 @@
47
69
  dismissOnSelect?: boolean;
48
70
  class?: string;
49
71
  dense?: boolean;
50
- onselect?: (value: string) => void;
72
+ submenuSide?: MenuSubmenuSide;
73
+ onselect?: (value: string, detail?: MenuSelectDetail) => void;
51
74
  };
52
75
 
53
76
  let {
@@ -57,104 +80,853 @@
57
80
  dismissOnSelect = false,
58
81
  class: className,
59
82
  dense = false,
83
+ submenuSide = "auto",
60
84
  onselect,
61
85
  ...rest
62
86
  }: MenuProps = $props();
63
87
 
64
- let host: HTMLDivElement | undefined = $state();
65
- function getFocusableItems(): HTMLButtonElement[] {
88
+ const instanceId = ++menuInstanceCounter;
89
+ const fallbackRootId = `st-menu-${instanceId}`;
90
+ const hostContext = getContext<MenuHostContext | undefined>(MENU_HOST_CONTEXT);
91
+ const isNested = hostContext !== undefined && hostContext !== null;
92
+ // Internal host flag (set by OverflowMenu via context, never a public
93
+ // prop): a flat menu renders the origin/main `st-overflowMenu__*` DOM
94
+ // (AC-37). Cascade branches are unaffected.
95
+ const useOverflowClasses = hostContext?.overflowClasses === true;
96
+ const rootId = $derived(
97
+ (rest as { id?: string }).id ?? hostContext?.rootMenuId ?? fallbackRootId
98
+ );
99
+
100
+ let host: HTMLElement | undefined = $state();
101
+ // Internal open state is an index path (never keys), so duplicate sibling
102
+ // keys cannot open or close together (§2.3, D7).
103
+ let openPath: number[] = $state([]);
104
+ // Roving tabindex target per level (raw item index); falls back to the
105
+ // first enabled item when unset.
106
+ let roving: number[] = $state([]);
107
+ // Resolved opening side per parent level (drives chevron + opening arrow).
108
+ let levelSides: ResolvedSubMenuSide[] = $state([]);
109
+ let levelPositions: { top: number; left: number; maxHeight?: number; capped: boolean }[] =
110
+ $state([]);
111
+
112
+ // Hover timers and triangle apex are intentionally NOT reactive: the
113
+ // `items`-validation $effect below cancels all timers, so tracking them
114
+ // would make every armed hover cancel itself on the next flush (§3.3).
115
+ let openTimer: ReturnType<typeof setTimeout> | undefined = undefined;
116
+ let closeTimer: ReturnType<typeof setTimeout> | undefined = undefined;
117
+ let closeLevel = -1;
118
+ let safeApex: CascadePoint | null = null;
119
+ let safeLevel = -1;
120
+ let warnedDuplicate = false;
121
+ const warnedDepthKeys = new Set<string>();
122
+
123
+ function isAction(item: MenuItem): item is MenuActionItem {
124
+ return item.kind === undefined || item.kind === "item";
125
+ }
126
+
127
+ function hasSubMenu(item: MenuItem): item is MenuActionItem & { children: MenuItem[] } {
128
+ return (
129
+ isAction(item) &&
130
+ Array.isArray(item.children) &&
131
+ item.children.length > 0
132
+ );
133
+ }
134
+
135
+ function treeHasCascade(list: MenuItem[]): boolean {
136
+ for (const item of list) {
137
+ if (hasSubMenu(item)) return true;
138
+ if (isAction(item) && Array.isArray(item.children)) {
139
+ if (treeHasCascade(item.children)) return true;
140
+ }
141
+ }
142
+ return false;
143
+ }
144
+
145
+ const hasCascade = $derived(treeHasCascade(items));
146
+
147
+ function keyOf(item: MenuActionItem): string {
148
+ return item.value;
149
+ }
150
+
151
+ function levelItems(depth: number): MenuItem[] {
152
+ let list = items;
153
+ for (let d = 0; d < depth; d += 1) {
154
+ const parent = list[openPath[d]];
155
+ if (!parent || !isAction(parent) || !Array.isArray(parent.children)) return [];
156
+ list = parent.children;
157
+ }
158
+ return list;
159
+ }
160
+
161
+ function pathKeys(indexPath: number[]): string[] {
162
+ const keys: string[] = [];
163
+ let list = items;
164
+ for (const index of indexPath) {
165
+ const item = list[index];
166
+ if (!item || !isAction(item)) break;
167
+ keys.push(keyOf(item));
168
+ list = Array.isArray(item.children) ? item.children : [];
169
+ }
170
+ return keys;
171
+ }
172
+
173
+ function subId(depth: number, index: number): string {
174
+ return `${rootId}--sub-${depth}-${index}`;
175
+ }
176
+
177
+ function parentButtonId(depth: number, index: number): string {
178
+ return `${rootId}--parent-${depth}-${index}`;
179
+ }
180
+
181
+ function cancelOpenTimer() {
182
+ if (openTimer !== undefined) {
183
+ clearTimeout(openTimer);
184
+ openTimer = undefined;
185
+ }
186
+ }
187
+
188
+ function cancelCloseTimer() {
189
+ if (closeTimer !== undefined) {
190
+ clearTimeout(closeTimer);
191
+ closeTimer = undefined;
192
+ }
193
+ closeLevel = -1;
194
+ }
195
+
196
+ function cancelAllTimers() {
197
+ cancelOpenTimer();
198
+ cancelCloseTimer();
199
+ safeApex = null;
200
+ safeLevel = -1;
201
+ }
202
+
203
+ // Guards deferred positioning work so a pending tick/RAF never runs after
204
+ // unmount (§3.4 recompute, AC-38).
205
+ let destroyed = false;
206
+ let rafId: number | undefined = undefined;
207
+
208
+ function cancelDeferredPositions() {
209
+ if (rafId !== undefined && typeof cancelAnimationFrame === "function") {
210
+ cancelAnimationFrame(rafId);
211
+ rafId = undefined;
212
+ }
213
+ }
214
+
215
+ onDestroy(() => {
216
+ destroyed = true;
217
+ cancelAllTimers();
218
+ cancelDeferredPositions();
219
+ });
220
+
221
+ function levelRootEl(level: number): Element | null {
222
+ if (!host) return null;
223
+ // The flat root IS its own level 0 element (querySelector skips self).
224
+ if (host.matches(`[data-menu-level="${level}"]`)) return host;
225
+ return host.querySelector(`[data-menu-level="${level}"]`);
226
+ }
227
+
228
+ function levelButtons(level: number): HTMLButtonElement[] {
229
+ const levelRoot = levelRootEl(level);
230
+ if (!levelRoot) return [];
66
231
  return Array.from(
67
- host?.querySelectorAll<HTMLButtonElement>('[role="menuitem"]:not(:disabled)') ?? []
232
+ levelRoot.querySelectorAll<HTMLButtonElement>('[role="menuitem"]:not(:disabled)')
233
+ );
234
+ }
235
+
236
+ function rawIndexOf(button: HTMLButtonElement): number {
237
+ const raw = button.getAttribute("data-item-index");
238
+ return raw === null ? -1 : Number(raw);
239
+ }
240
+
241
+ function firstEnabledIndex(list: MenuItem[]): number {
242
+ for (let i = 0; i < list.length; i += 1) {
243
+ const item = list[i];
244
+ if (isAction(item) && !item.disabled) return i;
245
+ }
246
+ return -1;
247
+ }
248
+
249
+ function rovingTarget(depth: number, list: MenuItem[]): number {
250
+ const stored = roving[depth];
251
+ if (
252
+ stored !== undefined &&
253
+ list[stored] !== undefined &&
254
+ isAction(list[stored]) &&
255
+ !(list[stored] as MenuActionItem).disabled
256
+ ) {
257
+ return stored;
258
+ }
259
+ return firstEnabledIndex(list);
260
+ }
261
+
262
+ function focusButton(level: number, index: number) {
263
+ const levelRoot = levelRootEl(level);
264
+ const button = levelRoot?.querySelector<HTMLButtonElement>(
265
+ `[data-item-index="${index}"]`
68
266
  );
267
+ roving[level] = index;
268
+ button?.focus();
269
+ }
270
+
271
+ function focusFirstEnabled(level: number): boolean {
272
+ const buttons = levelButtons(level);
273
+ if (buttons.length === 0) return false;
274
+ roving[level] = rawIndexOf(buttons[0]);
275
+ buttons[0].focus();
276
+ return true;
69
277
  }
70
278
 
71
- function moveIndex(index: number, size: number, step: number) {
72
- if (size <= 0) return 0;
73
- return ((index + step) % size + size) % size;
279
+ function focusLevelIndex(buttons: HTMLButtonElement[], at: number, level: number) {
280
+ if (buttons.length === 0) return;
281
+ const size = buttons.length;
282
+ const target = ((at % size) + size) % size;
283
+ roving[level] = rawIndexOf(buttons[target]);
284
+ buttons[target].focus();
74
285
  }
75
286
 
76
- function focusAt(index: number) {
77
- const focusable = getFocusableItems();
78
- if (!focusable.length) return;
79
- const target = moveIndex(index, focusable.length, 0);
80
- focusable.forEach((button, idx) => {
81
- button.tabIndex = idx === target ? 0 : -1;
287
+ function schedulePositions() {
288
+ if (destroyed) return;
289
+ tick().then(() => {
290
+ if (destroyed) return;
291
+ computeAllPositions();
292
+ if (typeof requestAnimationFrame === "function") {
293
+ cancelDeferredPositions();
294
+ rafId = requestAnimationFrame(() => {
295
+ rafId = undefined;
296
+ if (!destroyed) computeAllPositions();
297
+ });
298
+ }
82
299
  });
83
- focusable[target]?.focus();
84
300
  }
85
301
 
86
- const classes = () =>
87
- ["st-menu", dense ? "st-menu--dense" : null, className].filter(Boolean).join(" ");
302
+ function findContainingBlock(element: HTMLElement): HTMLElement | null {
303
+ let node: HTMLElement | null = element.parentElement;
304
+ while (node) {
305
+ const style = getComputedStyle(node);
306
+ const transform = style.transform;
307
+ const filter = style.filter;
308
+ const perspective = style.perspective;
309
+ const contain = style.contain;
310
+ const willChange = style.willChange;
311
+ if (
312
+ (transform && transform !== "none") ||
313
+ (filter && filter !== "none") ||
314
+ (perspective && perspective !== "none") ||
315
+ (contain && /layout|paint|strict|content/.test(contain)) ||
316
+ (willChange && /transform|filter|perspective/.test(willChange))
317
+ ) {
318
+ return node;
319
+ }
320
+ node = node.parentElement;
321
+ }
322
+ return null;
323
+ }
88
324
 
89
- function selectItem(item: MenuActionItem) {
325
+ function computeLevelPosition(level: number) {
326
+ if (!host || typeof window === "undefined") return;
327
+ const parentIndex = openPath[level - 1];
328
+ if (parentIndex === undefined) return;
329
+ const levelRoot = levelRootEl(level - 1);
330
+ const panel = levelRootEl(level);
331
+ const button = levelRoot?.querySelector(
332
+ `[data-item-index="${parentIndex}"]`
333
+ );
334
+ if (!levelRoot || !panel || !button) return;
335
+ const menuRect = levelRoot.getBoundingClientRect();
336
+ const itemRect = button.getBoundingClientRect();
337
+ const panelRect = panel.getBoundingClientRect();
338
+ const vw = window.innerWidth;
339
+ const vh = window.innerHeight;
340
+ const solved = computeSubMenuPosition({
341
+ parentMenuRect: { left: menuRect.left, right: menuRect.right },
342
+ parentItemRect: { top: itemRect.top },
343
+ panelSize: { width: panelRect.width, height: panelRect.height },
344
+ viewport: { width: vw, height: vh },
345
+ preferredSide: submenuSide
346
+ });
347
+ const block = findContainingBlock(panel as HTMLElement);
348
+ const converted = toContainingBlockPosition(
349
+ { top: solved.top, left: solved.left },
350
+ block ? block.getBoundingClientRect() : null
351
+ );
352
+ levelSides[level - 1] = solved.side;
353
+ levelPositions[level - 1] = {
354
+ top: converted.top,
355
+ left: converted.left,
356
+ maxHeight: solved.maxHeight,
357
+ // Viewport-alone derivation: the measured width is the capped width
358
+ // once the cap style applies, so re-deriving from it would drop the
359
+ // cap on the next scroll/resize recompute (§3.4 step 3).
360
+ capped: vw < SUBMENU_DEFAULT_WIDTH + 2 * VIEWPORT_MARGIN
361
+ };
362
+ }
363
+
364
+ function computeAllPositions() {
365
+ if (!host || openPath.length === 0) return;
366
+ for (let level = 1; level <= openPath.length; level += 1) {
367
+ computeLevelPosition(level);
368
+ }
369
+ }
370
+
371
+ function closeDeepestFrom(level: number, focusParent: boolean) {
372
+ cancelAllTimers();
373
+ const parentLevel = level - 1;
374
+ const parentIndex = openPath[parentLevel];
375
+ openPath = openPath.slice(0, parentLevel);
376
+ if (focusParent && parentIndex !== undefined) {
377
+ focusButton(parentLevel, parentIndex);
378
+ }
379
+ }
380
+
381
+ function closeAll(focusTrigger: boolean) {
382
+ cancelAllTimers();
383
+ openPath = [];
384
+ if (isNested) {
385
+ if (hasCascade) hostContext?.requestClose({ focusTrigger });
386
+ } else if (dismissOnSelect) {
387
+ open = false;
388
+ }
389
+ }
390
+
391
+ function indexPathFor(depth: number, index: number): number[] {
392
+ return [...openPath.slice(0, depth), index];
393
+ }
394
+
395
+ function selectItem(item: MenuActionItem, fullPath: number[], modality: "pointer" | "keyboard") {
90
396
  if (item.disabled) return;
91
- onselect?.(item.value);
92
- if (dismissOnSelect) open = false;
397
+ const cascade = treeHasCascade(items);
398
+ if (cascade || isNested) {
399
+ // Nested menus always pass the item reference through the internal
400
+ // host channel, so duplicate sibling values relay the clicked row (the
401
+ // host strips it back to a single argument for flat menus, AC-01).
402
+ onselect?.(item.value, { path: pathKeys(fullPath), item });
403
+ } else {
404
+ // Flat menus keep the legacy single-argument call (AC-01).
405
+ onselect?.(item.value);
406
+ }
407
+ cancelAllTimers();
408
+ openPath = [];
409
+ if (isNested) {
410
+ if (cascade) hostContext?.requestClose({ focusTrigger: modality === "keyboard" });
411
+ } else if (dismissOnSelect) {
412
+ open = false;
413
+ }
93
414
  }
94
415
 
95
- function isAction(item: MenuItem): item is MenuActionItem {
96
- return item.kind === undefined || item.kind === "item";
416
+ function openParent(depth: number, index: number, focusFirst: boolean) {
417
+ cancelAllTimers();
418
+ openPath = [...openPath.slice(0, depth), index];
419
+ schedulePositions();
420
+ if (focusFirst) {
421
+ tick().then(() => {
422
+ if (destroyed) return;
423
+ // No enabled item: focus stays on the parent line (§3.2).
424
+ focusFirstEnabled(depth + 1);
425
+ });
426
+ }
427
+ }
428
+
429
+ function toggleParent(depth: number, index: number) {
430
+ cancelAllTimers();
431
+ if (openPath[depth] === index && openPath.length > depth) {
432
+ // Second click closes that level and deeper; focus unchanged (AC-29).
433
+ openPath = openPath.slice(0, depth);
434
+ } else {
435
+ openPath = [...openPath.slice(0, depth), index];
436
+ schedulePositions();
437
+ }
438
+ }
439
+
440
+ function isMouseEvent(event: Event): boolean {
441
+ return (event as PointerEvent).pointerType === "mouse";
442
+ }
443
+
444
+ function triangleForLevel(level: number): [CascadePoint, CascadePoint, CascadePoint] | null {
445
+ if (!host || safeApex === null || safeLevel !== level) return null;
446
+ const panel = levelRootEl(level + 1);
447
+ if (!panel) return null;
448
+ const rect = panel.getBoundingClientRect();
449
+ if (rect.width === 0 && rect.height === 0 && rect.left === 0 && rect.right === 0) {
450
+ return null;
451
+ }
452
+ const side: ResolvedSubMenuSide = levelSides[level] ?? resolvePreferredSide(submenuSide);
453
+ const edgeX = side === "right" ? rect.left : rect.right;
454
+ return [
455
+ { x: safeApex.x, y: safeApex.y },
456
+ { x: edgeX, y: rect.top - 4 },
457
+ { x: edgeX, y: rect.bottom + 4 }
458
+ ];
97
459
  }
98
460
 
99
- function onItemKeyDown(event: KeyboardEvent, item: MenuActionItem) {
100
- const focusable = getFocusableItems();
101
- const current = focusable.indexOf(event.currentTarget as HTMLButtonElement);
461
+ function pointInActiveTriangle(level: number, point: CascadePoint): boolean {
462
+ const triangle = triangleForLevel(level);
463
+ if (!triangle) return false;
464
+ return pointInSafeTriangle(point, triangle[0], triangle[1], triangle[2]);
465
+ }
466
+
467
+ function armClose(level: number) {
468
+ cancelCloseTimer();
469
+ closeLevel = level;
470
+ // Capture before the slice: the parent line of the closing level lives
471
+ // at openPath[level] while the timer is pending (§3.3 step 5).
472
+ const parentIndex = openPath[level];
473
+ closeTimer = setTimeout(() => {
474
+ const active = document.activeElement;
475
+ const closingRoots = host?.querySelectorAll(`[data-menu-level="${level + 1}"]`);
476
+ openPath = openPath.slice(0, level);
477
+ safeApex = null;
478
+ safeLevel = -1;
479
+ // Focus inside a pointer-closed level moves to its parent line (§3.3).
480
+ if (active && closingRoots) {
481
+ for (const root of closingRoots) {
482
+ if (root.contains(active)) {
483
+ if (parentIndex !== undefined) focusButton(level, parentIndex);
484
+ break;
485
+ }
486
+ }
487
+ }
488
+ closeTimer = undefined;
489
+ closeLevel = -1;
490
+ }, CLOSE_DELAY);
491
+ }
492
+
493
+ function onParentPointerEnter(depth: number, index: number, event: Event) {
494
+ if (!isMouseEvent(event) || !hasCascade) return;
495
+ const pointer = event as PointerEvent;
496
+ // Safe-triangle priority: crossings during the diagonal arm nothing (§3.3).
497
+ if (pointInActiveTriangle(depth, { x: pointer.clientX, y: pointer.clientY })) return;
498
+ cancelCloseTimer();
499
+ cancelOpenTimer();
500
+ openTimer = setTimeout(() => {
501
+ openTimer = undefined;
502
+ openPath = [...openPath.slice(0, depth), index];
503
+ schedulePositions();
504
+ }, OPEN_DELAY);
505
+ }
506
+
507
+ function onLeafPointerEnter(depth: number, event: Event) {
508
+ if (!isMouseEvent(event) || !hasCascade) return;
509
+ const pointer = event as PointerEvent;
510
+ if (pointInActiveTriangle(depth, { x: pointer.clientX, y: pointer.clientY })) return;
511
+ cancelOpenTimer();
512
+ // Another branch open at this level: arm its close (§3.3 step 2).
513
+ if (openPath.length > depth) {
514
+ armClose(depth);
515
+ }
516
+ }
517
+
518
+ function onParentPointerLeave(depth: number, index: number, event: Event) {
519
+ if (!isMouseEvent(event) || !hasCascade) return;
520
+ // Leaving before the hover delay must drop the pending open: the pointer
521
+ // is already gone, so the panel shall never appear (§3.3 step 2).
522
+ cancelOpenTimer();
523
+ if (openPath[depth] !== index) return;
524
+ const pointer = event as PointerEvent;
525
+ // Record the exit point as the triangle apex (§3.3 step 3, D9).
526
+ safeApex = { x: pointer.clientX, y: pointer.clientY };
527
+ safeLevel = depth;
528
+ armClose(depth);
529
+ }
530
+
531
+ function onHostPointerMove(event: Event) {
532
+ if (!isMouseEvent(event) || !hasCascade || safeApex === null) return;
533
+ const pointer = event as PointerEvent;
534
+ const point = { x: pointer.clientX, y: pointer.clientY };
535
+ const triangle = triangleForLevel(safeLevel);
536
+ if (!triangle) return;
537
+ // Test first, then refresh the apex (D9).
538
+ if (pointInSafeTriangle(point, triangle[0], triangle[1], triangle[2])) {
539
+ cancelCloseTimer();
540
+ safeApex = point;
541
+ return;
542
+ }
543
+ // Outside the triangle and over no open panel: exit away from the panel
544
+ // re-arms the 250 ms close (§3.3 step 4). The armed-level guard keeps a
545
+ // move stream from resetting the timer on every event.
546
+ const target = event.target as Element | null;
547
+ const inOpenPanel =
548
+ target?.closest?.('[data-menu-level]:not([data-menu-level="0"])') ?? null;
549
+ const parentButton = levelRootEl(safeLevel)?.querySelector(
550
+ `[data-item-index="${openPath[safeLevel] ?? -1}"]`
551
+ );
552
+ const inArmedParent =
553
+ parentButton?.closest(".st-menu__itemWrap")?.contains(target ?? null) ??
554
+ false;
555
+ if (!inOpenPanel && !inArmedParent) {
556
+ if (closeTimer === undefined || closeLevel !== safeLevel) {
557
+ armClose(safeLevel);
558
+ }
559
+ }
560
+ }
561
+
562
+ function onPanelPointerEnter(event: Event) {
563
+ if (!isMouseEvent(event) || !hasCascade) return;
564
+ cancelAllTimers();
565
+ }
566
+
567
+ function onPanelPointerLeave(depth: number, event: Event) {
568
+ if (!isMouseEvent(event) || !hasCascade) return;
569
+ armClose(depth);
570
+ }
571
+
572
+ function openingArrow(): string {
573
+ const side = resolvePreferredSide(submenuSide);
574
+ return side === "right" ? "ArrowRight" : "ArrowLeft";
575
+ }
576
+
577
+ function resolvedSideFor(depth: number, index: number): ResolvedSubMenuSide {
578
+ if (openPath[depth] === index && openPath.length > depth && levelSides[depth] !== undefined) {
579
+ return levelSides[depth];
580
+ }
581
+ return resolvePreferredSide(submenuSide);
582
+ }
583
+
584
+ /**
585
+ * Opening side for keyboard handling: inside a sub-menu the whole level
586
+ * shares its containing level's resolved side, so a flipped panel keeps
587
+ * one opening arrow for parents and leaves alike (§3.4, AC-06/AC-19).
588
+ * Depth 0 keeps the per-item rule (open parents use their resolved side).
589
+ */
590
+ function openingSideFor(
591
+ depth: number,
592
+ index: number,
593
+ item: MenuActionItem
594
+ ): ResolvedSubMenuSide {
595
+ if (depth >= 1 && levelSides[depth - 1] !== undefined) {
596
+ return levelSides[depth - 1];
597
+ }
598
+ if (hasSubMenu(item)) return resolvedSideFor(depth, index);
599
+ return openingArrow() === "ArrowRight" ? "right" : "left";
600
+ }
601
+
602
+ function onItemKeyDown(
603
+ event: KeyboardEvent,
604
+ depth: number,
605
+ index: number,
606
+ item: MenuActionItem
607
+ ) {
608
+ const levelRoot = levelRootEl(depth);
609
+ const buttons = levelRoot
610
+ ? Array.from(
611
+ levelRoot.querySelectorAll<HTMLButtonElement>('[role="menuitem"]:not(:disabled)')
612
+ )
613
+ : [];
614
+ const current = buttons.indexOf(event.currentTarget as HTMLButtonElement);
102
615
  if (event.key === "ArrowDown") {
103
616
  event.preventDefault();
104
- focusAt(current + 1);
617
+ focusLevelIndex(buttons, current + 1, depth);
105
618
  return;
106
619
  }
107
620
  if (event.key === "ArrowUp") {
108
621
  event.preventDefault();
109
- focusAt(current - 1);
622
+ focusLevelIndex(buttons, current - 1, depth);
110
623
  return;
111
624
  }
112
625
  if (event.key === "Home") {
113
626
  event.preventDefault();
114
- focusAt(0);
627
+ focusLevelIndex(buttons, 0, depth);
115
628
  return;
116
629
  }
117
630
  if (event.key === "End") {
118
631
  event.preventDefault();
119
- focusAt(focusable.length - 1);
632
+ focusLevelIndex(buttons, buttons.length - 1, depth);
120
633
  return;
121
634
  }
635
+ if (item.disabled) return;
636
+ // The opening arrow follows the resolved (possibly flipped) side (§3.4).
637
+ const resolved = openingSideFor(depth, index, item);
638
+ const opening = resolved === "right" ? "ArrowRight" : "ArrowLeft";
639
+ const opposite = opening === "ArrowRight" ? "ArrowLeft" : "ArrowRight";
122
640
  if (event.key === "Enter" || event.key === " ") {
123
641
  event.preventDefault();
124
- if (!item.disabled) selectItem(item);
642
+ if (hasSubMenu(item) && depth < 2) {
643
+ // Enter/Space on a parent opens and focuses the first enabled item.
644
+ openParent(depth, index, true);
645
+ } else {
646
+ selectItem(item, indexPathFor(depth, index), "keyboard");
647
+ }
648
+ return;
649
+ }
650
+ if (event.key === opening) {
651
+ if (hasSubMenu(item) && depth < 2) {
652
+ event.preventDefault();
653
+ if (openPath[depth] === index && openPath.length > depth) {
654
+ // Already open: focus first enabled without closing (AC-30).
655
+ focusFirstEnabled(depth + 1);
656
+ } else {
657
+ openParent(depth, index, true);
658
+ }
659
+ }
660
+ return;
661
+ }
662
+ if (event.key === opposite) {
663
+ // Opposite arrow closes the deepest open level only, one level per
664
+ // press, and refocuses that level's parent line (§3.6, D8).
665
+ if (depth >= 1) {
666
+ event.preventDefault();
667
+ if (openPath.length > 0) closeDeepestFrom(openPath.length, true);
668
+ } else if (hasCascade && openPath[0] === index && openPath.length > 0) {
669
+ event.preventDefault();
670
+ closeDeepestFrom(openPath.length, true);
671
+ }
672
+ }
673
+ }
674
+
675
+ function onLevelKeyDown(event: KeyboardEvent, depth: number) {
676
+ if (!hasCascade) return;
677
+ if (event.key === "Escape") {
678
+ if (depth >= 1) {
679
+ // Esc closes the deepest open level only, one level per press,
680
+ // then stops the host close (D4, §3.6/D8).
681
+ event.preventDefault();
682
+ event.stopPropagation();
683
+ if (openPath.length > 0) closeDeepestFrom(openPath.length, true);
684
+ return;
685
+ }
686
+ if (openPath.length > 0) {
687
+ // Esc on the root line with a sub-menu open closes the deepest level.
688
+ event.preventDefault();
689
+ event.stopPropagation();
690
+ cancelAllTimers();
691
+ const parentLevel = openPath.length - 1;
692
+ const parentIndex = openPath[parentLevel];
693
+ openPath = openPath.slice(0, parentLevel);
694
+ if (parentIndex !== undefined) focusButton(parentLevel, parentIndex);
695
+ return;
696
+ }
697
+ // Esc at the root closes everything; the root close stays governed by
698
+ // `dismissOnSelect` for standalone menus (§3.6).
699
+ if (isNested || dismissOnSelect) {
700
+ event.preventDefault();
701
+ event.stopPropagation();
702
+ closeAll(true);
703
+ }
704
+ return;
705
+ }
706
+ if (event.key === "Tab") {
707
+ // Tab closes everything and lets focus leave the menu (no trap, AC-32).
708
+ closeAll(false);
125
709
  }
126
710
  }
127
711
 
128
712
  function onWindowKeydown(event: KeyboardEvent) {
713
+ // A level handler already consumed this key (D4).
714
+ if (event.defaultPrevented) return;
715
+ // A host owns the global close for nested cascade menus.
716
+ if (isNested && treeHasCascade(items)) return;
129
717
  if (event.key === "Escape" && open && dismissOnSelect) {
130
718
  event.preventDefault();
719
+ cancelAllTimers();
720
+ openPath = [];
131
721
  open = false;
132
722
  }
133
723
  }
134
724
 
135
725
  function onWindowPointerDown(event: MouseEvent) {
726
+ if (event.defaultPrevented) return;
727
+ if (isNested && treeHasCascade(items)) return;
136
728
  if (!open || !dismissOnSelect) return;
729
+ const composed = event as MouseEvent & { composedPath?: () => EventTarget[] };
730
+ const path = typeof composed.composedPath === "function" ? composed.composedPath() : [];
137
731
  const target = event.target as Node | null;
138
- if (host && target && !host.contains(target)) open = false;
732
+ const inside =
733
+ host !== undefined &&
734
+ (path.length > 0 ? path.includes(host) : Boolean(target && host.contains(target)));
735
+ if (!inside) {
736
+ cancelAllTimers();
737
+ openPath = [];
738
+ open = false;
739
+ }
740
+ }
741
+
742
+ function scanTreeWarnings(list: MenuItem[], depth: number) {
743
+ const seen = new Set<string>();
744
+ for (const item of list) {
745
+ if (!isAction(item)) continue;
746
+ const key = keyOf(item);
747
+ if (seen.has(key) && !warnedDuplicate) {
748
+ warnedDuplicate = true;
749
+ console.warn(`[Menu] duplicate sibling key "${key}": open state follows the index path.`);
750
+ }
751
+ seen.add(key);
752
+ if (depth >= 2 && hasSubMenu(item) && !warnedDepthKeys.has(key)) {
753
+ warnedDepthKeys.add(key);
754
+ console.warn(
755
+ `[Menu] item "${key}" is nested deeper than two sub-menu levels and renders as a leaf.`
756
+ );
757
+ }
758
+ if (isAction(item) && Array.isArray(item.children)) {
759
+ scanTreeWarnings(item.children, depth + 1);
760
+ }
761
+ }
762
+ }
763
+
764
+ // `items` (or the preferred side) changing removes orphan panels and
765
+ // cancels every pending hover timer (§3.2, AC-22, AC-38).
766
+ $effect(() => {
767
+ void items;
768
+ void submenuSide;
769
+ cancelAllTimers();
770
+ const previous = untrack(() => openPath);
771
+ let list = items;
772
+ const kept: number[] = [];
773
+ for (const index of previous) {
774
+ const item = list[index];
775
+ // A disabled parent is no longer expandable: prune its panel so
776
+ // `aria-expanded` and the rendered levels agree (§3.2, AC-22).
777
+ if (!item || !hasSubMenu(item) || item.disabled) break;
778
+ kept.push(index);
779
+ list = item.children;
780
+ }
781
+ if (kept.length !== previous.length) {
782
+ openPath = kept;
783
+ }
784
+ untrack(() => scanTreeWarnings(items, 0));
785
+ });
786
+
787
+ // Let the host know whether a cascade is present (focus-return + shadow
788
+ // decisions). Always reported so the flag resets when items lose their
789
+ // cascade instead of going stale.
790
+ $effect(() => {
791
+ if (isNested) {
792
+ hostContext?.setHasCascade?.(treeHasCascade(items));
793
+ }
794
+ });
795
+
796
+ // Recompute every open level against its own parent rect on scroll/resize,
797
+ // plus one recompute after mount once the real panel size is known (§3.4).
798
+ $effect(() => {
799
+ if (!open || openPath.length === 0) return;
800
+ schedulePositions();
801
+ const recompute = () => computeAllPositions();
802
+ window.addEventListener("scroll", recompute, true);
803
+ window.addEventListener("resize", recompute);
804
+ return () => {
805
+ window.removeEventListener("scroll", recompute, true);
806
+ window.removeEventListener("resize", recompute);
807
+ };
808
+ });
809
+
810
+ const classes = () =>
811
+ [
812
+ "st-menu",
813
+ dense ? "st-menu--dense" : null,
814
+ hasCascade ? "st-menu--hasCascade" : null,
815
+ className
816
+ ]
817
+ .filter(Boolean)
818
+ .join(" ");
819
+
820
+ // Origin/main OverflowMenu flat root class set (AC-37). Dense stays on the
821
+ // host (`st-overflowMenu--dense`); the list itself carries no modifier.
822
+ const overflowClasses = () =>
823
+ ["st-overflowMenu__list", className].filter(Boolean).join(" ");
824
+
825
+ // The host pins the panel box through `style` (absolute per placement plus
826
+ // the `--st-menu-maxHeight` viewport cap). The overflow list consumes that
827
+ // cap as a real `max-height`, mirroring the origin/main inline cap.
828
+ function overflowPanelStyle(): string {
829
+ const raw = (rest as { style?: unknown }).style;
830
+ const cap = "max-height: var(--st-menu-maxHeight, calc(100vh - 2rem));";
831
+ return typeof raw === "string" && raw.length > 0 ? `${raw} ${cap}` : cap;
832
+ }
833
+
834
+ function panelStyle(depth: number): string | undefined {
835
+ const position = levelPositions[depth];
836
+ if (!position) return undefined;
837
+ let style = `top: ${position.top}px; left: ${position.left}px;`;
838
+ if (position.maxHeight !== undefined) style += ` max-height: ${position.maxHeight}px;`;
839
+ if (position.capped) style += " min-width: 0; max-width: calc(100vw - 16px);";
840
+ return style;
841
+ }
842
+
843
+ function chevronSide(depth: number, index: number): ResolvedSubMenuSide {
844
+ return resolvedSideFor(depth, index);
139
845
  }
140
846
  </script>
141
847
 
142
848
  <svelte:window onkeydown={onWindowKeydown} onpointerdown={onWindowPointerDown} />
143
849
 
144
- {#if open}
145
- <div {...rest} bind:this={host} class={classes()} role="menu" aria-label={label}>
146
- {#each items as item, index (index)}
147
- {#if isAction(item)}
148
- {@const Icon = item.icon}
850
+ {#snippet menurows(list: MenuItem[], depth: number)}
851
+ {#each list as item, index (index)}
852
+ {#if isAction(item)}
853
+ {@const Icon = item.icon}
854
+ {@const isParent = hasSubMenu(item) && depth < 2}
855
+ {@const isOpen = openPath[depth] === index && openPath.length > depth}
856
+ {@const selected = Boolean(item.selected) || isOpen}
857
+ {@const tabIndex = rovingTarget(depth, list) === index ? 0 : -1}
858
+ {#if isParent}
859
+ <div
860
+ class="st-menu__itemWrap"
861
+ role="presentation"
862
+ onpointerenter={(event) => {
863
+ if (!item.disabled) onParentPointerEnter(depth, index, event);
864
+ }}
865
+ onpointerleave={(event) => {
866
+ if (!item.disabled) onParentPointerLeave(depth, index, event);
867
+ }}
868
+ >
869
+ <button
870
+ class="st-menu__item st-menu__item--hasSubmenu"
871
+ class:st-menu__item--danger={item.danger}
872
+ class:st-menu__item--selected={selected}
873
+ type="button"
874
+ role="menuitem"
875
+ id={parentButtonId(depth, index)}
876
+ data-item-index={index}
877
+ aria-haspopup="menu"
878
+ aria-expanded={item.disabled ? "false" : isOpen ? "true" : "false"}
879
+ aria-controls={subId(depth, index)}
880
+ aria-disabled={item.disabled ? "true" : undefined}
881
+ disabled={item.disabled}
882
+ tabindex={item.disabled ? undefined : tabIndex}
883
+ onclick={() => {
884
+ if (!item.disabled) toggleParent(depth, index);
885
+ }}
886
+ onkeydown={(event) => onItemKeyDown(event, depth, index, item)}
887
+ onfocus={() => {
888
+ roving[depth] = index;
889
+ }}
890
+ >
891
+ {#if chevronSide(depth, index) === "left"}
892
+ <span class="st-menu__itemChevron st-menu__itemChevron--start" aria-hidden="true">
893
+ <ChevronLeft size={16} strokeWidth={2} aria-hidden="true" />
894
+ </span>
895
+ {/if}
896
+ {#if Icon}
897
+ <span class="st-menu__itemIcon" aria-hidden="true">
898
+ {#if typeof Icon === "string"}
899
+ {Icon}
900
+ {:else}
901
+ <Icon size={16} strokeWidth={2} />
902
+ {/if}
903
+ </span>
904
+ {/if}
905
+ <span class="st-menu__itemLabel">{item.label}</span>
906
+ {#if chevronSide(depth, index) === "right"}
907
+ <span class="st-menu__itemChevron st-menu__itemChevron--end" aria-hidden="true">
908
+ <ChevronRight size={16} strokeWidth={2} aria-hidden="true" />
909
+ </span>
910
+ {/if}
911
+ </button>
912
+ </div>
913
+ {:else}
149
914
  <button
150
915
  class="st-menu__item"
151
916
  class:st-menu__item--danger={item.danger}
917
+ class:st-menu__item--selected={selected}
152
918
  type="button"
153
919
  role="menuitem"
920
+ data-item-index={index}
154
921
  aria-disabled={item.disabled ? "true" : undefined}
155
922
  disabled={item.disabled}
156
- onclick={() => selectItem(item)}
157
- onkeydown={(event) => onItemKeyDown(event, item)}
923
+ tabindex={item.disabled ? undefined : tabIndex}
924
+ onclick={() => selectItem(item, indexPathFor(depth, index), "pointer")}
925
+ onkeydown={(event) => onItemKeyDown(event, depth, index, item)}
926
+ onpointerenter={(event) => onLeafPointerEnter(depth, event)}
927
+ onfocus={() => {
928
+ roving[depth] = index;
929
+ }}
158
930
  >
159
931
  {#if Icon}
160
932
  <span class="st-menu__itemIcon" aria-hidden="true">
@@ -167,20 +939,157 @@
167
939
  {/if}
168
940
  <span class="st-menu__itemLabel">{item.label}</span>
169
941
  </button>
170
- {:else if item.kind === "divider"}
171
- <div class="st-menu__divider" role="separator" aria-hidden="true"></div>
172
- {:else}
173
- {@const groupId = nextGroupId()}
942
+ {/if}
943
+ {:else if item.kind === "divider"}
944
+ <div class="st-menu__divider" role="separator" aria-hidden="true"></div>
945
+ {:else}
946
+ <div
947
+ class="st-menu__group"
948
+ id={`${rootId}--group-${depth}-${index}`}
949
+ role="presentation"
950
+ >
951
+ {item.label}
952
+ </div>
953
+ {/if}
954
+ {/each}
955
+ {/snippet}
956
+
957
+ {#snippet overflowrows(list: MenuItem[], depth: number)}
958
+ {#each list as item, index (index)}
959
+ {#if isAction(item)}
960
+ {@const Icon = item.icon}
961
+ {@const tabIndex = rovingTarget(depth, list) === index ? 0 : -1}
962
+ <li role="none" class="st-overflowMenu__listItem">
963
+ <button
964
+ class="st-overflowMenu__item"
965
+ class:st-overflowMenu__item--danger={item.danger}
966
+ class:st-overflowMenu__item--selected={item.selected}
967
+ type="button"
968
+ role="menuitem"
969
+ data-item-index={index}
970
+ aria-disabled={item.disabled ? "true" : undefined}
971
+ disabled={item.disabled}
972
+ tabindex={item.disabled ? undefined : tabIndex}
973
+ onclick={() => selectItem(item, indexPathFor(depth, index), "pointer")}
974
+ onkeydown={(event) => onItemKeyDown(event, depth, index, item)}
975
+ onpointerenter={(event) => onLeafPointerEnter(depth, event)}
976
+ onfocus={() => {
977
+ roving[depth] = index;
978
+ }}
979
+ >
980
+ {#if Icon}
981
+ <span class="st-overflowMenu__itemIcon" aria-hidden="true">
982
+ {#if typeof Icon === "string"}
983
+ {Icon}
984
+ {:else}
985
+ <Icon size={16} strokeWidth={2} />
986
+ {/if}
987
+ </span>
988
+ {/if}
989
+ <span class="st-overflowMenu__itemLabel">{item.label}</span>
990
+ </button>
991
+ </li>
992
+ {:else if item.kind === "divider"}
993
+ <li role="separator" aria-hidden="true" class="st-overflowMenu__divider"></li>
994
+ {:else}
995
+ <li role="presentation" class="st-overflowMenu__group">{item.label}</li>
996
+ {/if}
997
+ {/each}
998
+ {/snippet}
999
+
1000
+ {#if open}
1001
+ {#if hasCascade}
1002
+ <!-- The root menu id lives on the inner role=menu list (not the outer
1003
+ host) so host aria-controls resolves to the menu itself (§2.2). -->
1004
+ <div
1005
+ {...rest}
1006
+ id={undefined}
1007
+ bind:this={host}
1008
+ class={classes()}
1009
+ onpointermove={onHostPointerMove}
1010
+ >
1011
+ <div
1012
+ class="st-menu__scroll"
1013
+ role="menu"
1014
+ id={rootId}
1015
+ aria-label={label}
1016
+ tabindex="-1"
1017
+ data-menu-level="0"
1018
+ onkeydown={(event) => onLevelKeyDown(event, 0)}
1019
+ >
1020
+ {@render menurows(items, 0)}
1021
+ </div>
1022
+ {#if openPath.length >= 1 && isAction(items[openPath[0]]) && Array.isArray((items[openPath[0]] as MenuActionItem).children)}
1023
+ {@const level1 = (items[openPath[0]] as MenuActionItem).children as MenuItem[]}
174
1024
  <div
175
- class="st-menu__group"
176
- id={groupId}
177
- role="presentation"
1025
+ class={["st-menu", "st-menu--submenu", dense ? "st-menu--dense" : null]
1026
+ .filter(Boolean)
1027
+ .join(" ")}
1028
+ role="menu"
1029
+ id={subId(0, openPath[0])}
1030
+ aria-labelledby={parentButtonId(0, openPath[0])}
1031
+ tabindex="-1"
1032
+ data-menu-level="1"
1033
+ style={panelStyle(0)}
1034
+ onkeydown={(event) => onLevelKeyDown(event, 1)}
1035
+ onpointerenter={onPanelPointerEnter}
1036
+ onpointerleave={(event) => onPanelPointerLeave(0, event)}
178
1037
  >
179
- {item.label}
1038
+ {@render menurows(level1, 1)}
180
1039
  </div>
181
1040
  {/if}
182
- {/each}
183
- </div>
1041
+ {#if openPath.length >= 2}
1042
+ {@const mid = (levelItems(1)[openPath[1]] as MenuActionItem | undefined)?.children as MenuItem[] | undefined}
1043
+ {#if mid}
1044
+ <div
1045
+ class={["st-menu", "st-menu--submenu", dense ? "st-menu--dense" : null]
1046
+ .filter(Boolean)
1047
+ .join(" ")}
1048
+ role="menu"
1049
+ id={subId(1, openPath[1])}
1050
+ aria-labelledby={parentButtonId(1, openPath[1])}
1051
+ tabindex="-1"
1052
+ data-menu-level="2"
1053
+ style={panelStyle(1)}
1054
+ onkeydown={(event) => onLevelKeyDown(event, 2)}
1055
+ onpointerenter={onPanelPointerEnter}
1056
+ onpointerleave={(event) => onPanelPointerLeave(1, event)}
1057
+ >
1058
+ {@render menurows(mid, 2)}
1059
+ </div>
1060
+ {/if}
1061
+ {/if}
1062
+ </div>
1063
+ {:else if useOverflowClasses}
1064
+ <!-- Overflow host parity (AC-37): origin/main `st-overflowMenu__*` flat DOM
1065
+ on the same elements (`ul > li` list, item buttons, icon/label spans,
1066
+ divider/group rows). Only reachable when the internal hook is set, so
1067
+ standalone Menu DOM is unchanged (AC-01). -->
1068
+ <ul
1069
+ {...(rest as unknown as Omit<HTMLAttributes<HTMLUListElement>, "class">)}
1070
+ id={rootId}
1071
+ bind:this={host}
1072
+ class={overflowClasses()}
1073
+ role="menu"
1074
+ aria-label={label}
1075
+ data-menu-level="0"
1076
+ style={overflowPanelStyle()}
1077
+ >
1078
+ {@render overflowrows(items, 0)}
1079
+ </ul>
1080
+ {:else}
1081
+ <div
1082
+ {...rest}
1083
+ id={rootId}
1084
+ bind:this={host}
1085
+ class={classes()}
1086
+ role="menu"
1087
+ aria-label={label}
1088
+ data-menu-level="0"
1089
+ >
1090
+ {@render menurows(items, 0)}
1091
+ </div>
1092
+ {/if}
184
1093
  {/if}
185
1094
 
186
1095
  <style>
@@ -200,6 +1109,38 @@
200
1109
  padding: var(--st-spacing-1, 0.25rem);
201
1110
  }
202
1111
 
1112
+ /* Cascade marker: the root panel escapes the root scroll container, so it
1113
+ must not clip the fixed sub-menu panels; both root and sub-menu panels
1114
+ use the popover shadow chain (§5, D12). */
1115
+ .st-menu--hasCascade {
1116
+ box-shadow: var(
1117
+ --st-component-popover-shadow,
1118
+ var(--st-component-menu-shadow, 0 8px 24px rgb(15 23 42 / 0.14))
1119
+ );
1120
+ overflow: visible;
1121
+ }
1122
+
1123
+ .st-menu__scroll {
1124
+ display: grid;
1125
+ max-height: var(--st-menu-maxHeight, 80vh);
1126
+ overflow-y: auto;
1127
+ }
1128
+
1129
+ .st-menu--submenu {
1130
+ box-shadow: var(
1131
+ --st-component-popover-shadow,
1132
+ var(--st-component-menu-shadow, 0 8px 24px rgb(15 23 42 / 0.14))
1133
+ );
1134
+ max-height: var(--st-menu-maxHeight, 80vh);
1135
+ overflow-y: auto;
1136
+ position: fixed;
1137
+ z-index: calc(var(--st-component-popover-zIndex, 80) + 2);
1138
+ }
1139
+
1140
+ .st-menu__itemWrap {
1141
+ position: relative;
1142
+ }
1143
+
203
1144
  .st-menu__item {
204
1145
  align-items: center;
205
1146
  background: transparent;
@@ -243,6 +1184,32 @@
243
1184
  );
244
1185
  }
245
1186
 
1187
+ /* Selected parent line / `selected: true`: existing selectableRow tokens,
1188
+ same no-color-mix fallback strategy as SelectableRow (no accent bar). */
1189
+ .st-menu__item--selected {
1190
+ background: var(
1191
+ --st-component-selectableRow-selectedBackground,
1192
+ color-mix(in oklch, var(--st-semantic-action-primary, #2563eb) 12%, transparent)
1193
+ );
1194
+ color: var(
1195
+ --st-component-selectableRow-selectedText,
1196
+ color-mix(in oklch, var(--st-semantic-action-primary, #2563eb) 78%, black)
1197
+ );
1198
+ }
1199
+
1200
+ @supports not (color: color-mix(in oklch, red, blue)) {
1201
+ .st-menu__item--selected {
1202
+ background: var(
1203
+ --st-component-selectableRow-selectedBackground,
1204
+ var(--st-semantic-surface-subtle, #eef2ff)
1205
+ );
1206
+ color: var(
1207
+ --st-component-selectableRow-selectedText,
1208
+ var(--st-semantic-text-primary, #0f172a)
1209
+ );
1210
+ }
1211
+ }
1212
+
246
1213
  .st-menu__itemIcon {
247
1214
  align-items: center;
248
1215
  display: inline-flex;
@@ -252,6 +1219,27 @@
252
1219
  width: 1rem;
253
1220
  }
254
1221
 
1222
+ .st-menu__itemChevron {
1223
+ align-items: center;
1224
+ display: inline-flex;
1225
+ flex: 0 0 auto;
1226
+ justify-content: center;
1227
+ line-height: 1;
1228
+ }
1229
+
1230
+ .st-menu__itemChevron--end {
1231
+ margin-left: auto;
1232
+ }
1233
+
1234
+ .st-menu__itemChevron--start {
1235
+ margin-right: auto;
1236
+ order: -1;
1237
+ }
1238
+
1239
+ .st-menu__itemChevron--start + .st-menu__itemIcon {
1240
+ order: 0;
1241
+ }
1242
+
255
1243
  .st-menu__itemLabel {
256
1244
  flex: 1 1 auto;
257
1245
  overflow: hidden;