@barqjs/aria 0.2.0-next.0 → 0.2.0-next.1

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 (78) hide show
  1. package/README.md +24 -13
  2. package/package.json +127 -37
  3. package/src/autocomplete.tsx +581 -0
  4. package/src/breadcrumbs.tsx +21 -20
  5. package/src/button.tsx +151 -25
  6. package/src/calendar.tsx +1019 -92
  7. package/src/checkbox.tsx +214 -52
  8. package/src/collections.ts +88 -5
  9. package/src/color.ts +1580 -23
  10. package/src/colorpicker.tsx +698 -153
  11. package/src/colorswatchpicker.tsx +240 -0
  12. package/src/combobox.tsx +635 -113
  13. package/src/command.tsx +78 -59
  14. package/src/date.ts +31 -9
  15. package/src/datefield.tsx +1451 -336
  16. package/src/datepicker.tsx +465 -114
  17. package/src/dialog.tsx +302 -115
  18. package/src/disclosure.tsx +81 -29
  19. package/src/dnd/clipboard.ts +125 -0
  20. package/src/dnd/collection.ts +1265 -0
  21. package/src/dnd/data.ts +409 -0
  22. package/src/dnd/drag-drop.ts +801 -0
  23. package/src/dnd/index.ts +133 -0
  24. package/src/dnd/manager.ts +639 -0
  25. package/src/dnd/strings.ts +1279 -0
  26. package/src/dnd/targets.ts +726 -0
  27. package/src/dnd/types.ts +212 -0
  28. package/src/dom.ts +3 -6
  29. package/src/drag-and-drop.tsx +669 -0
  30. package/src/dropzone.tsx +208 -0
  31. package/src/file-trigger.tsx +103 -0
  32. package/src/form.tsx +18 -18
  33. package/src/gridlist.tsx +912 -121
  34. package/src/group.tsx +146 -0
  35. package/src/index.ts +402 -0
  36. package/src/interactions/focus-events.ts +13 -5
  37. package/src/interactions/keyboard.ts +195 -2
  38. package/src/interactions/modality.ts +18 -6
  39. package/src/interactions/open-link.ts +46 -13
  40. package/src/interactions/press.ts +35 -18
  41. package/src/label.ts +18 -6
  42. package/src/link.tsx +146 -50
  43. package/src/listbox.tsx +615 -89
  44. package/src/live.ts +4 -0
  45. package/src/menu.tsx +182 -89
  46. package/src/menubar.tsx +21 -17
  47. package/src/navigation-tree.tsx +357 -0
  48. package/src/numberfield.tsx +164 -60
  49. package/src/overlay-arrow.tsx +157 -0
  50. package/src/overlays.ts +364 -62
  51. package/src/platform.ts +2 -1
  52. package/src/preview-trigger.tsx +582 -0
  53. package/src/progress-bar-context.ts +15 -0
  54. package/src/questionnaire.tsx +109 -104
  55. package/src/radio.tsx +101 -27
  56. package/src/select.tsx +225 -145
  57. package/src/selection-indicator.tsx +74 -0
  58. package/src/selection.ts +73 -16
  59. package/src/shared-element-transition.tsx +316 -0
  60. package/src/sheet.tsx +1461 -0
  61. package/src/slider.tsx +139 -44
  62. package/src/switch.tsx +47 -21
  63. package/src/table.tsx +0 -0
  64. package/src/tabs.tsx +198 -89
  65. package/src/tag.tsx +217 -32
  66. package/src/textarea.tsx +186 -0
  67. package/src/textfield.tsx +103 -37
  68. package/src/toast-components.tsx +589 -0
  69. package/src/toggle-button-group.tsx +175 -0
  70. package/src/toggle-input.tsx +38 -0
  71. package/src/toggle.ts +68 -5
  72. package/src/tokenfield.tsx +1673 -0
  73. package/src/toolbar.tsx +15 -10
  74. package/src/tooltip.tsx +46 -29
  75. package/src/tree.tsx +2075 -0
  76. package/src/utils.ts +30 -1
  77. package/src/validation.ts +79 -22
  78. package/src/virtualizer.tsx +186 -23
