@glasshome/ui 1.31.1 → 1.33.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/SPEC.md +1 -1
  3. package/dist/lib/opening-release.d.ts +6 -0
  4. package/dist/lib/when-animations-settle.d.ts +4 -0
  5. package/dist/solid/bottom-sheet/sheet-motion.d.ts +1 -0
  6. package/dist/solid/dock.d.ts +1 -1
  7. package/dist/solid/icon-picker.d.ts +1 -0
  8. package/dist/solid/index.d.ts +1 -0
  9. package/dist/solid/index.js +2989 -2806
  10. package/dist/solid/menu-parts.d.ts +2 -5
  11. package/dist/solid/selection.d.ts +21 -0
  12. package/dist/solid/sliding-indicator.d.ts +1 -0
  13. package/dist/testing/animations.d.ts +1 -0
  14. package/dist/testing/deny-fetch.d.ts +1 -0
  15. package/dist/testing/fake-time.d.ts +5 -0
  16. package/dist/testing/index.d.ts +3 -0
  17. package/dist/testing/index.js +39 -0
  18. package/package.json +14 -2
  19. package/src/lib/menu-classes.ts +1 -1
  20. package/src/lib/opening-release.ts +25 -0
  21. package/src/lib/when-animations-settle.ts +12 -0
  22. package/src/solid/area-picker.tsx +5 -9
  23. package/src/solid/bottom-sheet/bottom-sheet.tsx +17 -20
  24. package/src/solid/bottom-sheet/sheet-motion.ts +4 -0
  25. package/src/solid/dock.tsx +10 -7
  26. package/src/solid/entity-selector.tsx +4 -6
  27. package/src/solid/icon-picker.tsx +3 -1
  28. package/src/solid/index.ts +1 -0
  29. package/src/solid/menu-parts.tsx +21 -58
  30. package/src/solid/picker-row.tsx +2 -0
  31. package/src/solid/select.tsx +7 -6
  32. package/src/solid/selection.tsx +259 -0
  33. package/src/solid/sliding-indicator.tsx +2 -0
  34. package/src/solid/tabs.tsx +5 -8
  35. package/src/solid/toggle-group.tsx +21 -19
  36. package/src/solid/toggle.tsx +1 -1
  37. package/src/styles/globals.css +48 -1
  38. package/src/styles/theme.css +11 -14
  39. package/src/testing/animations.ts +16 -0
  40. package/src/testing/deny-fetch.ts +19 -0
  41. package/src/testing/fake-time.ts +18 -0
  42. package/src/testing/index.ts +3 -0
@@ -1,11 +1,8 @@
1
1
  import { DropdownMenu as MenuPrimitive } from "@kobalte/core/dropdown-menu";
2
2
  import { type Component, type ComponentProps, type ParentComponent } from "solid-js";
3
3
  export declare const MENU_CONTENT_CLASS: string;
4
- /** Every menu content and sub content wraps its rows in one sliding highlight,
5
- * keyed off Kobalte's roving-focus attribute. The highlighted row's own
6
- * --glass-tone (set inline by MenuItemPart) is mirrored onto the indicator,
7
- * since --glass-tone does not inherit and the indicator is a sibling, not
8
- * an ancestor, of the rows it highlights. */
4
+ /** Every menu content and sub content wraps its rows in one selection scope, keyed off
5
+ * Kobalte's highlighted row. */
9
6
  export declare const MenuContentIndicator: ParentComponent;
