@sdxc/ui 2026.9.14 → 2026.9.29

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 (83) hide show
  1. package/dist/animations/keyframes.d.ts +6 -0
  2. package/dist/animations/keyframes.js +8 -4
  3. package/dist/components/accordion.js +5 -1
  4. package/dist/components/alert-dialog.js +2 -2
  5. package/dist/components/attachment.js +7 -2
  6. package/dist/components/bubble.js +14 -20
  7. package/dist/components/button.d.ts +0 -14
  8. package/dist/components/button.js +60 -19
  9. package/dist/components/calendar.js +12 -5
  10. package/dist/components/card.js +8 -1
  11. package/dist/components/carousel.js +9 -3
  12. package/dist/components/color-picker.js +23 -4
  13. package/dist/components/color-slider.js +11 -1
  14. package/dist/components/color-wheel.js +14 -4
  15. package/dist/components/command.js +34 -7
  16. package/dist/components/date-picker.d.ts +20 -53
  17. package/dist/components/date-picker.js +50 -108
  18. package/dist/components/date-range-picker.d.ts +22 -43
  19. package/dist/components/date-range-picker.js +8 -52
  20. package/dist/components/dialog.js +27 -4
  21. package/dist/components/disclosure.d.ts +4 -1
  22. package/dist/components/disclosure.js +52 -11
  23. package/dist/components/drawer.js +16 -0
  24. package/dist/components/drop-indicator.d.ts +9 -8
  25. package/dist/components/drop-indicator.js +19 -6
  26. package/dist/components/empty.js +18 -3
  27. package/dist/components/file-trigger.js +35 -15
  28. package/dist/components/form.d.ts +15 -1
  29. package/dist/components/form.js +16 -6
  30. package/dist/components/grid-list.js +23 -7
  31. package/dist/components/group.d.ts +6 -6
  32. package/dist/components/group.js +28 -6
  33. package/dist/components/hover-card.js +38 -2
  34. package/dist/components/image-placeholder.js +8 -2
  35. package/dist/components/input.js +22 -21
  36. package/dist/components/item.js +9 -1
  37. package/dist/components/keyboard.d.ts +7 -7
  38. package/dist/components/keyboard.js +33 -7
  39. package/dist/components/link-button.js +32 -18
  40. package/dist/components/listbox.js +10 -1
  41. package/dist/components/menu.js +8 -2
  42. package/dist/components/message-scroller.js +19 -6
  43. package/dist/components/meter.js +17 -8
  44. package/dist/components/number-field.js +9 -3
  45. package/dist/components/overlay-arrow.js +16 -2
  46. package/dist/components/popover.js +31 -8
  47. package/dist/components/range-calendar.js +18 -4
  48. package/dist/components/search-field.d.ts +26 -1
  49. package/dist/components/search-field.js +84 -4
  50. package/dist/components/select.d.ts +7 -1
  51. package/dist/components/select.js +33 -29
  52. package/dist/components/sidebar.js +32 -11
  53. package/dist/components/slider.js +10 -6
  54. package/dist/components/table.js +2 -2
  55. package/dist/components/toggle-button.js +39 -15
  56. package/dist/components/tree.d.ts +6 -6
  57. package/dist/components/tree.js +25 -9
  58. package/dist/components/typeset.js +12 -1
  59. package/dist/mixins/calendar-keys.d.ts +6 -6
  60. package/dist/mixins/calendar-keys.js +35 -6
  61. package/dist/mixins/carousel-controls.d.ts +4 -2
  62. package/dist/mixins/carousel-controls.js +71 -20
  63. package/dist/mixins/clear-field.d.ts +9 -7
  64. package/dist/mixins/clear-field.js +25 -8
  65. package/dist/mixins/command-keys.js +22 -7
  66. package/dist/mixins/context-menu.d.ts +2 -0
  67. package/dist/mixins/context-menu.js +27 -1
  68. package/dist/mixins/copy-to-clipboard.js +15 -1
  69. package/dist/mixins/grid-list-keys.d.ts +6 -6
  70. package/dist/mixins/grid-list-keys.js +28 -6
  71. package/dist/mixins/hotkey.js +16 -9
  72. package/dist/mixins/index.d.ts +1 -0
  73. package/dist/mixins/index.js +1 -0
  74. package/dist/mixins/listbox-keys.js +20 -2
  75. package/dist/mixins/message-follow.js +50 -12
  76. package/dist/mixins/mirror-selected-option.d.ts +24 -0
  77. package/dist/mixins/mirror-selected-option.js +35 -0
  78. package/dist/mixins/treeKeys.d.ts +3 -2
  79. package/dist/mixins/treeKeys.js +53 -6
  80. package/dist/mixins/validate.d.ts +1 -1
  81. package/package.json +5 -5
  82. package/src/reset.css +6 -4
  83. package/src/theme.css +33 -3