@@ -12,6 +12,8 @@
12
12
  * would break `preventDefault`, `currentTarget` and every other live property.
13
13
  */
14
14
 
15
+ import { contains, targetElement } from "../dom.ts";
16
+ import { isMac } from "../platform.ts";
15
17
  import { access, type DOMProps, type MaybeAccessor } from "../utils.ts";
16
18
 
17
19
  /** A native event with the opt-out from this module's default. */
@@ -65,10 +67,174 @@ export function createEventHandler<E extends Event>(
65
67
  };
66
68
  }
67
69
 
70
+ // ---------------------------------------------------------------------------
71
+ // Shortcuts
72
+ // ---------------------------------------------------------------------------
73
+
74
+ /**
75
+ * What a shortcut does. Returning nothing or `true` prevents the default and
76
+ * stops the event; `false` lets it through untouched; an object decides each.
77
+ */
78
+ export type KeyboardShortcutAction = (
79
+ event: BaseEvent<KeyboardEvent>,
80
+ ) =>
81
+ | void
82
+ | boolean
83
+ | Partial<{ shouldContinuePropagation: boolean; shouldPreventDefault: boolean }>;
84
+
85
+ /** Shortcut strings (`"Mod+s"`, `"Control+Shift+a"`, `"Escape"`) to what they do. */
86
+ export type KeyboardShortcutBindings = Record<string, KeyboardShortcutAction>;
87
+
88
+ export interface ParsedKeyboardShortcut {
89
+ shift: boolean;
90
+ alt: boolean;
91
+ ctrl: boolean;
92
+ meta: boolean;
93
+ /** Command on Apple platforms, Control everywhere else. */
94
+ mod: boolean;
95
+ key: string;
96
+ }
97
+
98
+ const MODIFIER_ORDER = ["Alt", "Control", "Meta", "Shift"] as const;
99
+
100
+ const KEY_ALIASES: Record<string, string> = {
101
+ space: " ",
102
+ esc: "escape",
103
+ del: "delete",
104
+ ins: "insert",
105
+ left: "arrowleft",
106
+ right: "arrowright",
107
+ up: "arrowup",
108
+ down: "arrowdown",
109
+ };
110
+
111
+ /** `"Mod+Shift+z"` into its parts. Modifiers ignore case and order. */
112
+ export function parseKeyboardShortcut(spec: string): ParsedKeyboardShortcut {
113
+ const parsed: ParsedKeyboardShortcut = {
114
+ shift: false,
115
+ alt: false,
116
+ ctrl: false,
117
+ meta: false,
118
+ mod: false,
119
+ key: "",
120
+ };
121
+ for (const part of spec.split("+")) {
122
+ const lower = part.toLowerCase();
123
+ if (lower === "shift") parsed.shift = true;
124
+ else if (lower === "alt") parsed.alt = true;
125
+ else if (lower === "control") parsed.ctrl = true;
126
+ else if (lower === "meta") parsed.meta = true;
127
+ else if (lower === "mod") parsed.mod = true;
128
+ else parsed.key = part;
129
+ }
130
+ if (parsed.key === "") {
131
+ throw new Error(
132
+ `Invalid keyboard shortcut: "${spec}". Must include exactly one non-modifier key (e.g. "a", "Enter", "ArrowDown"). Combine any of Shift, Alt, Control, Meta, and Mod.`,
133
+ );
134
+ }
135
+ return parsed;
136
+ }
137
+
138
+ function joinShortcut(modifiers: Set<string>, key: string): string {
139
+ const ordered = MODIFIER_ORDER.filter((name) => modifiers.has(name));
140
+ return ordered.length > 0 ? `${ordered.join("+")}+${key}` : key;
141
+ }
142
+
143
+ /** One spelling per shortcut, so `Shift+Mod+a` and `Mod+Shift+a` are the same key. */
144
+ export function canonicalKeyboardShortcut(parsed: ParsedKeyboardShortcut): string {
145
+ const modifiers = new Set<string>();
146
+ if (parsed.alt) modifiers.add("Alt");
147
+ if (parsed.shift) modifiers.add("Shift");
148
+ if (parsed.ctrl) modifiers.add("Control");
149
+ if (parsed.meta) modifiers.add("Meta");
150
+ if (parsed.mod) modifiers.add(isMac() ? "Meta" : "Control");
151
+ const key = parsed.key.toLowerCase();
152
+ return joinShortcut(modifiers, KEY_ALIASES[key] ?? key);
153
+ }
154
+
155
+ /** The canonical shortcut a keydown spells. */
156
+ export function keyboardEventToCanonicalShortcut(event: KeyboardEvent): string {
157
+ const modifiers = new Set<string>();
158
+ if (event.altKey) modifiers.add("Alt");
159
+ if (event.ctrlKey) modifiers.add("Control");
160
+ if (event.metaKey) modifiers.add("Meta");
161
+ if (event.shiftKey) modifiers.add("Shift");
162
+ return joinShortcut(modifiers, event.key.toLowerCase());
163
+ }
164
+
165
+ /**
166
+ * A keydown handler that runs the binding whose modifiers and key match the
167
+ * event exactly. Two bindings that spell the same shortcut: the later wins.
168
+ *
169
+ * ```ts
170
+ * const onKeyDown = createKeyboardShortcutHandler({ "Mod+s": () => save() });
171
+ * ```
172
+ */
173
+ export function createKeyboardShortcutHandler(
174
+ bindings: KeyboardShortcutBindings,
175
+ ): (event: BaseEvent<KeyboardEvent>) => void {
176
+ const map = new Map<string, KeyboardShortcutAction>();
177
+ for (const [spec, action] of Object.entries(bindings)) {
178
+ map.set(canonicalKeyboardShortcut(parseKeyboardShortcut(spec)), action);
179
+ }
180
+
181
+ return (event) => {
182
+ const action = map.get(keyboardEventToCanonicalShortcut(event));
183
+ if (action === undefined) {
184
+ event.continuePropagation();
185
+ return;
186
+ }
187
+ const result = action(event);
188
+ const outcome =
189
+ result === undefined
190
+ ? { shouldContinuePropagation: false, shouldPreventDefault: true }
191
+ : typeof result === "boolean"
192
+ ? { shouldContinuePropagation: !result, shouldPreventDefault: result }
193
+ : result;
194
+ if (outcome.shouldPreventDefault === true) event.preventDefault();
195
+ if (outcome.shouldContinuePropagation === true) event.continuePropagation();
196
+ };
197
+ }
198
+
199
+ /**
200
+ * Call a handler that does not decide propagation. It still receives a
201
+ * `continuePropagation`, the enclosing handler's when there is one.
202
+ */
203
+ function callUndecided(
204
+ handler: ((event: BaseEvent<KeyboardEvent>) => void) | undefined,
205
+ event: KeyboardEvent,
206
+ ): void {
207
+ if (handler === undefined) return;
208
+ const base = event as Partial<BaseEvent<KeyboardEvent>>;
209
+ if (typeof base.continuePropagation === "function") {
210
+ handler(event as BaseEvent<KeyboardEvent>);
211
+ return;
212
+ }
213
+ Object.defineProperty(event, "continuePropagation", {
214
+ configurable: true,
215
+ writable: true,
216
+ value: (): void => {},
217
+ });
218
+ try {
219
+ handler(event as BaseEvent<KeyboardEvent>);
220
+ } finally {
221
+ delete base.continuePropagation;
222
+ }
223
+ }
224
+
68
225
  export interface KeyboardOptions {
69
226
  isDisabled?: MaybeAccessor<boolean | undefined>;
70
227
  onKeyDown?: (event: BaseEvent<KeyboardEvent>) => void;
71
228
  onKeyUp?: (event: BaseEvent<KeyboardEvent>) => void;
229
+ /**
230
+ * Keyboard shortcuts on keydown. With these, `onKeyDown` and `onKeyUp` run
231
+ * as they are and only the shortcuts decide whether the event goes on.
232
+ */
233
+ shortcuts?: KeyboardShortcutBindings;
234
+ /** Run shortcuts for a held key's repeats too. */
235
+ allowRepeats?: MaybeAccessor<boolean | undefined>;
236
+ /** Run shortcuts while an input method is composing. */
237
+ allowComposing?: MaybeAccessor<boolean | undefined>;
72
238
  }