10
7
  type ToneProps = {
11
8
  tone?: string;
@@ -0,0 +1,21 @@
1
+ import { type ComponentProps, type JSX } from "solid-js";
2
+ /** The attribute (without `data-`) that marks the active item: Kobalte's, or the caller's own. */
3
+ export type SelectionMarker = "pressed" | "selected" | "highlighted" | "lit";
4
+ /**
5
+ * The glass behind an item while it is the active one. Render it as the first child of every
6
+ * item inside a `SelectionScope`; CSS shows the one whose item carries the scope's marker, so
7
+ * layout keeps it in place and nothing measures it at rest. Renders nothing outside a scope.
8
+ */
9
+ export declare function SelectionHighlight(): JSX.Element;
10
+ interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
11
+ marker: SelectionMarker;
12
+ /** CSS colour for the highlight's glass. Default `var(--material-accent)`. */
13
+ tone?: string;
14
+ style?: JSX.CSSProperties;
15
+ }
16
+ /**
17
+ * Wraps items that each render a `SelectionHighlight`. When the marker moves to another item,
18
+ * one flyer animates from the old item to the new one and hands off to its resting highlight.
19
+ */
20
+ export declare function SelectionScope(props: SelectionScopeProps): JSX.Element;
21
+ export {};
@@ -30,5 +30,6 @@ interface SlidingIndicatorProps extends ComponentProps<"div"> {
30
30
  wrapped?: boolean;
31
31
  children: JSX.Element;
32
32
  }
33
+ /** @deprecated Use `SelectionScope` with a `SelectionHighlight` in each item; removed in 2.0. */
33
34
  export declare function SlidingIndicator(props: SlidingIndicatorProps): JSX.Element;
34
35
  export {};
