@tensor_1/react 2.59.0 → 2.62.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/README.md CHANGED
@@ -831,6 +831,25 @@ Both are a `role="grid"` table with one tab stop. Arrow keys move between cells,
831
831
  - `count: 0` shows a zero. `hideCount` shows the band alone, for a zero you would rather not print. A row and column left out of `cells` is drawn empty (dashed, `labels.empty`), and can still be opened: `onOpenCell` gets only its `rowId` and `columnId`.
832
832
  - Tones are `neutral`, `info`, `success`, `warning`, `attention` and `danger`, always beside their words.
833
833
 
834
+ ### ListSummary: long lists of names
835
+
836
+ A cell that lists sixteen roles makes every row of its table tall. `ListSummary` shows a count, the first `max` names (default 3) and the words for the rest, with one button that shows the whole list in place and hides it again (`aria-expanded`, `aria-controls`). A list only one name longer than `max` is shown whole, because hiding a single name saves no space. Every word is a prop; the defaults are English.
837
+
838
+ ```tsx
839
+ import { ListSummary } from '@tensor_1/react';
840
+
841
+ <ListSummary
842
+ items={roles.map((r) => r.name)}
843
+ count={(n) => `${n} Rollen`}
844
+ more={(n) => `und ${n} weitere`}
845
+ expandLabel="Alle anzeigen"
846
+ collapseLabel="Weniger anzeigen"
847
+ empty="Keine Rolle"
848
+ />
849
+ ```
850
+
851
+ The toggle sits in the line of names: underlined, so colour is not its only cue, with a 24 px hit area that leaves the line height alone (`.uix-list-summary__toggle`).
852
+
834
853
  ### FilterEditor (typed column filters)
835
854
 
836
855
  `FilterEditor` is the content of one column-filter popover with a typed value (HAR-1365; TENSOR's
@@ -425,6 +425,10 @@
425
425
  "name": "ListItem",
426
426
  "subpath": "."
427
427
  },
428
+ {
429
+ "name": "ListSummary",
430
+ "subpath": "."
431
+ },
428
432
  {
429
433
  "name": "LiveIndicator",
430
434
  "subpath": "."
@@ -48,6 +48,21 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
48
48
  * the product binds the key.
49
49
  */
50
50
  shortcut?: KeyShortcut;
51
+ /**
52
+ * Why the button is unavailable (HAR-2816), e.g. "Nur Administratoren können Lizenzen
53
+ * löschen". Use it with `disabled`: the button then stays focusable and hoverable as
54
+ * `aria-disabled="true"`, takes no press, shows the reason in a `Tooltip` and is described by
55
+ * it, so a keyboard or screen-reader user learns why as well. A disabled button looks the same
56
+ * with or without a reason (muted text, no fill, a hairline); the reason is what tells a person
57
+ * what to do instead. While the button is enabled the reason is silent. Pass the prop for as
58
+ * long as the button can become unavailable (`undefined` only when it never can): the button
59
+ * then sits in the Tooltip's inline wrapper the whole time, so turning `disabled` on or off
60
+ * never remounts it and focus stays on it. Give a full-width button's wrapper its width with
61
+ * `disabledReasonClassName`.
62
+ */
63
+ disabledReason?: string;
64
+ /** Class for the Tooltip wrapper `disabledReason` adds, e.g. to make it full width. */
65
+ disabledReasonClassName?: string;
51
66
  children?: ReactNode;
52
67
  }
53
68
  declare const Button: react.ForwardRefExoticComponent<ButtonProps & react.RefAttributes<HTMLButtonElement>>;
@@ -5,6 +5,7 @@ import { renderUixLink } from "../link.js";
5
5
  import { ShortcutHint } from "./ShortcutHint.js";
6
6
  import { ButtonFeedback } from "./ButtonFeedback.js";
7
7
  import { PENDING_DELAY_MS } from "../motion-timing.js";