73
239
 
74
240
  export interface KeyboardResult {
@@ -88,9 +254,36 @@ export interface KeyboardResult {
88
254
  * ```
89
255
  */
90
256
  export function keyboard(options: KeyboardOptions = {}): KeyboardResult {
91
- const down = createEventHandler(options.onKeyDown);
92
- const up = createEventHandler(options.onKeyUp);
93
257
  const enabled = (): boolean => access(options.isDisabled) !== true;
258
+ let down: ((event: KeyboardEvent) => void) | undefined;
259
+ let up: ((event: KeyboardEvent) => void) | undefined;
260
+
261
+ if (options.shortcuts === undefined) {
262
+ down = createEventHandler(options.onKeyDown);
263
+ up = createEventHandler(options.onKeyUp);
264
+ } else {
265
+ const shortcut = createKeyboardShortcutHandler(options.shortcuts);
266
+ const onShortcut = createEventHandler<KeyboardEvent>((event) => {
267
+ // A key from a portalled subtree is not this element's.
268
+ if (!contains(event.currentTarget as Element | null, targetElement(event))) {
269
+ event.continuePropagation();
270
+ return;
271
+ }
272
+ if (
273
+ (event.repeat && access(options.allowRepeats) !== true) ||
274
+ (event.isComposing && access(options.allowComposing) !== true)
275
+ ) {
276
+ event.continuePropagation();
277
+ return;
278
+ }
279
+ shortcut(event);
280
+ });
281
+ down = (event) => {
282
+ callUndecided(options.onKeyDown, event);
283
+ onShortcut?.(event);
284
+ };
285
+ up = (event) => callUndecided(options.onKeyUp, event);
286
+ }
94
287
 
95
288
  return {
96
289
  keyboardProps: {
@@ -43,7 +43,8 @@ let hasBlurredWindowRecently = false;
43
43
  // user typing, and a ring that appears while typing is noise.
44
44
  const TEXT_INPUT_FOCUS_KEYS = new Set(["Tab", "Escape"]);
45
45
 
46
- const NON_TEXT_INPUT_TYPES = new Set([
46
+ /** The `<input>` types that are a control rather than a place to type. */
47
+ export const NON_TEXT_INPUT_TYPES: ReadonlySet<string> = new Set([
47
48
  "checkbox",
48
49
  "radio",
49
50
  "range",
@@ -55,6 +56,21 @@ const NON_TEXT_INPUT_TYPES = new Set([
55
56
  "reset",
56
57
  ]);
57
58
 
59
+ /**
60
+ * Whether the element takes typed text: a text-like input, a textarea, or
61
+ * editable content. What brings up an on-screen keyboard, and where a key
62
+ * press is typing rather than navigation.
63
+ */
64
+ export function isTextEntry(element: Element | null): boolean {
65
+ if (element === null) return false;
66
+ const view = ownerWindow(element);
67
+ return (
68
+ (element instanceof view.HTMLInputElement && !NON_TEXT_INPUT_TYPES.has(element.type)) ||
69
+ element instanceof view.HTMLTextAreaElement ||
70
+ (element instanceof view.HTMLElement && element.isContentEditable)
71
+ );
72
+ }
73
+
58
74
  function notify(next: Modality, event: ModalityEvent): void {
59
75
  for (const handler of handlers) handler(next, event);
60
76
  }
@@ -363,11 +379,7 @@ function shouldReportKeyboardFocus(
363
379
  // The caller passes `isTextInput` for the case the DOM cannot answer: a key
364
380
  // pressed on a button that is about to move focus INTO a field, where the
365
381
  // active element at this moment is still the button.
366
- const intoText =
367
- isTextInput ||
368
- (active instanceof view.HTMLInputElement && !NON_TEXT_INPUT_TYPES.has(active.type)) ||
369
- active instanceof view.HTMLTextAreaElement ||
370
- (active instanceof view.HTMLElement && active.isContentEditable);
382
+ const intoText = isTextInput || isTextEntry(active);
371
383
 
372
384
  return !(
373
385
  intoText &&
@@ -24,10 +24,30 @@ export interface LinkModifiers {
24
24
  shiftKey?: boolean;
25
25
  }
26
26
 
27
+ /**
28
+ * Augment with `routerOptions` to type what a link hands its router:
29
+ *
30
+ * ```ts
31
+ * declare module "@barqjs/aria" {
32
+ * interface RouterConfig {
33
+ * routerOptions: { replace?: boolean };
34
+ * }
35
+ * }
36
+ * ```
37
+ */
38
+ export interface RouterConfig {}
39
+
40
+ export type RouterOptions = RouterConfig extends { routerOptions: infer O } ? O : unknown;
41
+
27
42
  export interface Router {
28
43
  /** Whether navigation is the browser's, rather than a client router's. */
29
44
  isNative: boolean;
30
- open: (target: Element, modifiers: LinkModifiers, href: string) => void;
45
+ open: (
46
+ target: Element,
47
+ modifiers: LinkModifiers,
48
+ href: string,
49
+ routerOptions?: RouterOptions,
50
+ ) => void;
31
51
  href: (href: string) => string;
32
52
  }
33
53
 
@@ -149,17 +169,25 @@ function withSyntheticLink(target: Element, open: (link: HTMLAnchorElement) => v
149
169
  }
150
170
  }
151
171
 
152
- /** The `data-*` attributes that make a non-anchor element behave as a link. */
153
- export function syntheticLinkProps(props: {
154
- href?: string;
155
- target?: string;
156
- rel?: string;
157
- download?: boolean | string;
158
- ping?: string;
159
- referrerPolicy?: string;
160
- }): Record<string, unknown> {
172
+ /**
173
+ * The `data-*` attributes that make a non-anchor element behave as a link.
174
+ *
175
+ * `active` is the router the href is rendered for, read once by a caller that
176
+ * computes these again later, outside the scope that provides it.
177
+ */
178
+ export function syntheticLinkProps(
179
+ props: {
180
+ href?: string;
181
+ target?: string;
182
+ rel?: string;
183
+ download?: boolean | string;
184
+ ping?: string;
185
+ referrerPolicy?: string;
186
+ },
187
+ active: Router = router(),
188
+ ): Record<string, unknown> {
161
189
  return {
162
- "data-href": props.href === undefined ? undefined : router().href(props.href),
190
+ "data-href": props.href === undefined ? undefined : active.href(props.href),
163
191
  "data-target": props.target,
164
192
  "data-rel": props.rel,
165
193
  "data-download": props.download,
@@ -175,7 +203,12 @@ export function syntheticLinkProps(props: {
175
203
  * `active` is the {@link router} the link read while it was being set up: a
176
204
  * click has no owner to find one from.
177
205
  */
178
- export function handleLinkClick(event: MouseEvent, href: string | undefined, active: Router): void {
206
+ export function handleLinkClick(
207
+ event: MouseEvent,
208
+ href: string | undefined,
209
+ active: Router,
210
+ routerOptions?: RouterOptions,
211
+ ): void {
179
212
  const target = event.currentTarget;
180
213
  if (
181
214
  active.isNative ||
@@ -189,5 +222,5 @@ export function handleLinkClick(event: MouseEvent, href: string | undefined, act
189
222
  }
190
223
 
191
224
  event.preventDefault();
192
- active.open(target, event, href);
225
+ active.open(target, event, href, routerOptions);
193
226
  }
@@ -37,7 +37,12 @@ import { isMac } from "../platform.ts";
37
37
  import { access, type DOMProps, type MaybeAccessor } from "../utils.ts";
38
38
  import { isOpeningLink } from "./flags.ts";
39
39
  import { globalListeners } from "./listeners.ts";
40
- import { isVirtualClick, isVirtualPointerEvent, type PointerType } from "./modality.ts";
40
+ import {
41
+ isVirtualClick,
42
+ isVirtualPointerEvent,
43
+ NON_TEXT_INPUT_TYPES,
44
+ type PointerType,
45
+ } from "./modality.ts";
41
46
  import { openLink } from "./open-link.ts";
42
47
  import { preventFocus } from "./prevent-focus.ts";
43
48
  import { disableTextSelection, restoreTextSelection } from "./text-selection.ts";
@@ -181,24 +186,13 @@ interface PressState {
181
186
  pointerType: PointerType | null;
182
187
  metaKeyEvents: Map<string, KeyboardEvent> | undefined;
183
188
  disposables: (() => void)[];
189
+ defaultKeyboardClickEvent: KeyboardEvent | null;
184
190
  }
185
191
 
186
192
  const LINK_CLICKED = Symbol.for("barq.aria.linkClicked");
187
193
  const PRESSABLE_ATTRIBUTE = "data-barq-pressable";
188
194
  const STYLE_ID = "barq-aria-pressable-style";
189
195
 
190
- const NON_TEXT_INPUT_TYPES = new Set([
191
- "checkbox",
192
- "radio",
193
- "range",
194
- "color",
195
- "file",
196
- "image",
197
- "button",
198
- "submit",
199
- "reset",
200
- ]);
201
-
202
196
  function isAnchorLink(target: Element): target is HTMLAnchorElement {
203
197
  return target.tagName === "A" && target.hasAttribute("href");
204
198
  }
@@ -239,9 +233,13 @@ function shouldPreventDefaultUp(target: Element): boolean {
239
233
  return true;
240
234
  }
241
235
 
242
- function shouldPreventDefaultKeyboard(target: Element, key: string): boolean {
236
+ function shouldPreventDefaultKeyboard(
237
+ target: Element,
238
+ event: Pick<KeyboardEvent, "key" | "ctrlKey">,
239
+ ): boolean {
240
+ const { key } = event;
243
241
  // Control-Enter opens the context menu on macOS.
244
- if (isMac() && key === "Enter") return false;
242
+ if (isMac() && key === "Enter" && event.ctrlKey) return false;
245
243
 
246
244
  if (target instanceof HTMLInputElement) {
247
245
  // Enter on a checkbox or radio submits the form; it must not also toggle.
@@ -353,6 +351,7 @@ export function press(options: PressOptions): PressResult {
353
351
  pointerType: null,
354
352
  metaKeyEvents: undefined,
355
353
  disposables: [],
354
+ defaultKeyboardClickEvent: null,
356
355
  };
357
356
 
358
357
  const isDisabled = (): boolean => access(options.isDisabled) === true;
@@ -462,9 +461,13 @@ export function press(options: PressOptions): PressResult {
462
461
  const onKeyUp = (event: KeyboardEvent): void => {
463
462
  if (state.isPressed && state.target !== null && isActivationKey(event, state.target)) {
464
463
  const target = targetElement(event);
465
- if (shouldPreventDefaultKeyboard(target ?? state.target, event.key)) event.preventDefault();
464
+ if (shouldPreventDefaultKeyboard(target ?? state.target, event)) event.preventDefault();
466
465
 
467
466
  const wasPressed = contains(state.target, target);
467
+ // Space activates on keyup, and the browser follows with a click of its
468
+ // own. This listener captures, so a later handler may still prevent the
469
+ // default: keep the event and read `defaultPrevented` at the click.
470
+ state.defaultKeyboardClickEvent = event.key !== "Enter" && wasPressed ? event : null;
468
471
  triggerPressEnd(retarget(state.target, event), "keyboard", wasPressed);
469
472
  if (wasPressed) triggerSyntheticClick(event, state.target);
470
473
  listeners.removeAll();
@@ -508,7 +511,10 @@ export function press(options: PressOptions): PressResult {
508
511
  return;
509
512
  }
510
513
 
511
- if (shouldPreventDefaultKeyboard(targetElement(event) ?? currentTarget, event.key)) {
514
+ // Enter activates on keydown, and the browser follows with a click.
515
+ state.defaultKeyboardClickEvent = event.key === "Enter" ? event : null;
516
+
517
+ if (shouldPreventDefaultKeyboard(targetElement(event) ?? currentTarget, event)) {
512
518
  event.preventDefault();
513
519
  }
514
520
 
@@ -558,7 +564,17 @@ export function press(options: PressOptions): PressResult {
558
564
  let stopPropagation = true;
559
565
  if (isDisabled()) event.preventDefault();
560
566
 
561
- if (!state.isPressed && (state.pointerType === "virtual" || isVirtualClick(event))) {
567
+ // The click a browser fires as a key's default action looks like a virtual
568
+ // click. It happens only when nothing prevented the key's default, and
569
+ // unlike `element.click()` it is trusted.
570
+ const isDefaultKeyboardClick =
571
+ event.isTrusted && state.defaultKeyboardClickEvent?.defaultPrevented === false;
572
+
573
+ if (
574
+ !isDefaultKeyboardClick &&
575
+ !state.isPressed &&
576
+ (state.pointerType === "virtual" || isVirtualClick(event))
577
+ ) {
562
578
  // A screen reader, or `element.click()`. There was no pointer sequence,
563
579
  // so the whole press runs here.
564
580
  const start = triggerPressStart(event, "virtual");
@@ -578,6 +594,7 @@ export function press(options: PressOptions): PressResult {
578
594
  cancel(event);
579
595
  }
580
596
 
597
+ state.defaultKeyboardClickEvent = null;
581
598
  if (stopPropagation) event.stopPropagation();
582
599
  };
583
600
 
package/src/label.ts CHANGED
@@ -86,6 +86,12 @@ export interface FieldOptions extends LabelOptions {
86
86
  export interface FieldResult extends LabelResult {
87
87
  descriptionProps: DOMProps;
88
88
  errorMessageProps: DOMProps;
89
+ /**
90
+ * The description and the error, when they are rendered, without the
91
+ * caller's own `aria-describedby`: for the controls inside a group, which a
92
+ * screen reader reaches one by one without passing the group.
93
+ */
94
+ descriptionIds: Accessor<string | undefined>;
89
95
  }
90
96
 
91
97
  /**
@@ -105,22 +111,28 @@ export function field(options: FieldOptions): FieldResult {
105
111
  return resolved !== undefined && resolved !== null && resolved !== false && resolved !== "";
106
112
  };
107
113
 
108
- const describedBy = (): string | undefined => {
109
- const parts = [
114
+ const ids = (...parts: (string | undefined)[]): string | undefined => {
115
+ const given = parts.filter((part): part is string => part !== undefined);
116
+ return given.length === 0 ? undefined : given.join(" ");
117
+ };
118
+
119
+ const descriptionIds = (): string | undefined =>
120
+ ids(
110
121
  present(options.description) ? descriptionId() : undefined,
111
122
  present(options.errorMessage) && access(options.isInvalid) === true
112
123
  ? errorMessageId()
113
124
  : undefined,
114
- access(options["aria-describedby"]),
115
- ].filter((part): part is string => part !== undefined);
116
- return parts.length === 0 ? undefined : parts.join(" ");
117
- };
125
+ );
126
+
127
+ const describedBy = (): string | undefined =>
128
+ ids(descriptionIds(), access(options["aria-describedby"]));
118
129
 
119
130
  return {
120
131
  labelProps,
121
132
  fieldProps: mergeProps(fieldProps, { "aria-describedby": describedBy }),
122
133
  descriptionProps: { id: descriptionId },
123
134
  errorMessageProps: { id: errorMessageId },
135
+ descriptionIds,
124
136
  };
125
137
  }
126
138