@@ -0,0 +1 @@
1
+ export declare function installSettledAnimations(): void;
@@ -0,0 +1 @@
1
+ export declare function installDenyFetch(): void;
@@ -0,0 +1,5 @@
1
+ import { vi } from "vitest";
2
+ export declare function useFakeTime(config?: {
3
+ toFake?: NonNullable<Parameters<typeof vi.useFakeTimers>[0]>["toFake"];
4
+ }): void;
5
+ export declare function useSystemTime(at: number | Date): void;
@@ -0,0 +1,3 @@
1
+ export { installSettledAnimations } from "./animations.js";
2
+ export { useFakeTime, useSystemTime } from "./fake-time.js";
3
+ export { installDenyFetch } from "./deny-fetch.js";
@@ -0,0 +1,39 @@
1
+ import { afterEach as e, onTestFinished as t, vi as n } from "vitest";
2
+ //#region src/testing/animations.ts
3
+ function r() {
4
+ let e = window.getComputedStyle.bind(window);
5
+ window.getComputedStyle = ((t, n) => {
6
+ let r = e(t, n);
7
+ return r.animationName ? r : new Proxy(r, { get: (e, t) => {
8
+ if (t === "animationName") return "none";
9
+ let n = Reflect.get(e, t);
10
+ return typeof n == "function" ? n.bind(e) : n;
11
+ } });
12
+ });
13
+ }
14
+ //#endregion
15
+ //#region src/testing/fake-time.ts
16
+ function i(e) {
17
+ n.useFakeTimers(e), t(() => {
18
+ n.useRealTimers();
19
+ });
20
+ }
21
+ function a(e) {
22
+ n.useFakeTimers({ toFake: ["Date"] }), n.setSystemTime(e), t(() => {
23
+ n.useRealTimers();
24
+ });
25
+ }
26
+ //#endregion
27
+ //#region src/testing/deny-fetch.ts
28
+ function o() {
29
+ let t = [];
30
+ globalThis.fetch = Object.assign((e) => {
31
+ let n = e instanceof Request ? e.url : String(e);
32
+ return t.push(n), Promise.reject(/* @__PURE__ */ Error(`fetch denied in tests: stub the route for ${n}`));
33
+ }, { preconnect: () => {} }), e(() => {
34
+ let e = t;
35
+ if (t = [], e.length > 0) throw Error(`unstubbed fetch: ${[...new Set(e)].join(", ")}`);
36
+ });
37
+ }
38
+ //#endregion
39
+ export { o as installDenyFetch, r as installSettledAnimations, i as useFakeTime, a as useSystemTime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.31.1",
3
+ "version": "1.33.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "keywords": [
6
6
  "components",
@@ -29,6 +29,7 @@
29
29
  "src/lib",
30
30
  "src/solid",
31
31
  "src/styles",
32
+ "src/testing",
32
33
  "src/tokens",
33
34
  "scripts",
34
35
  "SPEC.md"
@@ -59,6 +60,11 @@
59
60
  "./package.json": "./package.json",
60
61
  "./styles/theme": "./src/styles/theme.css",
61
62
  "./scripts/*": "./scripts/*",
63
+ "./testing": {
64
+ "@glasshome/source": "./src/testing/index.ts",
65
+ "types": "./dist/testing/index.d.ts",
66
+ "import": "./dist/testing/index.js"
67
+ },
62
68
  "./backgrounds": {
63
69
  "@glasshome/source": "./src/backgrounds/index.ts",
64
70
  "types": "./dist/backgrounds/index.d.ts",
@@ -122,7 +128,13 @@
122
128
  "peerDependencies": {
123
129
  "solid-js": "^1.9.9",
124
130
  "tailwindcss": "^4.1.13",
125
- "tw-animate-css": "^1.4.0"
131
+ "tw-animate-css": "^1.4.0",
132
+ "vitest": "^4.1.10"
133
+ },
134
+ "peerDependenciesMeta": {
135
+ "vitest": {
136
+ "optional": true
137
+ }
126
138
  },
127
139
  "engines": {
128
140
  "node": ">=20"
@@ -1,5 +1,5 @@
1
1
  /* One menu row, label and separator for every listbox and menu (Select,
2
- * DropdownMenu, ContextMenu, pickers). Highlight comes from SlidingIndicator,
2
+ * DropdownMenu, ContextMenu, pickers). Highlight comes from SelectionHighlight,
3
3
  * so the row itself paints no background. A toned row (MenuItemPart sets
4
4
  * data-tone) guards off the muted svg color so its icon inherits the row's
5
5
  * own currentColor instead.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * A panel that opens on pointerdown under the pointer (an overlaid Select, a menu anchored on
3
+ * its trigger) would receive that press's release, and Kobalte acts on release. Only a press
4
+ * that starts inside the panel may act; with or without an opening animation.
5
+ */
6
+ export function ignoreOpeningRelease(panel: HTMLElement): () => void {
7
+ let pressedInside = false;
8
+ const onDown = () => {
9
+ pressedInside = true;
10
+ };
11
+ const onUp = (event: PointerEvent) => {
12
+ if (pressedInside) {
13
+ pressedInside = false;
14
+ return;
15
+ }
16
+ event.stopPropagation();
17
+ event.preventDefault();
18
+ };
19
+ panel.addEventListener("pointerdown", onDown, true);
20
+ panel.addEventListener("pointerup", onUp, true);
21
+ return () => {
22
+ panel.removeEventListener("pointerdown", onDown, true);
23
+ panel.removeEventListener("pointerup", onUp, true);
24
+ };
25
+ }
@@ -0,0 +1,12 @@
1
+ export async function whenAnimationsSettle(
2
+ el: Element,
3
+ options: { subtree?: boolean; filter?: (animation: Animation) => boolean } = {},
4
+ ): Promise<void> {
5
+ // One microtask so styles written in the same tick start their animations first.
6
+ await Promise.resolve();
7
+ if (typeof el.getAnimations !== "function") return;
8
+ const all = el.getAnimations({ subtree: options.subtree ?? false });
9
+ const running = options.filter ? all.filter(options.filter) : all;
10
+ if (running.length === 0) return;
11
+ await Promise.allSettled(running.map((animation) => animation.finished));
12
+ }
@@ -9,7 +9,7 @@ import { PickerRow } from "./picker-row.js";
9
9
  import { PickerSearch } from "./picker-search.js";
10
10
  import { PickerTrigger } from "./picker-trigger.js";
11
11
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
12
- import { SlidingIndicator } from "./sliding-indicator.js";
12
+ import { SelectionScope } from "./selection.js";
13
13
 
14
14
  interface AreaPickerBaseProps {
15
15
  placeholder?: string;
@@ -87,9 +87,7 @@ export function AreaPicker(props: AreaPickerProps) {
87
87
  return only.length === 1 ? areaList().find((a) => a.id === only[0]) : undefined;
88
88
  });
89
89
 
90
- // One glass pill (SlidingIndicator) tracks the highlighted row and animates
91
- // between rows, exactly like the Select. Hover wins; otherwise the pill rests
92
- // on a selected row, which in multi mode is the first one still listed.
90
+ // Hover wins; otherwise the highlight rests on a selected row (in multi mode the first still listed).
93
91
  const [hovered, setHovered] = createSignal<string | null>(null);
94
92
  const restingId = createMemo(() => {
95
93
  const list = filtered();
@@ -183,10 +181,8 @@ export function AreaPicker(props: AreaPickerProps) {
183
181
  placeholder="Search areas..."
184
182
  aria-label="Search areas"
185
183
  />
186
- <SlidingIndicator
187
- activeSelector="[data-highlighted]"
188
- orientation="vertical"
189
- indicatorClass="rounded-sm"
184
+ <SelectionScope
185
+ marker="highlighted"
190
186
  class={cn("flex flex-col gap-0.5 p-1", STAGGER, PICKER_LIST)}
191
187
  onMouseLeave={() => setHovered(null)}
192
188
  >
@@ -222,7 +218,7 @@ export function AreaPicker(props: AreaPickerProps) {
222
218
  />
223
219
  )}
224
220
  </For>
225
- </SlidingIndicator>
221
+ </SelectionScope>
226
222
  </div>
227
223
  </PopoverContent>
228
224
  </Popover>
@@ -18,6 +18,8 @@ import { Dynamic, Portal } from "solid-js/web";
18
18
  import { Z } from "../../lib/layers.js";
19
19
  import { OVERLAY_SURFACE_OPAQUE } from "../../lib/overlay-classes.js";
20
20
  import { cn } from "../../lib/utils.js";
21
+ import { whenAnimationsSettle } from "../../lib/when-animations-settle.js";
22
+ import { isSheetMotion } from "./sheet-motion.js";
21
23
  import {
22
24
  callEventHandler,
23
25
  createModalLabels,
@@ -216,25 +218,22 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
216
218
  el.style.transform = "";
217
219
  };
218
220
 
219
- const onAnimationEnd = (e: AnimationEvent) => {
220
- if (e.target !== el) return;
221
- const s = ctx.state();
222
- if (s === "opening" && e.animationName === "bs-slide-up") ctx.setState("open");
223
- else if (s === "closing" && e.animationName === "bs-slide-down") ctx.setState("closed");
224
- };
225
-
226
- const onTransitionEnd = (e: TransitionEvent) => {
227
- if (e.target !== el) return;
228
- if (e.propertyName !== "transform") return;
221
+ createEffect(() => {
229
222
  const s = ctx.state();
230
- if (s === "snapping") {
231
- ctx.setState("open");
232
- clearAnimInline();
233
- } else if (s === "closing") {
234
- ctx.setState("closed");
235
- clearAnimInline();
236
- }
237
- };
223
+ if (s !== "opening" && s !== "closing" && s !== "snapping") return;
224
+ const node = el;
225
+ if (!node) return;
226
+ let stale = false;
227
+ onCleanup(() => (stale = true));
228
+ void whenAnimationsSettle(node, { filter: isSheetMotion }).then(() => {
229
+ if (stale) return;
230
+ if (s === "opening") ctx.setState("open");
231
+ else {
232
+ ctx.setState(s === "snapping" ? "open" : "closed");
233
+ clearAnimInline();
234
+ }
235
+ });
236
+ });
238
237
 
239
238
  createEffect(() => {
240
239
  const node = ctx.contentRef();
@@ -352,8 +351,6 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
352
351
  data-sheet-content=""
353
352
  data-state={ctx.state()}
354
353
  data-reduced-motion={prefersReducedMotion() ? "" : undefined}
355
- onAnimationEnd={onAnimationEnd}
356
- onTransitionEnd={onTransitionEnd}
357
354
  style={{
358
355
  ...(typeof local.style === "object" ? local.style : {}),
359
356
  "z-index": Z.sheet,
@@ -0,0 +1,4 @@
1
+ export const isSheetMotion = (a: Animation) =>
2
+ "animationName" in a
3
+ ? a.animationName === "bs-slide-up" || a.animationName === "bs-slide-down"
4
+ : "transitionProperty" in a && a.transitionProperty === "transform";
@@ -18,7 +18,7 @@ import { HOLD_MOTION, PRESS_DIP } from "../lib/motion-classes.js";
18
18
  import { cn } from "../lib/utils.js";
19
19
  import { Badge } from "./badge.js";
20
20
  import { pageCount, pageOf, pageOffset, stripWidth } from "./dock-paging.js";
21
- import { SlidingIndicator } from "./sliding-indicator.js";
21
+ import { SelectionHighlight, SelectionScope } from "./selection.js";
22
22
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
23
23
 
24
24
  interface DockItem {
@@ -48,11 +48,13 @@ interface DockIconButtonProps extends ComponentProps<"button"> {
48
48
  icon: Component<{ class?: string }> | JSX.Element;
49
49
  label: string;
50
50
  isActive?: boolean;
51
- /** Sits on the sliding pill: the active item, or the one a drag would land on. */
51
+ /** Wears the selection highlight: the active item, or the one a drag would land on. */
52
52
  lit?: boolean;
53
53
  badge?: number;
54
54
  }
55
55
 
56
+ const DOCK_PAGE_MS = 300;
57
+
56
58
  const DockIconButton: Component<DockIconButtonProps> = (props) => {
57
59
  // Kobalte's button root narrows `type`; Solid's ComponentProps<"button"> also
58
60
  // admits "menu", so it is split off rather than spread.
@@ -73,14 +75,16 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
73
75
  type="button"
74
76
  data-slot="dock-item"
75
77
  class={cn(
76
- "group relative flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
78
+ "group relative isolate flex size-11 touch-manipulation items-center justify-center rounded-lg transition-transform duration-(--duration-micro) sm:size-12",
77
79
  PRESS_DIP,
78
80
  local.class,
79
81
  )}
80
82
  aria-label={local.label}
81
83
  aria-current={local.isActive ? "page" : undefined}
84
+ data-lit={local.lit ? "" : undefined}
82
85
  {...rest}
83
86
  >
87
+ <SelectionHighlight />
84
88
  <div
85
89
  data-slot="dock-item-icon"
86
90
  class={cn(
@@ -146,7 +150,6 @@ const Dock: Component<DockProps> = (props) => {
146
150
  const [page, setPage] = createSignal(0);
147
151
  const [viewportWidth, setViewportWidth] = createSignal(0);
148
152
 
149
- // The moving background: the shared SlidingIndicator tracks the active item.
150
153
  // A memo: the items list is rebuilt on every hover change, and only a new active item may scroll the strip.
151
154
  const activeIndex = createMemo(() => {
152
155
  const i = local.items.findIndex((it) => it.isActive);
@@ -220,7 +223,7 @@ const Dock: Component<DockProps> = (props) => {
220
223
  Math.floor(((point.x - surface.left) / surface.width) * pages()),
221
224
  );
222
225
  if (target === page()) return;
223
- const timer = setTimeout(() => goToPage(target), 300);
226
+ const timer = setTimeout(() => goToPage(target), DOCK_PAGE_MS);
224
227
  onCleanup(() => clearTimeout(timer));
225
228
  });
226
229
 
@@ -331,7 +334,7 @@ const Dock: Component<DockProps> = (props) => {
331
334
  "min-width": needsScroll() ? "auto" : "fit-content",
332
335
  }}
333
336
  >
334
- <SlidingIndicator active={pillIndex()} class="flex items-center gap-0.5 sm:gap-1">
337
+ <SelectionScope marker="lit" class="flex items-center gap-0.5 sm:gap-1">
335
338
  <Index each={local.items}>
336
339
  {(item, i) => (
337
340
  <DockIconButton
@@ -347,7 +350,7 @@ const Dock: Component<DockProps> = (props) => {
347
350
  />
348
351
  )}
349
352
  </Index>
350
- </SlidingIndicator>
353
+ </SelectionScope>
351
354
  </div>
352
355
  <Show when={pages() > 1}>
353
356
  <div
@@ -26,7 +26,7 @@ import { PICKER_ROW_HEIGHT, PickerRow } from "./picker-row.js";
26
26
  import { PickerSearch } from "./picker-search.js";
27
27
  import { PickerTrigger } from "./picker-trigger.js";
28
28
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
29
- import { SlidingIndicator } from "./sliding-indicator.js";
29
+ import { SelectionScope } from "./selection.js";
30
30
 
31
31
  interface EntitySelectorProps {
32
32
  entityIds: string[];
@@ -529,10 +529,8 @@ export function EntitySelector(props: EntitySelectorProps) {
529
529
  </div>
530
530
  }
531
531
  >
532
- <SlidingIndicator
533
- activeSelector="[data-highlighted]"
534
- orientation="vertical"
535
- indicatorClass="rounded-sm"
532
+ <SelectionScope
533
+ marker="highlighted"
536
534
  role="presentation"
537
535
  style={{ height: `${totalHeight()}px` }}
538
536
  >
@@ -554,7 +552,7 @@ export function EntitySelector(props: EntitySelectorProps) {
554
552
  )
555
553
  }
556
554
  </For>
557
- </SlidingIndicator>
555
+ </SelectionScope>
558
556
  </Show>
559
557
  </div>
560
558
  <Show when={diagnosticCount() > 0 || props.deviceClass}>
@@ -8,6 +8,8 @@ import { PickerSearch } from "./picker-search.js";
8
8
  import { PickerTrigger } from "./picker-trigger.js";
9
9
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
10
10
 
11
+ export const ICON_SEARCH_DEBOUNCE_MS = 300;
12
+
11
13
  const ICON_LIBRARIES = [
12
14
  { prefix: "", label: "All" },
13
15
  { prefix: "mdi", label: "MDI" },
@@ -296,7 +298,7 @@ export function IconPicker(props: IconPickerProps) {
296
298
  } finally {
297
299
  setLoading(false);
298
300
  }
299
- }, 300);
301
+ }, ICON_SEARCH_DEBOUNCE_MS);
300
302
  };
301
303
 
302
304
  const defaultIcons = createMemo(() => {
@@ -367,6 +367,7 @@ export {
367
367
  } from "./sheet.js";
368
368
  export { Skeleton } from "./skeleton.js";
369
369
  export { Slider } from "./slider.js";
370
+ export { SelectionHighlight, type SelectionMarker, SelectionScope } from "./selection.js";
370
371
  export { SlidingIndicator } from "./sliding-indicator.js";
371
372
  // Wave 4: React-Library Alternatives - Simpler
372
373
  export { GlassToast, Toaster, toast } from "./sonner.js";
@@ -1,20 +1,13 @@
1
1
  import { DropdownMenu as MenuPrimitive } from "@kobalte/core/dropdown-menu";
2
- import {
3
- type Component,
4
- type ComponentProps,
5
- createSignal,
6
- onCleanup,
7
- onMount,
8
- type ParentComponent,
9
- splitProps,
10
- } from "solid-js";
2
+ import { type Component, type ComponentProps, type ParentComponent, splitProps } from "solid-js";
11
3
  import { glassToneText } from "../lib/glass-tone.js";
12
4
  import { MENU_ITEM, MENU_ITEM_BASE, MENU_LABEL, MENU_SEPARATOR } from "../lib/menu-classes.js";
13
5
  import { STAGGER } from "../lib/motion-classes.js";
6
+ import { ignoreOpeningRelease } from "../lib/opening-release.js";
14
7
  import { FLOATING_PANEL } from "../lib/overlay-classes.js";
15
8
  import { cn } from "../lib/utils.js";
16
9
  import { Icon } from "./icon.js";
17
- import { SlidingIndicator } from "./sliding-indicator.js";
10
+ import { SelectionHighlight, SelectionScope } from "./selection.js";
18
11
 
19
12
  /*
20
13
  * DropdownMenu and ContextMenu are two Root flavors over one Kobalte Menu
@@ -29,52 +22,15 @@ import { SlidingIndicator } from "./sliding-indicator.js";
29
22
  * ContextMenu unfolds from the pointer. */
30
23
  export const MENU_CONTENT_CLASS = cn(FLOATING_PANEL, "min-w-[8rem] overflow-hidden p-1");
31
24
 
32
- /** Every menu content and sub content wraps its rows in one sliding highlight,
33
- * keyed off Kobalte's roving-focus attribute. The highlighted row's own
34
- * --glass-tone (set inline by MenuItemPart) is mirrored onto the indicator,
35
- * since --glass-tone does not inherit and the indicator is a sibling, not
36
- * an ancestor, of the rows it highlights. */
37
- export const MenuContentIndicator: ParentComponent = (props) => {
38
- let containerRef: HTMLDivElement | undefined;
39
- const [tone, setTone] = createSignal<string | undefined>(undefined);
40
-
41
- const syncTone = () => {
42
- const highlighted = containerRef?.querySelector<HTMLElement>("[data-highlighted]");
43
- setTone(highlighted?.style.getPropertyValue("--glass-tone") || undefined);
44
- };
45
-
46
- onMount(() => {
47
- if (!containerRef) return;
48
- const mo = new MutationObserver(syncTone);
49
- mo.observe(containerRef, {
50
- subtree: true,
51
- attributes: true,
52
- attributeFilter: ["data-highlighted"],
53
- });
54
- containerRef.addEventListener("focusin", syncTone);
55
- syncTone();
56
- onCleanup(() => {
57
- mo.disconnect();
58
- containerRef?.removeEventListener("focusin", syncTone);
59
- });
60
- });
61
-
62
- return (
63
- <SlidingIndicator
64
- ref={containerRef}
65
- // The one element between role="menu" and its role="menuitem" rows:
66
- // an unnamed div there breaks the menu's ownership in the a11y tree.
67
- role="none"
68
- class={STAGGER}
69
- activeSelector="[data-highlighted]"
70
- orientation="vertical"
71
- indicatorClass="rounded-sm"
72
- indicatorTone={tone()}
73
- >
74
- {props.children}
75
- </SlidingIndicator>
76
- );
77
- };
25
+ /** Every menu content and sub content wraps its rows in one selection scope, keyed off
26
+ * Kobalte's highlighted row. */
27
+ export const MenuContentIndicator: ParentComponent = (props) => (
28
+ // The one element between role="menu" and its role="menuitem" rows:
29
+ // an unnamed div there breaks the menu's ownership in the a11y tree.
30
+ <SelectionScope ref={ignoreOpeningRelease} role="none" class={STAGGER} marker="highlighted">
31
+ {props.children}
32
+ </SelectionScope>
33
+ );
78
34
 
79
35
  type ToneProps = {
80
36
  tone?: string;
@@ -87,7 +43,7 @@ function resolveTone(local: ToneProps): string | undefined {
87
43
  }
88
44
 
89
45
  function toneStyle(tone: string | undefined) {
90
- return tone ? { "--glass-tone": tone, color: glassToneText(tone) } : undefined;
46
+ return tone ? { "--selection-tone": tone, color: glassToneText(tone) } : undefined;
91
47
  }
92
48
 
93
49
  type MenuItemProps = ComponentProps<typeof MenuPrimitive.Item> &
@@ -113,6 +69,7 @@ export const MenuItemPart: Component<MenuItemProps> = (props) => {
113
69
  "variant",
114
70
  "slotName",
115
71
  "style",
72
+ "children",
116
73
  ]);
117
74
  const tone = () => resolveTone(local);
118
75
  return (
@@ -125,7 +82,10 @@ export const MenuItemPart: Component<MenuItemProps> = (props) => {
125
82
  class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
126
83
  style={{ ...toneStyle(tone()), ...local.style }}
127
84
  {...rest}
128
- />
85
+ >
86
+ <SelectionHighlight />
87
+ {local.children}
88
+ </MenuPrimitive.Item>
129
89
  );
130
90
  };
131
91
 
@@ -179,6 +139,7 @@ export const MenuSubTriggerPart: ParentComponent<MenuSubTriggerProps> = (props)
179
139
  class={cn(MENU_ITEM, local.inset && "pl-8", local.class)}
180
140
  {...rest}
181
141
  >
142
+ <SelectionHighlight />
182
143
  {local.children}
183
144
  <Icon icon="lucide:chevron-right" width={16} height={16} class="ml-auto" />
184
145
  </MenuPrimitive.SubTrigger>
@@ -214,6 +175,7 @@ export const MenuCheckboxItemPart: ParentComponent<MenuCheckboxItemProps> = (pro
214
175
  class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
215
176
  {...rest}
216
177
  >
178
+ <SelectionHighlight />
217
179
  <span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
218
180
  <MenuPrimitive.ItemIndicator>
219
181
  <Icon icon="lucide:check" width={16} height={16} class="size-4" />
@@ -236,6 +198,7 @@ export const MenuRadioItemPart: ParentComponent<MenuRadioItemProps> = (props) =>
236
198
  class={cn(MENU_ITEM_BASE, "py-1.5 pr-2 pl-8", local.class)}
237
199
  {...rest}
238
200
  >
201
+ <SelectionHighlight />
239
202
  <span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
240
203
  <MenuPrimitive.ItemIndicator>
241
204
  {/* mdi:circle is filled; lucide:circle is stroke-only and invisible at 8px. */}
@@ -5,6 +5,7 @@ import { ICON_PILL, ICON_PILL_TINT } from "../lib/pill-classes.js";
5
5
  import { cn } from "../lib/utils.js";
6
6
  import { Checkbox } from "./checkbox.js";
7
7
  import { Icon } from "./icon.js";
8
+ import { SelectionHighlight } from "./selection.js";
8
9
 
9
10
  /* One row for every picker that lists things with an icon (entities, areas):
10
11
  * icon well, title over a muted line, optional meta, and the selection
@@ -47,6 +48,7 @@ export function PickerRow(props: PickerRowProps) {
47
48
  style={{ "min-height": `${PICKER_ROW_HEIGHT}px` }}
48
49
  {...rest}
49
50
  >
51
+ <SelectionHighlight />
50
52
  <Show when={local.icon}>
51
53
  {(icon) => (
52
54
  <div
@@ -4,11 +4,12 @@ import { CONTROL_H, INPUT_SURFACE } from "../lib/input-classes.js";
4
4
  import { Z_CLASS } from "../lib/layers.js";
5
5
  import { MENU_ITEM, MENU_LABEL, MENU_SEPARATOR } from "../lib/menu-classes.js";
6
6
  import { FIELD_MOTION, STAGGER } from "../lib/motion-classes.js";
7
+ import { ignoreOpeningRelease } from "../lib/opening-release.js";
7
8
  import { anchorToTriggerTop } from "../lib/overlay-classes.js";
8
9
  import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
9
10
  import { cn } from "../lib/utils.js";
10
11
  import { Icon } from "./icon.js";
11
- import { SlidingIndicator } from "./sliding-indicator.js";
12
+ import { SelectionHighlight, SelectionScope } from "./selection.js";
12
13
 
13
14
  const Select = ((props: ComponentProps<typeof SelectPrimitive>) => (
14
15
  <SelectPrimitive gutter={0} getAnchorRect={anchorToTriggerTop} flip={false} overlap {...props} />
@@ -65,14 +66,13 @@ const SelectContent: ParentComponent<
65
66
  )}
66
67
  {...rest}
67
68
  >
68
- <SlidingIndicator
69
- activeSelector="[data-highlighted]"
70
- orientation="vertical"
71
- indicatorClass="rounded-sm"
69
+ <SelectionScope
70
+ ref={ignoreOpeningRelease}
71
+ marker="highlighted"
72
72
  class={cn("w-full", PICKER_LIST)}
73
73
  >
74
74
  <SelectPrimitive.Listbox class={cn(STAGGER, local.listboxClass)} />
75
- </SlidingIndicator>
75
+ </SelectionScope>
76
76
  </SelectPrimitive.Content>
77
77
  </SelectPrimitive.Portal>
78
78
  );
@@ -101,6 +101,7 @@ const SelectItem: ParentComponent<ComponentProps<typeof SelectPrimitive.Item>> =
101
101
  )}
102
102
  {...rest}
103
103
  >
104
+ <SelectionHighlight />
104
105
  <span class="absolute right-2 flex size-3.5 items-center justify-center">
105
106
  <SelectPrimitive.ItemIndicator>
106
107
  <Icon icon="lucide:check" width={16} height={16} class="size-4 text-current" />