@@ -54,13 +54,13 @@ export declare namespace Tree {
54
54
  interface LoadMoreItemProps extends TagProps<"div"> {
55
55
  }
56
56
  /**
57
- * Props accepted by {@link Tree.ExpandButton}: every native `<button>`
58
- * attribute except `type` (fixed to `"button"` so it never submits an
59
- * enclosing form), plus a required `aria-label` for the icon-only control.
57
+ * Props accepted by {@link Tree.ExpandButton}: every native `<span>` attribute.
58
+ *
59
+ * No accessible name is asked for, because the chevron names nothing: the row it
60
+ * sits in is a `<summary>`, which announces the branch and its expanded state on
61
+ * its own, and a second name beside it would be read out twice.
60
62
  */
61
- interface ExpandButtonProps extends Omit<TagProps<"button">, "type"> {
62
- /** Accessible name for the icon-only control, e.g. "Expand" or "Collapse". */
63
- "aria-label": string;
63
+ interface ExpandButtonProps extends TagProps<"span"> {
64
64
  }
65
65
  }
66
66
  /**
@@ -37,6 +37,12 @@ const DEFAULT_DEPTH = 0;
37
37
  * own value, letting {@link Tree.Item}'s styling target just this chevron.
38
38
  */
39
39
  const DEFAULT_EXPAND_BUTTON_SLOT = "expand-button";
40
+ /**
41
+ * Inline space a row with no {@link Tree.ExpandButton} keeps where the chevron would
42
+ * sit — the chevron's own width plus the row's gap — so a leaf's icon lines up under
43
+ * the icons of the branches around it instead of under their chevrons.
44
+ */
45
+ const LEAF_GUTTER = "calc(var(--ui-spacing, 0.25rem) * 7)";
40
46
  /**
41
47
  * Reads the nesting depth published by the nearest ancestor {@link Tree.Item},
42
48
  * resolving to `undefined` when the lookup finds no ancestor item at all.
@@ -130,14 +136,18 @@ function TreeItem(handle) {
130
136
  return (_jsx("details", { ...rest, id: id, "data-rmx-key": id, mix: [
131
137
  attrs({ role: DEFAULT_ITEM_ROLE }),
132
138
  interpolateSize(),
133
- detailsContent([clip(), bs(0)]),
134
139
  detailsContent([
140
+ clip(),
135
141
  raw({
136
142
  transitionProperty: "block-size, content-visibility",
137
143
  transitionBehavior: "allow-discrete",
138
144
  }),
139
145
  transitionDuration("200ms"),
140
146
  ]),
147
+ // Collapsed and expanded sizes are written under selectors that never
148
+ // match at once, so the reveal holds whichever order the cascade puts
149
+ // the pair in.
150
+ when("&:not([open])::details-content", bs(0)),
141
151
  when("&[open]::details-content", bs("auto")),
142
152
  when(`&[open] > summary [data-slot="${DEFAULT_EXPAND_BUTTON_SLOT}"]`, rotate(90)),
143
153
  media("(prefers-reduced-motion: reduce)", detailsContent(transitionDuration("0s"))),
@@ -177,9 +187,14 @@ Tree.ItemContent = function TreeItemContent(handle) {
177
187
  fg("neutral.emphasis"),
178
188
  cursor("default"),
179
189
  listStyle(),
180
- raw({
190
+ // The two indents are written under selectors that never match at once, so
191
+ // a row keeps its own whichever order the cascade puts the pair in.
192
+ when(`&:has([data-slot="${DEFAULT_EXPAND_BUTTON_SLOT}"])`, raw({
181
193
  paddingInlineStart: `calc(0.5rem + ${depth} * var(--ui-tree-indent, 1.25rem))`,
182
- }),
194
+ })),
195
+ when(`&:not(:has([data-slot="${DEFAULT_EXPAND_BUTTON_SLOT}"]))`, raw({
196
+ paddingInlineStart: `calc(0.5rem + ${depth} * var(--ui-tree-indent, 1.25rem) + ${LEAF_GUTTER})`,
197
+ })),
183
198
  outline("none"),
184
199
  text("sm"),
185
200
  when("&::-webkit-details-marker", hidden()),
@@ -208,9 +223,12 @@ Tree.LoadMoreItem = SentinelRow;
208
223
  /**
209
224
  * Renders the chevron a node's row shows for a subtree, rotated 90 degrees
210
225
  * while the enclosing {@link Tree.Item}'s `<details>` carries `[open]`.
211
- * `type="button"` precedes the consumer's attributes so a `command`/`commandfor` invoker still runs inside a `<form>`.
212
226
  *
213
- * @param handle Runtime handle carrying the host `<button>`'s props.
227
+ * It is decoration, not a control: the row it sits in is a `<summary>`, which is already
228
+ * the thing that opens the branch, and a button nested inside one takes the activation
229
+ * for itself — the chevron would be the one place on the row that did not expand it.
230
+ *
231
+ * @param handle Runtime handle carrying the host `<span>`'s props.
214
232
  * @returns The render function producing the chevron's markup.
215
233
  * @example
216
234
  * <Tree.ItemContent>
@@ -221,8 +239,8 @@ Tree.LoadMoreItem = SentinelRow;
221
239
  Tree.ExpandButton = function TreeExpandButton(handle) {
222
240
  return () => {
223
241
  let { children, mix, ...rest } = handle.props;
224
- return (_jsx("button", { type: "button", ...rest, mix: [
225
- attrs({ "data-slot": DEFAULT_EXPAND_BUTTON_SLOT }),
242
+ return (_jsx("span", { ...rest, mix: [
243
+ attrs({ "data-slot": DEFAULT_EXPAND_BUTTON_SLOT, "aria-hidden": "true" }),
226
244
  center(),
227
245
  is(5),
228
246
  bs(5),
@@ -231,8 +249,6 @@ Tree.ExpandButton = function TreeExpandButton(handle) {
231
249
  transition("transform, background-color"),
232
250
  shrink(),
233
251
  media("(prefers-reduced-motion: reduce)", transitionDuration("0s")),
234
- when("&:hover", bg("neutral.bg-tint-pressed")),
235
- when("&:focus-visible", outline("brand.ring")),
236
252
  mix,
237
253
  ], children: children ?? _jsx(ChevronRightIcon, { size: 16 }) }));
238
254
  };
@@ -251,7 +251,18 @@ export function Typeset(handle) {
251
251
  pb("0.875em"),
252
252
  overflow("auto"),
253
253
  ]),
254
- when("& :where(pre code)", [bg("transparent"), fg("inherit"), rounded("none")]),
254
+ /*
255
+ * A fenced block's `code` is an inline box, so the chip padding above would
256
+ * apply at the start of the box alone and indent the block's first line
257
+ * past every line under it. The block's own padding is the `pre`'s.
258
+ */
259
+ when("& :where(pre code)", [
260
+ bg("transparent"),
261
+ fg("inherit"),
262
+ rounded("none"),
263
+ pi(0),
264
+ pb(0),
265
+ ]),
255
266
  when("& :where(table)", [
256
267
  block(),
257
268
  is("max(100%, max-content)"),
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Keyboard navigation for a Calendar grid: moves day/week/month focus on a
3
- * `CalendarModel` from Arrow/Page/Home/End keys, then mirrors the model's
4
- * focused day back onto the grid as roving `tabindex` and DOM focus.
2
+ * Day navigation for a Calendar grid: the Arrow/Page/Home/End keys and a click
3
+ * on a day cell both move a `CalendarModel`'s focused day, which mirrors back
4
+ * onto the grid as roving `tabindex` and DOM focus.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
@@ -14,9 +14,9 @@ import type { CalendarModel } from "../behaviors/calendar-model.js";
14
14
  */
15
15
  export declare const CALENDAR_DAY_DATE_ATTRIBUTE = "data-date";
16
16
  /**
17
- * Adds keyboard navigation to a Calendar grid: each key delegates to the
18
- * matching `CalendarModel` method, and any `focusedDate` change — from a key
19
- * or another caller of the model — re-syncs roving `tabindex` and DOM focus.
17
+ * Adds keyboard and pointer navigation to a Calendar grid: each key delegates
18
+ * to the matching `CalendarModel` method, a click focuses the day cell it
19
+ * lands on, and any `focusedDate` change re-syncs `tabindex` and DOM focus.
20
20
  *
21
21
  * @param model Behavior class instance owning the grid's focused day, visible
22
22
  * month, and range selection state.
@@ -1,12 +1,13 @@
1
1
  /**
2
- * Keyboard navigation for a Calendar grid: moves day/week/month focus on a
3
- * `CalendarModel` from Arrow/Page/Home/End keys, then mirrors the model's
4
- * focused day back onto the grid as roving `tabindex` and DOM focus.
2
+ * Day navigation for a Calendar grid: the Arrow/Page/Home/End keys and a click
3
+ * on a day cell both move a `CalendarModel`'s focused day, which mirrors back
4
+ * onto the grid as roving `tabindex` and DOM focus.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
9
  import { createElement, createMixin, on } from "remix/ui";
10
+ import { DISABLED_SELECTOR } from "../utils/disabled-selector.js";
10
11
  /**
11
12
  * Attribute every calendar day cell exposes its date on, in local
12
13
  * `YYYY-MM-DD` form, that `calendarKeys()` matches against a
@@ -28,9 +29,26 @@ function toDateKey(date) {
28
29
  return `${year}-${month}-${day}`;
29
30
  }
30
31
  /**
31
- * Adds keyboard navigation to a Calendar grid: each key delegates to the
32
- * matching `CalendarModel` method, and any `focusedDate` change — from a key
33
- * or another caller of the model — re-syncs roving `tabindex` and DOM focus.
32
+ * Reads a day cell's {@link CALENDAR_DAY_DATE_ATTRIBUTE} value back into the
33
+ * local-midnight `Date` a `CalendarModel` counts in, so a clicked cell lands
34
+ * on the same day the keyboard path moves between.
35
+ *
36
+ * @param key Attribute value in `YYYY-MM-DD` form, or `null` when absent.
37
+ * @returns The day named, or `null` when `key` is missing or malformed.
38
+ */
39
+ function fromDateKey(key) {
40
+ if (key === null)
41
+ return null;
42
+ let match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(key);
43
+ if (match === null)
44
+ return null;
45
+ let [, year, month, day] = match;
46
+ return new Date(Number(year), Number(month) - 1, Number(day));
47
+ }
48
+ /**
49
+ * Adds keyboard and pointer navigation to a Calendar grid: each key delegates
50
+ * to the matching `CalendarModel` method, a click focuses the day cell it
51
+ * lands on, and any `focusedDate` change re-syncs `tabindex` and DOM focus.
34
52
  *
35
53
  * @param model Behavior class instance owning the grid's focused day, visible
36
54
  * month, and range selection state.
@@ -71,6 +89,17 @@ export const calendarKeys = createMixin((handle) => {
71
89
  }
72
90
  return createElement(handle.element, {
73
91
  mix: [
92
+ on("click", (event) => {
93
+ if (!(event.target instanceof Element))
94
+ return;
95
+ let cell = event.target.closest(`[${CALENDAR_DAY_DATE_ATTRIBUTE}]`);
96
+ if (cell === null || cell.matches(DISABLED_SELECTOR))
97
+ return;
98
+ let date = fromDateKey(cell.getAttribute(CALENDAR_DAY_DATE_ATTRIBUTE));
99
+ if (date === null || model.isDisabled(date))
100
+ return;
101
+ model.focusDate(date);
102
+ }),
74
103
  on("keydown", (event) => {
75
104
  switch (event.key) {
76
105
  case "ArrowUp":
@@ -15,8 +15,10 @@
15
15
  export declare const CAROUSEL_SLIDE_ATTRIBUTE = "data-carousel-slide";
16
16
  /**
17
17
  * Adds `--ui-prev`/`--ui-next`/`--ui-goto` command handling to a Carousel
18
- * viewport, scrolling by page or to a `data-slide` index and re-syncing every
19
- * invoker button's disabled state on every command, scroll, and resize.
18
+ * viewport, scrolling by page or to a `data-slide` index and, on every command,
19
+ * scroll and resize, re-syncing what the invokers say: each `--ui-prev`/`--ui-next`
20
+ * button's disabled state, and `aria-current` on whichever `--ui-goto` button names
21
+ * the slide in view.
20
22
  *
21
23
  * @example
22
24
  * <div id="cart-carousel" mix={carouselControls()}>
@@ -30,16 +30,6 @@ export const CAROUSEL_SLIDE_ATTRIBUTE = "data-carousel-slide";
30
30
  * never leaves both — or neither — of a pair of invoker buttons enabled.
31
31
  */
32
32
  const EDGE_TOLERANCE_PX = 1;
33
- /**
34
- * Resolves the animation to scroll a Carousel command with. `scrollBy()`'s
35
- * smooth-scroll rides the platform's own animation, not a CSS transition, so
36
- * it never picks up the reduced-motion override applied there.
37
- *
38
- * @returns `"instant"` when the user prefers reduced motion, `"smooth"` otherwise.
39
- */
40
- function resolveScrollBehavior() {
41
- return window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth";
42
- }
43
33
  /**
44
34
  * Reports whether `node` renders in a right-to-left writing direction, so
45
35
  * scroll math can flip which physical direction counts as "previous" and
@@ -84,7 +74,7 @@ function readScrollEdges(node) {
84
74
  */
85
75
  function scrollByPage(node, direction) {
86
76
  let sign = isRightToLeft(node) ? -direction : direction;
87
- node.scrollBy({ left: sign * node.clientWidth, behavior: resolveScrollBehavior() });
77
+ node.scrollBy({ left: sign * node.clientWidth });
88
78
  }
89
79
  /**
90
80
  * Scrolls `node` so the slide at `index` among its
@@ -99,14 +89,68 @@ function scrollToSlide(node, index) {
99
89
  let slide = slides[index];
100
90
  if (slide === undefined)
101
91
  return;
102
- let targetScrollLeft = isRightToLeft(node)
103
- ? slide.offsetLeft - getMaxScrollLeft(node)
104
- : slide.offsetLeft;
105
- node.scrollBy({
106
- left: targetScrollLeft - node.scrollLeft,
107
- behavior: resolveScrollBehavior(),
92
+ /*
93
+ * Measured against the viewport's own box rather than through `offsetLeft`, which
94
+ * reports a distance from whichever ancestor happens to be positioned — usually the
95
+ * page — and so scrolls the carousel by however far it sits from that ancestor.
96
+ */
97
+ let viewportEdges = node.getBoundingClientRect();
98
+ let slideEdges = slide.getBoundingClientRect();
99
+ /*
100
+ * Given as a position rather than a distance. A distance is measured against wherever
101
+ * the viewport happens to be at that instant, so a second command arriving while the
102
+ * first is still animating moves by an amount that is already stale; a position is the
103
+ * same answer however many times it is asked, and the scroller simply retargets.
104
+ */
105
+ node.scrollTo({
106
+ left: node.scrollLeft +
107
+ (isRightToLeft(node)
108
+ ? slideEdges.right - viewportEdges.right
109
+ : slideEdges.left - viewportEdges.left),
108
110
  });
109
111
  }
112
+ /**
113
+ * Reads which slide the viewport has settled on: the one whose start edge sits nearest
114
+ * the viewport's own, which is the slide a mandatory snap leaves in view.
115
+ *
116
+ * @param node Carousel viewport to read.
117
+ * @returns The zero-based position of the slide in view, or `null` when there are none.
118
+ */
119
+ function readCurrentSlideIndex(node) {
120
+ let slides = node.querySelectorAll(`[${CAROUSEL_SLIDE_ATTRIBUTE}]`);
121
+ if (slides.length === 0)
122
+ return null;
123
+ let viewportEdges = node.getBoundingClientRect();
124
+ let rightToLeft = isRightToLeft(node);
125
+ let closest = 0;
126
+ let shortest = Number.POSITIVE_INFINITY;
127
+ for (let [index, slide] of slides.entries()) {
128
+ let slideEdges = slide.getBoundingClientRect();
129
+ let distance = Math.abs(rightToLeft ? slideEdges.right - viewportEdges.right : slideEdges.left - viewportEdges.left);
130
+ if (distance < shortest) {
131
+ shortest = distance;
132
+ closest = index;
133
+ }
134
+ }
135
+ return closest;
136
+ }
137
+ /**
138
+ * Marks whichever `--ui-goto` invoker names the slide in view, so a row of them reads as
139
+ * a position indicator rather than as five identical buttons.
140
+ *
141
+ * @param node Carousel viewport whose scroll position is read.
142
+ */
143
+ function syncGotoCurrent(node) {
144
+ let current = readCurrentSlideIndex(node);
145
+ if (current === null)
146
+ return;
147
+ for (let button of findInvokerButtons(node, GOTO_COMMAND)) {
148
+ if (readGotoSlideIndex(button) === current)
149
+ button.setAttribute("aria-current", "true");
150
+ else
151
+ button.removeAttribute("aria-current");
152
+ }
153
+ }
110
154
  /**
111
155
  * Parses a `--ui-goto` command's target slide index from its invoking
112
156
  * button's `data-slide` attribute.
@@ -174,8 +218,10 @@ function syncInvokerDisabled(node) {
174
218
  }
175
219
  /**
176
220
  * Adds `--ui-prev`/`--ui-next`/`--ui-goto` command handling to a Carousel
177
- * viewport, scrolling by page or to a `data-slide` index and re-syncing every
178
- * invoker button's disabled state on every command, scroll, and resize.
221
+ * viewport, scrolling by page or to a `data-slide` index and, on every command,
222
+ * scroll and resize, re-syncing what the invokers say: each `--ui-prev`/`--ui-next`
223
+ * button's disabled state, and `aria-current` on whichever `--ui-goto` button names
224
+ * the slide in view.
179
225
  *
180
226
  * @example
181
227
  * <div id="cart-carousel" mix={carouselControls()}>
@@ -190,7 +236,11 @@ export const carouselControls = createMixin((handle) => {
190
236
  handle.addEventListener("insert", (event) => {
191
237
  let viewport = event.node;
192
238
  syncInvokerDisabled(viewport);
193
- let observer = new ResizeObserver(() => syncInvokerDisabled(viewport));
239
+ syncGotoCurrent(viewport);
240
+ let observer = new ResizeObserver(() => {
241
+ syncInvokerDisabled(viewport);
242
+ syncGotoCurrent(viewport);
243
+ });
194
244
  observer.observe(viewport);
195
245
  handle.signal.addEventListener("abort", () => observer.disconnect());
196
246
  });
@@ -216,6 +266,7 @@ export const carouselControls = createMixin((handle) => {
216
266
  }),
217
267
  on("scroll", (event) => {
218
268
  syncInvokerDisabled(event.currentTarget);
269
+ syncGotoCurrent(event.currentTarget);
219
270
  }),
220
271
  ],
221
272
  });
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Wires a SearchField's clear button to empty its associated input alone
3
- * and reveals the button, shipped `hidden` in markup, the moment it mounts.
4
- * Script is required since a form button can only submit or reset every
5
- * field, and no built-in browser command clears a single input on its own —
6
- * WebKit's native `type="search"` cancel affordance is the only fallback.
2
+ * Wires a SearchField's clear button to empty its associated input alone, and
3
+ * keeps the button — shipped `hidden` in markup — showing exactly while that
4
+ * input holds a value. Script is required since a form button can only submit
5
+ * or reset every field, and no built-in browser command clears a single input
6
+ * on its own — WebKit's native `type="search"` cancel affordance is the only
7
+ * fallback.
7
8
  *
8
9
  * @author [Sergio Xalambrí](https://sergiodxa.com)
9
10
  * @copyright Sergio Xalambrí 2026
@@ -37,8 +38,9 @@ export declare class SearchFieldClearEvent extends Event {
37
38
  }
38
39
  /**
39
40
  * Wires a SearchField's clear button to empty its own `commandfor`-resolved
40
- * input and dispatch `input`/`change` plus {@link SearchFieldClearEvent}
41
- * before refocusing the field, since the button can vanish once styles react to the emptied state; a disabled, read-only, or already-empty target leaves the press with no effect.
41
+ * input and dispatch `input`/`change` plus {@link SearchFieldClearEvent} before
42
+ * refocusing the field, and shows the button exactly while that input holds text;
43
+ * a disabled, read-only, or already-empty target leaves the press with no effect.
42
44
  *
43
45
  * @returns A mixin descriptor for a SearchField clear button's `mix` prop.
44
46
  * @example
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Wires a SearchField's clear button to empty its associated input alone
3
- * and reveals the button, shipped `hidden` in markup, the moment it mounts.
4
- * Script is required since a form button can only submit or reset every
5
- * field, and no built-in browser command clears a single input on its own —
6
- * WebKit's native `type="search"` cancel affordance is the only fallback.
2
+ * Wires a SearchField's clear button to empty its associated input alone, and
3
+ * keeps the button — shipped `hidden` in markup — showing exactly while that
4
+ * input holds a value. Script is required since a form button can only submit
5
+ * or reset every field, and no built-in browser command clears a single input
6
+ * on its own — WebKit's native `type="search"` cancel affordance is the only
7
+ * fallback.
7
8
  *
8
9
  * @author [Sergio Xalambrí](https://sergiodxa.com)
9
10
  * @copyright Sergio Xalambrí 2026
@@ -52,8 +53,9 @@ function resolveClearTarget(button) {
52
53
  }
53
54
  /**
54
55
  * Wires a SearchField's clear button to empty its own `commandfor`-resolved
55
- * input and dispatch `input`/`change` plus {@link SearchFieldClearEvent}
56
- * before refocusing the field, since the button can vanish once styles react to the emptied state; a disabled, read-only, or already-empty target leaves the press with no effect.
56
+ * input and dispatch `input`/`change` plus {@link SearchFieldClearEvent} before
57
+ * refocusing the field, and shows the button exactly while that input holds text;
58
+ * a disabled, read-only, or already-empty target leaves the press with no effect.
57
59
  *
58
60
  * @returns A mixin descriptor for a SearchField clear button's `mix` prop.
59
61
  * @example
@@ -73,7 +75,22 @@ function resolveClearTarget(button) {
73
75
  */
74
76
  export const clearField = createMixin((handle) => {
75
77
  handle.addEventListener("insert", (event) => {
76
- event.node.hidden = false;
78
+ let button = event.node;
79
+ let input = resolveClearTarget(button);
80
+ /*
81
+ * A button whose target resolves later — markup that renders the input after it,
82
+ * or a `commandfor` the consumer rewrites — shows from the moment script runs, so
83
+ * its press stays reachable while the pairing settles.
84
+ */
85
+ if (!input) {
86
+ button.hidden = false;
87
+ return;
88
+ }
89
+ let syncVisibility = () => {
90
+ button.hidden = input.value === "";
91
+ };
92
+ syncVisibility();
93
+ input.addEventListener("input", syncVisibility, { signal: handle.signal });
77
94
  });
78
95
  return () => createElement(handle.element, {
79
96
  mix: [
@@ -78,8 +78,27 @@ function activateCurrent(root, model) {
78
78
  export const commandKeys = createMixin((handle) => {
79
79
  let hostNode;
80
80
  let boundModel;
81
+ /** The most recent model the mixin was given, which insertion subscribes to. */
82
+ let pendingModel;
83
+ /**
84
+ * The subscription belongs to the inserted host: it exists to write the active item
85
+ * onto a live node, and `handle.signal` is the lifetime of that node. Binding it while
86
+ * the host is only being rendered — on a server, say — subscribes on behalf of nothing
87
+ * and hands `addEventListener` a signal that does not exist yet.
88
+ */
89
+ function follow(model) {
90
+ if (boundModel === model)
91
+ return;
92
+ boundModel = model;
93
+ model.addEventListener("change", () => {
94
+ if (hostNode !== undefined)
95
+ syncActive(hostNode, model);
96
+ }, { signal: handle.signal });
97
+ }
81
98
  handle.addEventListener("insert", (event) => {
82
99
  hostNode = event.node;
100
+ if (pendingModel !== undefined)
101
+ follow(pendingModel);
83
102
  if (boundModel !== undefined)
84
103
  syncActive(hostNode, boundModel);
85
104
  });
@@ -87,13 +106,9 @@ export const commandKeys = createMixin((handle) => {
87
106
  hostNode = undefined;
88
107
  });
89
108
  return (model) => {
90
- if (boundModel !== model) {
91
- boundModel = model;
92
- model.addEventListener("change", () => {
93
- if (hostNode !== undefined)
94
- syncActive(hostNode, model);
95
- }, { signal: handle.signal });
96
- }
109
+ pendingModel = model;
110
+ if (hostNode !== undefined)
111
+ follow(model);
97
112
  return createElement(handle.element, {
98
113
  mix: [
99
114
  on("keydown", (event) => {
@@ -14,6 +14,8 @@ import { type AnchorOptions } from "remix/ui/anchor";
14
14
  * Opens the popover surface identified by `id` at the pointer position on a
15
15
  * `contextmenu` event, or the host's bounding box from the keyboard, since a
16
16
  * `popover="auto"` surface already handles its own Escape/outside-click dismissal.
17
+ * A pointer's menu opens on the release of the press that asked for it, so the surface
18
+ * stays up until the next press rather than being dismissed by that same one.
17
19
  *
18
20
  * @param id `id` of the popover surface to open.
19
21
  * @param options Anchor placement and offsets forwarded to `remix/ui/anchor`; placement defaults to `"bottom-start"`. Safe to omit — `contextMenu(id)` resets the runtime's trailing current-props argument back to an empty options object.
@@ -12,10 +12,14 @@ import { attrs, createElement, createMixin, on } from "remix/ui";
12
12
  import { anchor } from "remix/ui/anchor";
13
13
  /** Placement `contextMenu()` anchors the surface to when `options` doesn't specify one. */
14
14
  const DEFAULT_PLACEMENT = "bottom-start";
15
+ /** `MouseEvent.button` for the secondary press a pointer asks for a context menu with. */
16
+ const SECONDARY_BUTTON = 2;
15
17
  /**
16
18
  * Opens the popover surface identified by `id` at the pointer position on a
17
19
  * `contextmenu` event, or the host's bounding box from the keyboard, since a
18
20
  * `popover="auto"` surface already handles its own Escape/outside-click dismissal.
21
+ * A pointer's menu opens on the release of the press that asked for it, so the surface
22
+ * stays up until the next press rather than being dismissed by that same one.
19
23
  *
20
24
  * @param id `id` of the popover surface to open.
21
25
  * @param options Anchor placement and offsets forwarded to `remix/ui/anchor`; placement defaults to `"bottom-start"`. Safe to omit — `contextMenu(id)` resets the runtime's trailing current-props argument back to an empty options object.
@@ -25,6 +29,11 @@ const DEFAULT_PLACEMENT = "bottom-start";
25
29
  */
26
30
  export const contextMenu = createMixin((handle) => {
27
31
  let cleanupAnchor = () => { };
32
+ /**
33
+ * Read once here, because the mixin's lifetime is only readable while it is being set
34
+ * up — and the listener that needs it is registered from a pointer event much later.
35
+ */
36
+ let lifetime = handle.signal;
28
37
  handle.addEventListener("remove", () => cleanupAnchor());
29
38
  /** Shows the surface `id` refers to, if any, and anchors it to `point`, replacing any previous anchor tracking. */
30
39
  function openSurfaceAt(id, point, options) {
@@ -49,7 +58,24 @@ export const contextMenu = createMixin((handle) => {
49
58
  attrs({ "aria-controls": id, "aria-haspopup": "menu" }),
50
59
  on("contextmenu", (event) => {
51
60
  event.preventDefault();
52
- openSurfaceAt(id, { x: event.clientX, y: event.clientY }, options);
61
+ let point = { x: event.clientX, y: event.clientY };
62
+ /*
63
+ * A `popover="auto"` surface is dismissed by a press that begins outside it, and
64
+ * the press asking for the menu began before the menu existed: the browser pairs
65
+ * that pointerdown with the pointerup still to come and reads the pair as a click
66
+ * away. Opening once the button is released leaves the surface to the next press
67
+ * instead of the one that summoned it. A menu asked for from the keyboard reports
68
+ * no button and has no release to wait for, so it opens where it stands.
69
+ */
70
+ if (event.button !== SECONDARY_BUTTON) {
71
+ openSurfaceAt(id, point, options);
72
+ return;
73
+ }
74
+ document.addEventListener("pointerup", () => openSurfaceAt(id, point, options), {
75
+ capture: true,
76
+ once: true,
77
+ signal: lifetime,
78
+ });
53
79
  }),
54
80
  on("keydown", (event) => {
55
81
  if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10"))
@@ -37,6 +37,20 @@ export class CopyEvent extends Event {
37
37
  this.text = text;
38
38
  }
39
39
  }
40
+ /**
41
+ * Reads what a target offers to be copied. A form control keeps what it shows in its
42
+ * `value` and has no text of its own, so the pairing a copy button is most often written
43
+ * for — a read-only field beside a button — is read there rather than from its markup.
44
+ *
45
+ * @param target - The element the button's `commandfor` names.
46
+ * @returns The text to write to the clipboard, trimmed.
47
+ */
48
+ function copyableText(target) {
49
+ if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {
50
+ return target.value.trim();
51
+ }
52
+ return target.textContent?.trim() ?? "";
53
+ }
40
54
  /**
41
55
  * Finds the element a copy button's `commandfor` targets, preferring the
42
56
  * live `commandForElement` reference and falling back to an `id` lookup for
@@ -89,7 +103,7 @@ export const copyToClipboard = createMixin((handle) => {
89
103
  }
90
104
  return;
91
105
  }
92
- let text = target.textContent?.trim() ?? "";
106
+ let text = copyableText(target);
93
107
  if (text === "")
94
108
  return;
95
109
  try {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Adapts the WAI-ARIA grid keyboard pattern onto a GridList's rows and
3
- * action cells: one roving focus position moves with the arrow and
4
- * Home/End keys, and Space/Shift/Ctrl drive selection through a
2
+ * Adapts the WAI-ARIA grid pattern onto a GridList's rows and action
3
+ * cells: one roving focus position moves with the arrow and Home/End keys
4
+ * or a click, and Space, Shift and a click drive selection through a
5
5
  * `SelectionModel` instance.
6
6
  *
7
7
  * @author [Sergio Xalambrí](https://sergiodxa.com)
@@ -15,9 +15,9 @@ import type { SelectionModel } from "../behaviors/selection-model.js";
15
15
  */
16
16
  export declare const GRIDLIST_ROW_KEY_ATTRIBUTE = "data-rmx-key";
17
17
  /**
18
- * Adds ARIA grid keyboard navigation and selection to a GridList's rows and
19
- * action cells, driving a `SelectionModel` and mirroring its `"change"`
20
- * events back onto the rows as `aria-selected`.
18
+ * Adds ARIA grid keyboard and pointer navigation to a GridList's rows and
19
+ * action cells, driving a `SelectionModel` from both and mirroring its
20
+ * `"change"` events back onto the rows as `aria-selected`.
21
21
  *
22
22
  * @param model Behavior class instance owning the grid's selected keys.
23
23
  * @example