8
+ import { Tooltip } from "./Tooltip.js";
8
9
  const buttonClasses = (variant, size, icon, wrap, className) => cx(
9
10
  "uix-btn",
10
11
  `uix-btn--${variant}`,
@@ -15,22 +16,25 @@ const buttonClasses = (variant, size, icon, wrap, className) => cx(
15
16
  );
16
17
  let warnedIconButton = false;
17
18
  const Button = forwardRef(
18
- ({ variant = "secondary", size = "md", icon = false, loading, loadingDelay = PENDING_DELAY_MS, result, resultLabels, wrap = false, shortcut, className, children, disabled, onClick, ...props }, ref) => {
19
+ ({ variant = "secondary", size = "md", icon = false, loading, loadingDelay = PENDING_DELAY_MS, result, resultLabels, wrap = false, shortcut, disabledReason, disabledReasonClassName, className, children, disabled, onClick, ...props }, ref) => {
19
20
  if (!warnedIconButton && icon && children == null && !props["aria-label"] && !props["aria-labelledby"] && typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
20
21
  warnedIconButton = true;
21
22
  console.warn("uix: icon-only <Button> has no accessible name \u2014 pass aria-label or aria-labelledby.");
22
23
  }
23
- return /* @__PURE__ */ jsxs(
24
+ const explained = !!disabled && !!disabledReason;
25
+ const blocked = loading || explained;
26
+ const button = /* @__PURE__ */ jsxs(
24
27
  "button",
25
28
  {
26
29
  ref,
27
30
  className: buttonClasses(variant, size, icon, wrap, className),
28
- disabled,
29
- "aria-disabled": loading || void 0,
31
+ disabled: explained ? void 0 : disabled,
32
+ "aria-disabled": blocked || void 0,
30
33
  "aria-busy": loading || void 0,
31
34
  "data-pending": loading || void 0,
32
- onClick: loading || onClick ? (e) => {
33
- if (loading) {
35
+ "data-disabled-reason": explained || void 0,
36
+ onClick: blocked || onClick ? (e) => {
37
+ if (blocked) {
34
38
  e.preventDefault();
35
39
  return;
36
40
  }
@@ -43,6 +47,7 @@ const Button = forwardRef(
43
47
  ]
44
48
  }
45
49
  );
50
+ return disabledReason !== void 0 ? /* @__PURE__ */ jsx(Tooltip, { label: explained ? disabledReason : void 0, className: disabledReasonClassName, children: button }) : button;
46
51
  }
47
52
  );
48
53
  Button.displayName = "Button";
@@ -2,7 +2,7 @@
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useId, useRef } from "react";
4
4
  import { cx } from "../cx.js";
5
- const CheckIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: 2.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("polyline", { points: "1.5,6 4.5,9 10.5,3" }) });
5
+ const CheckIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: 2.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("polyline", { points: "1.5,6 4.5,9 10.5,3", pathLength: 1 }) });
6
6
  const IndeterminateIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 12 12", "aria-hidden": "true", children: /* @__PURE__ */ jsx("rect", { x: "2", y: "5", width: "8", height: "2", rx: "1", fill: "currentColor" }) });
7
7
  const Checkbox = forwardRef(
8
8
  ({ label, indeterminate, className, ...props }, forwardedRef) => {
@@ -1,10 +1,85 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useId, useRef } from "react";
3
+ import { useEffect, useId, useRef } from "react";
4
4
  import { cx } from "../cx.js";
5
5
  import { useUixLabels } from "../labels-context.js";
6
6
  import { isBackdropClick } from "../hooks/backdropDismiss.js";
7
7
  import { useGuardedDialog } from "./DiscardPrompt.js";
8
+ import { prefersReducedMotion } from "../hooks/useReducedMotion.js";
9
+ const SWIPE_VELOCITY = 0.11;
10
+ const SWIPE_SLOP = 6;
11
+ const SWIPE_WINDOW = 100;
12
+ const NOT_A_HANDLE = 'button, a, input, textarea, select, label, [role="button"], [role="slider"], [contenteditable=""], [contenteditable="true"]';
13
+ function useDrawerSwipe(side, canClose, dismiss) {
14
+ const drag = useRef(null);
15
+ const vertical = side === "bottom";
16
+ const sign = side === "start" ? -1 : 1;
17
+ const along = (e, d) => (vertical ? e.clientY - d.y0 : e.clientX - d.x0) * sign;
18
+ const across = (e, d) => vertical ? e.clientX - d.x0 : e.clientY - d.y0;
19
+ const place = (el, d) => {
20
+ el.style.translate = vertical ? `0 ${d}px` : `${d * sign}px 0`;
21
+ const size = vertical ? el.offsetHeight : el.offsetWidth;
22
+ el.style.setProperty("--uix-drawer-swipe", String(Math.min(1, d / Math.max(1, size))));
23
+ };
24
+ const settle = (el) => {
25
+ el.removeAttribute("data-swiping");
26
+ el.style.translate = "";
27
+ el.style.removeProperty("--uix-drawer-swipe");
28
+ };
29
+ const end = (e) => {
30
+ const d = drag.current;
31
+ drag.current = null;
32
+ if (!d?.active) return;
33
+ const el = e.currentTarget;
34
+ const recent = d.samples.filter((s) => e.timeStamp - s.t <= SWIPE_WINDOW);
35
+ const v = recent.length ? (along(e, d) - recent[0].p) / Math.max(1, e.timeStamp - recent[0].t) : 0;
36
+ const size = vertical ? el.offsetHeight : el.offsetWidth;
37
+ if (e.type === "pointerup" && (v > SWIPE_VELOCITY || d.d > size / 3) && dismiss(e)) {
38
+ el.removeAttribute("data-swiping");
39
+ if (!prefersReducedMotion()) place(el, size + 32);
40
+ return;
41
+ }
42
+ settle(el);
43
+ };
44
+ return {
45
+ settle,
46
+ handlers: {
47
+ onPointerDown: (e) => {
48
+ if (!canClose || e.pointerType === "mouse" || !e.isPrimary || e.target === e.currentTarget) return;
49
+ const target = e.target;
50
+ if (target.closest(NOT_A_HANDLE)) return;
51
+ if (vertical) {
52
+ const body = e.currentTarget.querySelector(".uix-drawer__body");
53
+ if (!target.closest(".uix-drawer__header") && body && body.contains(target) && body.scrollTop > 0) return;
54
+ }
55
+ drag.current = { id: e.pointerId, x0: e.clientX, y0: e.clientY, d: 0, samples: [{ p: 0, t: e.timeStamp }], active: false };
56
+ },
57
+ onPointerMove: (e) => {
58
+ const d = drag.current;
59
+ if (!d || d.id !== e.pointerId) return;
60
+ const a = along(e, d);
61
+ if (!d.active) {
62
+ if (Math.abs(a) < SWIPE_SLOP) return;
63
+ if (Math.abs(across(e, d)) > Math.abs(a) || a < 0) {
64
+ drag.current = null;
65
+ return;
66
+ }
67
+ d.active = true;
68
+ try {
69
+ e.currentTarget.setPointerCapture?.(e.pointerId);
70
+ } catch {
71
+ }
72
+ e.currentTarget.setAttribute("data-swiping", "");
73
+ }
74
+ d.samples = [...d.samples.filter((s) => e.timeStamp - s.t <= SWIPE_WINDOW), { p: a, t: e.timeStamp }];
75
+ d.d = Math.max(0, a);
76
+ place(e.currentTarget, d.d);
77
+ },
78
+ onPointerUp: end,
79
+ onPointerCancel: end
80
+ }
81
+ };
82
+ }
8
83
  const CloseIcon = () => /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8" }) });
9
84
  function Drawer({
10
85
  open,
@@ -28,6 +103,18 @@ function Drawer({
28
103
  const closeRef = useRef(null);
29
104
  const guard = useGuardedDialog({ open, onClose, dirty, pending, labels: discardLabels, closeRef });
30
105
  const titleId = useId();
106
+ const swipe = useDrawerSwipe(side, !!onClose && !pending, (event) => {
107
+ if (dirty) {
108
+ guard.requestClose(null, event);
109
+ return false;
110
+ }
111
+ guard.requestClose(null, event);
112
+ return true;
113
+ });
114
+ useEffect(() => {
115
+ const el = guard.ref.current;
116
+ if (open && el) swipe.settle(el);
117
+ }, [open]);
31
118
  return /* @__PURE__ */ jsxs(
32
119
  "dialog",
33
120
  {
@@ -43,6 +130,22 @@ function Drawer({
43
130
  onKeyDown?.(event);
44
131
  guard.onKeyDown(event);
45
132
  },
133
+ onPointerDown: (event) => {
134
+ rest.onPointerDown?.(event);
135
+ swipe.handlers.onPointerDown(event);
136
+ },
137
+ onPointerMove: (event) => {
138
+ rest.onPointerMove?.(event);
139
+ swipe.handlers.onPointerMove(event);
140
+ },
141
+ onPointerUp: (event) => {
142
+ rest.onPointerUp?.(event);
143
+ swipe.handlers.onPointerUp(event);
144
+ },
145
+ onPointerCancel: (event) => {
146
+ rest.onPointerCancel?.(event);
147
+ swipe.handlers.onPointerCancel(event);
148
+ },
46
149
  children: [
47
150
  guard.provide(
48
151
  /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -0,0 +1,32 @@
1
+ import * as react from 'react';
2
+ import { HTMLAttributes, ReactNode } from 'react';
3
+
4
+ interface ListSummaryProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
5
+ /** The names, in the order to show them. */
6
+ items: ReadonlyArray<string>;
7
+ /** How many names show while the list is collapsed. Default 3. */
8
+ max?: number;
9
+ /** An optional first line that counts the whole list, e.g. `(n) => \`${n} roles\``. */
10
+ count?: (total: number) => ReactNode;
11
+ /** The words for the names not shown, e.g. `(n) => \`und ${n} weitere\``. Default `and N more`. */
12
+ more?: (hidden: number) => string;
13
+ /** The toggle while collapsed. Translatable; default `Show all`. */
14
+ expandLabel?: string;
15
+ /** The toggle while expanded. Translatable; default `Show less`. */
16
+ collapseLabel?: string;
17
+ /** Shown instead of the list when `items` is empty. */
18
+ empty?: ReactNode;
19
+ /** Joins the names. Default `, `. */
20
+ separator?: string;
21
+ /** Start with the whole list shown. */
22
+ defaultExpanded?: boolean;
23
+ }
24
+ /**
25
+ * A long list of names (roles, teams, recipients) read as a count, the first few names and the
26
+ * words for the rest, with a button that shows the whole list in place and hides it again
27
+ * (HAR-3069). A list only one name longer than `max` is shown whole: hiding a single name saves
28
+ * no space. Every word is a prop; the defaults are English.
29
+ */
30
+ declare function ListSummary({ items, max, count, more, expandLabel, collapseLabel, empty, separator, defaultExpanded, className, ...props }: ListSummaryProps): react.JSX.Element;
31
+
32
+ export { ListSummary, type ListSummaryProps };
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import { useId, useState } from "react";
4
+ import { cx } from "../cx.js";
5
+ function ListSummary({
6
+ items,
7
+ max = 3,
8
+ count,
9
+ more = (hidden) => `and ${hidden} more`,
10
+ expandLabel = "Show all",
11
+ collapseLabel = "Show less",
12
+ empty,
13
+ separator = ", ",
14
+ defaultExpanded = false,
15
+ className,
16
+ ...props
17
+ }) {
18
+ const [expanded, setExpanded] = useState(defaultExpanded);
19
+ const listId = useId();
20
+ const limit = Math.max(1, Math.floor(max));
21
+ const collapsible = items.length > limit + 1;
22
+ const shown = collapsible && !expanded ? items.slice(0, limit) : items;
23
+ return /* @__PURE__ */ jsx("div", { className: cx("uix-list-summary", className), ...props, children: items.length === 0 ? /* @__PURE__ */ jsx("p", { className: "uix-list-summary__items", children: empty }) : /* @__PURE__ */ jsxs(Fragment, { children: [
24
+ count ? /* @__PURE__ */ jsx("p", { className: "uix-list-summary__count", children: count(items.length) }) : null,
25
+ /* @__PURE__ */ jsxs("p", { className: "uix-list-summary__items", children: [
26
+ /* @__PURE__ */ jsxs("span", { id: listId, children: [
27
+ shown.join(separator),
28
+ collapsible && !expanded ? ` ${more(items.length - limit)}` : null
29
+ ] }),
30
+ collapsible ? /* @__PURE__ */ jsxs(Fragment, { children: [
31
+ " ",
32
+ /* @__PURE__ */ jsx(
33
+ "button",
34
+ {
35
+ type: "button",
36
+ className: "uix-list-summary__toggle",
37
+ "aria-expanded": expanded,
38
+ "aria-controls": listId,
39
+ onClick: () => setExpanded((open) => !open),
40
+ children: expanded ? collapseLabel : expandLabel
41
+ }
42
+ )
43
+ ] }) : null
44
+ ] })
45
+ ] }) });
46
+ }
47
+ export {
48
+ ListSummary
49
+ };
@@ -6,6 +6,8 @@ import { Popover } from "./Popover.js";
6
6
  import { CheckIcon } from "../icons/components.js";
7
7
  import { renderUixLink } from "../link.js";
8
8
  import { KbdCombo, ariaKeyShortcuts, isKeyShortcut, useKbdPlatform } from "./Kbd.js";
9
+ import { useHoverGlide } from "../hooks/useHoverGlide.js";
10
+ import { useArrivalBlur } from "../hooks/useArrivalBlur.js";
9
11
  function useRowShortcut(shortcut) {
10
12
  const platform = useKbdPlatform();
11
13
  if (shortcut == null) return { node: null, aria: {} };
@@ -32,6 +34,8 @@ function Menu({ trigger, children, open: controlledOpen, defaultOpen = false, on
32
34
  const open = controlledOpen ?? internalOpen;
33
35
  const focusOnOpen = useRef("first");
34
36
  const typeahead = useRef({ text: "", at: 0 });
37
+ const glideRef = useRef(null);
38
+ useHoverGlide(glideRef, ".uix-menu__item", open);
35
39
  const setOpen = (next) => {
36
40
  if (controlledOpen === void 0) setInternalOpen(next);
37
41
  onOpenChange?.(next);
@@ -78,6 +82,7 @@ function Menu({ trigger, children, open: controlledOpen, defaultOpen = false, on
78
82
  document.addEventListener("pointerdown", onPointer, true);
79
83
  return () => document.removeEventListener("pointerdown", onPointer, true);
80
84
  }, [open, menuId]);
85
+ useArrivalBlur(menu, ':scope > :is(.uix-menu__item, .uix-menu__label, .uix-menu__sep, [role="group"])', open);
81
86
  const onMenuKeyDown = (event) => {
82
87
  const list = items();
83
88
  const index = list.indexOf(document.activeElement);
@@ -143,6 +148,7 @@ function Menu({ trigger, children, open: controlledOpen, defaultOpen = false, on
143
148
  {
144
149
  id: menuId,
145
150
  popover: "manual",
151
+ "data-uix-animate-keys": "",
146
152
  anchor: triggerRef,
147
153
  placement,
148
154
  capHeight: true,
@@ -151,7 +157,10 @@ function Menu({ trigger, children, open: controlledOpen, defaultOpen = false, on
151
157
  "aria-labelledby": label ? void 0 : triggerProps.id ?? triggerId,
152
158
  className: cx("uix-menu", className),
153
159
  onKeyDown: onMenuKeyDown,
154
- children: open ? children : null
160
+ children: open ? /* @__PURE__ */ jsxs(Fragment, { children: [
161
+ /* @__PURE__ */ jsx("span", { ref: glideRef, className: "uix-glide", "aria-hidden": "true" }),
162
+ children
163
+ ] }) : null
155
164
  }
156
165
  )
157
166
  ] });
@@ -59,7 +59,10 @@ function Popover({
59
59
  watchInputModality();
60
60
  const el = ref.current;
61
61
  if (!el) return;
62
- const mark = () => markKeyOpened(el);
62
+ const mark = () => {
63
+ if (el.hasAttribute("data-uix-animate-keys")) el.removeAttribute("data-uix-key-opened");
64
+ else markKeyOpened(el);
65
+ };
63
66
  el.addEventListener("beforetoggle", mark);
64
67
  return () => el.removeEventListener("beforetoggle", mark);
65
68
  }, []);
@@ -4,7 +4,10 @@ import { Children, Fragment as Fragment2, forwardRef, isValidElement, useCallbac
4
4
  import { cx } from "../cx.js";
5
5
  import { useUixLabels } from "../labels-context.js";
6
6
  import { useAnchoredPosition, zoomOf } from "../hooks/useAnchoredPosition.js";
7
- import { markKeyOpened, watchInputModality } from "../motion.js";
7
+ import { blurIn, keyboardInitiated, tokenEase, tokenMs, tokenPx, watchInputModality } from "../motion.js";
8
+ import { prefersReducedMotion } from "../hooks/useReducedMotion.js";
9
+ import { useHoverGlide } from "../hooks/useHoverGlide.js";
10
+ import { useArrivalBlur } from "../hooks/useArrivalBlur.js";
8
11
  import { Drawer } from "./Drawer.js";
9
12
  import {
10
13
  buildSelectModel,
@@ -134,7 +137,7 @@ function labelText(trigger, own, ariaLabel, labelledBy) {
134
137
  const labels = trigger.labels;
135
138
  return labels ? Array.from(labels).map(read).join(" ").trim() : "";
136
139
  }
137
- const CheckIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
140
+ const CheckIcon = () => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5", pathLength: 1 }) });
138
141
  const Select = forwardRef(function Select2(props, forwardedRef) {
139
142
  const {
140
143
  size = "md",
@@ -181,6 +184,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
181
184
  const proxyRef = useRef(null);
182
185
  const popupRef = useRef(null);
183
186
  const listRef = useRef(null);
187
+ const glideRef = useRef(null);
184
188
  const searchRef = useRef(null);
185
189
  const staticItems = useMemo(() => options ? [...options] : parseChildren(children), [options, children]);
186
190
  const formModel = useMemo(() => buildSelectModel(staticItems), [staticItems]);
@@ -202,6 +206,30 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
202
206
  controlledRef.current = controlled;
203
207
  const [initialDefault] = useState(() => multiple ? values : current);
204
208
  const [open, setOpen] = useState(false);
209
+ const [justChosen, setJustChosen] = useState(null);
210
+ useEffect(() => {
211
+ if (justChosen == null) return void 0;
212
+ const t = setTimeout(() => setJustChosen(null), 600);
213
+ return () => clearTimeout(t);
214
+ }, [justChosen]);
215
+ const holdTimer = useRef(null);
216
+ const onHoldKey = () => clearHold();
217
+ const clearHold = () => {
218
+ document.removeEventListener("keydown", onHoldKey, true);
219
+ if (holdTimer.current != null) {
220
+ clearTimeout(holdTimer.current);
221
+ holdTimer.current = null;
222
+ }
223
+ };
224
+ useEffect(() => clearHold, []);
225
+ const valueKey = values.join("|");
226
+ const lastValueKey = useRef(valueKey);
227
+ const valueChanged = useRef(false);
228
+ if (lastValueKey.current !== valueKey) {
229
+ lastValueKey.current = valueKey;
230
+ valueChanged.current = true;
231
+ }
232
+ useHoverGlide(glideRef, ".uix-listbox__option", open);
205
233
  const [mode, setMode] = useState("popover");
206
234
  const [active, setActive] = useState(-1);
207
235
  const [query, setQuery] = useState("");
@@ -369,6 +397,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
369
397
  setOpen(true);
370
398
  };
371
399
  const close = (opts = {}) => {
400
+ clearHold();
372
401
  if (opts.revert && multiple) {
373
402
  const was = snapshot.current;
374
403
  const now = valuesRef.current;
@@ -382,6 +411,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
382
411
  };
383
412
  const choose = (entry, closeAfter = !multiple) => {
384
413
  if (!entry || entry.disabled) return;
414
+ setJustChosen(entry.option.value);
385
415
  if (multiple) {
386
416
  commit(toggleValue(valuesRef.current, entry.option.value), entry.option);
387
417
  setActive(entry.index);
@@ -389,6 +419,17 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
389
419
  return;
390
420
  }
391
421
  if (entry.option.value !== current) commit([entry.option.value], entry.option);
422
+ const pointer = !keyboardInitiated() && !!window.matchMedia?.("(hover: hover)").matches;
423
+ const hold = mode === "popover" && pointer && !prefersReducedMotion() ? tokenMs("--uix-hold-pick", 250) : 0;
424
+ if (hold > 0) {
425
+ clearHold();
426
+ holdTimer.current = setTimeout(() => {
427
+ clearHold();
428
+ close({ focus: true });
429
+ }, hold);
430
+ document.addEventListener("keydown", onHoldKey, true);
431
+ return;
432
+ }
392
433
  close({ focus: true });
393
434
  };
394
435
  const clearAll = () => {
@@ -541,16 +582,14 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
541
582
  const zoom = zoomOf(trigger);
542
583
  const r = trigger.getBoundingClientRect();
543
584
  const room = Math.max(r.top, window.innerHeight - r.bottom) / zoom - OFFSET - EDGE;
544
- popup.style.minWidth = `${Math.round(r.width / zoom)}px`;
585
+ popup.style.minWidth = `${Math.round(trigger.offsetWidth || r.width / zoom)}px`;
545
586
  popup.style.maxHeight = `${Math.max(96, Math.min(MAX_HEIGHT, Math.floor(room)))}px`;
546
- if (!isOpen()) markKeyOpened(popup);
547
587
  try {
548
588
  if (!isOpen()) popup.showPopover();
549
589
  } catch {
550
590
  }
551
591
  if (isSearchable) searchRef.current?.focus({ preventScroll: true });
552
592
  } else {
553
- if (isOpen()) markKeyOpened(popup);
554
593
  try {
555
594
  if (isOpen()) popup.hidePopover();
556
595
  } catch {
@@ -561,6 +600,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
561
600
  watchInputModality();
562
601
  }, []);
563
602
  useAnchoredPosition(triggerRef, popupRef, { open: showing, placement, offset: OFFSET, padding: EDGE });
603
+ useArrivalBlur(() => popupRef.current, ".uix-listbox > :is(.uix-listbox__option, .uix-listbox__group)", showing);
564
604
  useEffect(() => {
565
605
  if (open && mode === "sheet") (isSearchable ? searchRef.current : listRef.current)?.focus({ preventScroll: true });
566
606
  }, [open, mode, isSearchable]);
@@ -601,6 +641,36 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
601
641
  firstSelected?.icon != null && /* @__PURE__ */ jsx("span", { className: "uix-select__icon", "aria-hidden": "true", children: firstSelected.icon }),
602
642
  /* @__PURE__ */ jsx("span", { className: "uix-select__text", children: firstSelected?.label })
603
643
  ] });
644
+ const valueRef = useRef(null);
645
+ const shownText = useRef(null);
646
+ useIsomorphicLayoutEffect(() => {
647
+ const trigger = triggerRef.current;
648
+ const was = shownText.current;
649
+ shownText.current = valueRef.current?.textContent ?? "";
650
+ if (!trigger || was == null || was === shownText.current || prefersReducedMotion()) return void 0;
651
+ trigger.setAttribute("data-leaving", was);
652
+ trigger.removeAttribute("data-swap");
653
+ void trigger.offsetWidth;
654
+ trigger.setAttribute("data-swap", "");
655
+ const blur = tokenPx("--uix-arrive-blur", 4);
656
+ const duration = tokenMs("--uix-dur-overlay", 400);
657
+ const ease = tokenEase("--uix-ease-soft");
658
+ const stops = [
659
+ valueRef.current ? blurIn([valueRef.current], { from: blur, duration, ease }) : () => {
660
+ },
661
+ blurIn([trigger], { from: blur, duration, ease, leave: true, property: "--uix-leaving-blur" })
662
+ ];
663
+ const t = setTimeout(() => {
664
+ trigger.removeAttribute("data-leaving");
665
+ trigger.removeAttribute("data-swap");
666
+ }, duration);
667
+ return () => {
668
+ clearTimeout(t);
669
+ stops.forEach((stop) => stop());
670
+ trigger.removeAttribute("data-leaving");
671
+ trigger.removeAttribute("data-swap");
672
+ };
673
+ }, [valueKey]);
604
674
  const more = multiple && values.length > 1 ? values.length - 1 : 0;
605
675
  const isInvalid = !!invalid || formInvalid || ariaInvalid != null && ariaInvalid !== false && ariaInvalid !== "false";
606
676
  const popoverAttr = { popover: "manual" };
@@ -641,6 +711,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
641
711
  "aria-selected": selected,
642
712
  "aria-disabled": entry.disabled || void 0,
643
713
  "data-active": open && isActive || void 0,
714
+ "data-just-chosen": selected && justChosen === o.value || void 0,
644
715
  onMouseDown: (e) => e.preventDefault(),
645
716
  onPointerMove: () => {
646
717
  if (!isActive && !entry.disabled) setActive(entry.index);
@@ -665,7 +736,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
665
736
  };
666
737
  const empty = entries.length === 0;
667
738
  const status = hasLoader ? asyncState.status : "ready";
668
- const listbox = /* @__PURE__ */ jsx(
739
+ const listbox = /* @__PURE__ */ jsxs(
669
740
  "div",
670
741
  {
671
742
  ref: listRef,
@@ -679,10 +750,13 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
679
750
  tabIndex: mode === "sheet" ? 0 : -1,
680
751
  hidden: entries.length === 0 || void 0,
681
752
  onKeyDown: mode === "sheet" && !isSearchable ? (e) => onOpenKey(e, false) : void 0,
682
- children: listModel.sections.map((section, i) => section.label != null ? /* @__PURE__ */ jsxs("div", { role: "group", className: "uix-listbox__group", "aria-labelledby": `${uid}-group-${i}`, "aria-disabled": section.disabled || void 0, children: [
683
- /* @__PURE__ */ jsx("div", { id: `${uid}-group-${i}`, role: "presentation", className: "uix-listbox__group-label", children: section.label }),
684
- section.entries.map(renderEntry)
685
- ] }, `g${i}`) : /* @__PURE__ */ jsx(Fragment2, { children: section.entries.map(renderEntry) }, `s${i}`))
753
+ children: [
754
+ /* @__PURE__ */ jsx("span", { ref: glideRef, className: "uix-glide", "aria-hidden": "true" }),
755
+ listModel.sections.map((section, i) => section.label != null ? /* @__PURE__ */ jsxs("div", { role: "group", className: "uix-listbox__group", "aria-labelledby": `${uid}-group-${i}`, "aria-disabled": section.disabled || void 0, children: [
756
+ /* @__PURE__ */ jsx("div", { id: `${uid}-group-${i}`, role: "presentation", className: "uix-listbox__group-label", children: section.label }),
757
+ section.entries.map(renderEntry)
758
+ ] }, `g${i}`) : /* @__PURE__ */ jsx(Fragment2, { children: section.entries.map(renderEntry) }, `s${i}`))
759
+ ]
686
760
  }
687
761
  );
688
762
  const stateRow = status === "loading" && empty ? /* @__PURE__ */ jsxs("div", { className: "uix-select__state", role: "status", children: [
@@ -738,7 +812,7 @@ const Select = forwardRef(function Select2(props, forwardedRef) {
738
812
  onFocus: handleFocus,
739
813
  onBlur: handleBlur,
740
814
  children: [
741
- /* @__PURE__ */ jsx("span", { className: "uix-select__value", children: display }),
815
+ /* @__PURE__ */ jsx("span", { ref: valueRef, className: "uix-select__value", "data-changed": valueChanged.current || void 0, children: display }, valueKey),
742
816
  more > 0 && /* @__PURE__ */ jsxs("span", { className: "uix-select__more", children: [
743
817
  /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", children: [
744
818
  "+",
@@ -6,6 +6,10 @@ import { useUixLabels } from "../labels-context.js";
6
6
  import { SearchIcon } from "../icons/components.js";
7
7
  import { useInShellDrawer } from "../shell-context.js";
8
8
  import { KbdCombo, ariaKeyShortcuts, useKbdPlatform } from "./Kbd.js";
9
+ import { useHoverGlide } from "../hooks/useHoverGlide.js";
10
+ import { useSlidingIndicator } from "../hooks/useSlidingIndicator.js";
11
+ import { useArrivalBlur } from "../hooks/useArrivalBlur.js";
12
+ import { watchInputModality } from "../motion.js";
9
13
  const ChevronIcon = () => /* @__PURE__ */ jsx("svg", { className: "uix-navgroup__chevron", viewBox: "0 0 12 12", fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M2 4l4 4 4-4" }) });
10
14
  function Sidebar({ collapsed, nav, onToggle, brand, toggleIcon, actions, search, footer, children, expandLabel: expandLabelProp, collapseLabel: collapseLabelProp, className, ...props }) {
11
15
  const uixLabels = useUixLabels();
@@ -14,7 +18,26 @@ function Sidebar({ collapsed, nav, onToggle, brand, toggleIcon, actions, search,
14
18
  const inDrawer = useInShellDrawer();
15
19
  const isCollapsed = !inDrawer && (collapsed ?? nav === "rail");
16
20
  const platform = useKbdPlatform();
17
- return /* @__PURE__ */ jsxs("nav", { className: cx("uix-sidebar", className), "data-collapsed": isCollapsed || void 0, "data-nav": inDrawer ? void 0 : nav, ...props, children: [
21
+ const navRef = useRef(null);
22
+ const glideRef = useRef(null);
23
+ const markRef = useRef(null);
24
+ useHoverGlide(glideRef, ".uix-navitem");
25
+ useSlidingIndicator(navRef, markRef, '.uix-navitem[aria-current="page"]');
26
+ const lastCollapsed = useRef(isCollapsed);
27
+ useEffect(() => {
28
+ const el = navRef.current;
29
+ if (!el || lastCollapsed.current === isCollapsed) return void 0;
30
+ lastCollapsed.current = isCollapsed;
31
+ el.setAttribute("data-uix-toggled", "");
32
+ const t = setTimeout(() => el.removeAttribute("data-uix-toggled"), 600);
33
+ return () => {
34
+ clearTimeout(t);
35
+ el.removeAttribute("data-uix-toggled");
36
+ };
37
+ }, [isCollapsed]);
38
+ return /* @__PURE__ */ jsxs("nav", { ref: navRef, className: cx("uix-sidebar", className), "data-collapsed": isCollapsed || void 0, "data-nav": inDrawer ? void 0 : nav, ...props, children: [
39
+ /* @__PURE__ */ jsx("span", { ref: glideRef, className: "uix-glide", "aria-hidden": "true" }),
40
+ /* @__PURE__ */ jsx("span", { ref: markRef, className: "uix-sidebar__mark", "aria-hidden": "true", hidden: true }),
18
41
  (brand != null || onToggle || actions != null) && /* @__PURE__ */ jsxs("div", { className: "uix-sidebar__head", children: [
19
42
  brand && /* @__PURE__ */ jsx("div", { className: "uix-sidebar__brand", children: brand }),
20
43
  actions != null && /* @__PURE__ */ jsx("div", { className: "uix-sidebar__actions", children: actions }),
@@ -96,6 +119,10 @@ function NavGroup({ icon, label, children, defaultExpanded = true, expanded: con
96
119
  const panelId = useId();
97
120
  const triggerRef = useRef(null);
98
121
  const panelRef = useRef(null);
122
+ useEffect(() => {
123
+ watchInputModality();
124
+ }, []);
125
+ useArrivalBlur(() => panelRef.current, ":scope > div > .uix-subitem", expanded, true);
99
126
  useEffect(() => {
100
127
  panelRef.current?.toggleAttribute("inert", !expanded);
101
128
  if (!expanded && panelRef.current?.contains(document.activeElement)) triggerRef.current?.focus();
@@ -105,7 +132,7 @@ function NavGroup({ icon, label, children, defaultExpanded = true, expanded: con
105
132
  if (controlledExpanded == null) setInternalExpanded(next);
106
133
  onExpandedChange?.(next);
107
134
  };
108
- return /* @__PURE__ */ jsxs("div", { className: "uix-navgroup", children: [
135
+ return /* @__PURE__ */ jsxs("div", { className: "uix-navgroup", "data-plain": icon ? void 0 : "", children: [
109
136
  /* @__PURE__ */ jsxs(
110
137
  "button",
111
138
  {