@mistriwork/ui 1.0.0-rc.47 → 1.0.0-rc.49

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/Carousel.d.ts +2 -1
  3. package/dist/Carousel.js +9 -8
  4. package/dist/Choices.d.ts +5 -4
  5. package/dist/Choices.js +18 -16
  6. package/dist/DateField.d.ts +8 -3
  7. package/dist/DateField.js +17 -14
  8. package/dist/Drawer.d.ts +2 -1
  9. package/dist/Drawer.js +4 -3
  10. package/dist/DropMenu.d.ts +2 -1
  11. package/dist/DropMenu.js +3 -2
  12. package/dist/Dropdown.d.ts +8 -3
  13. package/dist/Dropdown.js +10 -6
  14. package/dist/FileField.d.ts +3 -2
  15. package/dist/FileField.js +4 -2
  16. package/dist/Pagination.d.ts +2 -1
  17. package/dist/Pagination.js +3 -2
  18. package/dist/Popover.d.ts +2 -1
  19. package/dist/Popover.js +3 -2
  20. package/dist/Resizable.d.ts +2 -1
  21. package/dist/Resizable.js +10 -9
  22. package/dist/Select.d.ts +3 -3
  23. package/dist/Select.js +2 -2
  24. package/dist/SensitiveField.d.ts +2 -1
  25. package/dist/SensitiveField.js +6 -5
  26. package/dist/Slider.d.ts +2 -1
  27. package/dist/Slider.js +3 -2
  28. package/dist/Switch.d.ts +2 -2
  29. package/dist/Switch.js +4 -3
  30. package/dist/Tabs.d.ts +5 -2
  31. package/dist/Tabs.js +3 -2
  32. package/dist/TextArea.d.ts +24 -0
  33. package/dist/TextArea.js +7 -0
  34. package/dist/TextField.d.ts +3 -2
  35. package/dist/TextField.js +6 -5
  36. package/dist/Tooltip.d.ts +2 -1
  37. package/dist/Tooltip.js +3 -3
  38. package/dist/Typeahead.d.ts +5 -2
  39. package/dist/Typeahead.js +31 -10
  40. package/dist/UiKit.d.ts +8 -2
  41. package/dist/changeDetails.d.ts +28 -0
  42. package/dist/changeDetails.js +54 -0
  43. package/dist/conformance.d.ts +1 -1
  44. package/dist/conformance.js +83 -5
  45. package/dist/conformancePatterns.d.ts +27 -0
  46. package/dist/conformancePatterns.js +421 -0
  47. package/dist/forms.css +3 -0
  48. package/dist/index.d.ts +5 -3
  49. package/dist/index.js +3 -0
  50. package/dist/internal/uiKitContext.d.ts +4 -1
  51. package/dist/internal/uiKitContext.js +49 -3
  52. package/package.json +2 -1
@@ -0,0 +1,421 @@
1
+ /**
2
+ * `checkPatterns(root)`: the WAI-ARIA Authoring Practices patterns, read off a live page. Every listbox, menu, tab
3
+ * list, tree, dialog, combobox, radio group and switch under `root` is held to what its pattern promises a reader —
4
+ *
5
+ * - its role and an accessible name, and a name on each of its items;
6
+ * - the roles it must own (a listbox its options, a menu its menu items, a tab list its tabs, a tree its tree items,
7
+ * a radio group its radios), and nothing it may not;
8
+ * - one Tab stop for a composite widget, kept by a roving tabindex or by `aria-activedescendant` on a focusable
9
+ * holder — none inside a popup a combobox drives, since the focus stays in the box;
10
+ * - the keys the pattern names: the arrows, Home and End move the current item; Escape closes a popup;
11
+ * - the focus never falls to the body or into inert content, after any of those keys or in an open modal dialog.
12
+ *
13
+ * It answers with the problems it found, each naming the widget, so one run says everything wrong with a page; an
14
+ * empty list is a pass. The keys are pressed the way the conformance suite presses them — dispatched by hand — and a
15
+ * key that changes what is chosen (a tab list's arrows) is walked back afterwards; Escape on an open popup is left
16
+ * closed. A dialog's Escape belongs to whoever opened it, so dialogs are read, not pressed.
17
+ *
18
+ * It is self-contained on purpose — no imports, nothing read from this module's scope — so a browser test can hand the
19
+ * function itself to Playwright's `page.evaluate` and read a real App's page by the rules the unit tests use.
20
+ */
21
+ export async function checkPatterns(root, options) {
22
+ const doc = root ? (root.ownerDocument ?? root) : document;
23
+ const scope = root ?? doc;
24
+ const opts = options ?? {};
25
+ const problems = [];
26
+ /* ---- Reading the page ---- */
27
+ const roleOf = (el) => {
28
+ const explicit = (el.getAttribute('role') ?? '').trim().split(/\s+/)[0];
29
+ if (explicit)
30
+ return explicit;
31
+ if (el.tagName === 'DIALOG')
32
+ return 'dialog';
33
+ if (el.tagName === 'SELECT')
34
+ return el.multiple || el.size > 1 ? 'listbox' : 'combobox';
35
+ if (el.tagName === 'INPUT') {
36
+ const kind = (el.getAttribute('type') ?? 'text').toLowerCase();
37
+ if (kind === 'radio')
38
+ return 'radio';
39
+ if (kind !== 'hidden' && el.hasAttribute('list') && /^(text|search|email|tel|url)$/.test(kind))
40
+ return 'combobox';
41
+ }
42
+ return '';
43
+ };
44
+ const native = (el) => el.tagName === 'SELECT' || el.tagName === 'INPUT';
45
+ /* What a bare element is to a reader when it names no role: only the few that matter for what a composite may own, so a
46
+ `<button>` set among a listbox's options is seen as the button it is. */
47
+ const implicitRole = (el) => {
48
+ switch (el.tagName) {
49
+ case 'BUTTON':
50
+ return 'button';
51
+ case 'A':
52
+ return el.hasAttribute('href') ? 'link' : '';
53
+ case 'LI':
54
+ return 'listitem';
55
+ case 'TEXTAREA':
56
+ return 'textbox';
57
+ case 'IMG':
58
+ return el.getAttribute('alt') === '' ? '' : 'img';
59
+ case 'INPUT': {
60
+ const kind = (el.getAttribute('type') ?? 'text').toLowerCase();
61
+ if (kind === 'hidden')
62
+ return '';
63
+ if (kind === 'checkbox' || kind === 'radio')
64
+ return kind;
65
+ if (kind === 'button' || kind === 'submit' || kind === 'reset' || kind === 'image')
66
+ return 'button';
67
+ return kind === 'range' ? 'slider' : 'textbox';
68
+ }
69
+ default:
70
+ return /^H[1-6]$/.test(el.tagName) ? 'heading' : '';
71
+ }
72
+ };
73
+ const hidden = (el) => {
74
+ const view = doc.defaultView;
75
+ for (let at = el; at; at = at.parentElement) {
76
+ if (at.hidden || at.getAttribute('aria-hidden') === 'true' || at.hasAttribute('inert'))
77
+ return true;
78
+ if (at.tagName === 'DIALOG' && !at.hasAttribute('open'))
79
+ return true;
80
+ const style = view?.getComputedStyle(at);
81
+ if (style && (style.display === 'none' || style.visibility === 'hidden'))
82
+ return true;
83
+ }
84
+ return false;
85
+ };
86
+ const words = (el) => (el?.textContent ?? '').replace(/\s+/g, ' ').trim();
87
+ /* The words an element is named by its content: text, a descendant's own aria-label, and nothing under aria-hidden or
88
+ a hidden element, so an item that is only an icon has no name. */
89
+ const contentWords = (el) => {
90
+ const parts = [];
91
+ const walk = (node) => {
92
+ for (const child of node.childNodes) {
93
+ if (child.nodeType === 3)
94
+ parts.push(child.textContent ?? '');
95
+ else if (child.nodeType === 1) {
96
+ const inner = child;
97
+ if (inner.getAttribute('aria-hidden') === 'true' || inner.hidden)
98
+ continue;
99
+ const own = inner.getAttribute('aria-label')?.trim();
100
+ if (own)
101
+ parts.push(` ${own} `);
102
+ else
103
+ walk(inner);
104
+ }
105
+ }
106
+ };
107
+ walk(el);
108
+ return parts.join('').replace(/\s+/g, ' ').trim();
109
+ };
110
+ const byIds = (ids) => ids
111
+ .split(/\s+/)
112
+ .map((id) => words(doc.getElementById(id)))
113
+ .join(' ')
114
+ .trim();
115
+ /* The name a reader hears: aria-labelledby, aria-label, a label, a title — and the words inside for a role named by
116
+ its content (an option, a tab, a switch). */
117
+ const nameOf = (el, fromContent) => {
118
+ const labelledBy = el.getAttribute('aria-labelledby');
119
+ if (labelledBy && byIds(labelledBy))
120
+ return byIds(labelledBy);
121
+ const label = el.getAttribute('aria-label')?.trim();
122
+ if (label)
123
+ return label;
124
+ const labels = el.labels;
125
+ if (labels && labels.length)
126
+ return [...labels].map(words).join(' ').trim();
127
+ const title = el.getAttribute('title')?.trim();
128
+ if (fromContent && contentWords(el))
129
+ return contentWords(el);
130
+ if (title)
131
+ return title;
132
+ return el.tagName === 'INPUT' ? (el.placeholder ?? '').trim() : '';
133
+ };
134
+ const disabled = (el) => el.disabled === true || el.getAttribute('aria-disabled') === 'true';
135
+ const tabbable = (el) => el.tabIndex >= 0 && !el.disabled && !hidden(el);
136
+ const said = (el, role) => {
137
+ const name = nameOf(el, false) || nameOf(el, true).slice(0, 40);
138
+ return name ? `${role} "${name}"` : `a ${role}`;
139
+ };
140
+ /* What a container owns: the role-bearing elements under it with nothing but groups between. */
141
+ const THROUGH = new Set(['', 'group', 'presentation', 'none', 'generic']);
142
+ const effectiveRole = (el) => roleOf(el) || implicitRole(el);
143
+ const owned = (container) => [...container.querySelectorAll('*')].filter((el) => {
144
+ if (!effectiveRole(el) || hidden(el))
145
+ return false;
146
+ for (let at = el.parentElement; at && at !== container; at = at.parentElement)
147
+ if (!THROUGH.has(effectiveRole(at)))
148
+ return false;
149
+ return true;
150
+ });
151
+ const OWNS = {
152
+ listbox: { required: ['option'], allowed: ['option', 'group', 'presentation', 'none'] },
153
+ menu: {
154
+ required: ['menuitem', 'menuitemcheckbox', 'menuitemradio'],
155
+ allowed: ['menuitem', 'menuitemcheckbox', 'menuitemradio', 'group', 'separator', 'presentation', 'none'],
156
+ },
157
+ tablist: { required: ['tab'], allowed: ['tab', 'presentation', 'none'] },
158
+ tree: { required: ['treeitem'], allowed: ['treeitem', 'group', 'presentation', 'none'] },
159
+ radiogroup: { required: ['radio'], allowed: ['radio', 'presentation', 'none', 'group'] },
160
+ };
161
+ const ITEM = { listbox: 'option', menu: 'menuitem', tablist: 'tab', tree: 'treeitem', radiogroup: 'radio' };
162
+ const items = (container, role) => [...container.querySelectorAll('*')].filter((el) => (roleOf(el) === ITEM[role] || (role === 'menu' && roleOf(el).startsWith('menuitem'))) && !hidden(el));
163
+ /* The element a combobox or a container points at as its current item, or the focused item. */
164
+ const current = (holder, container) => {
165
+ const id = holder.getAttribute('aria-activedescendant');
166
+ if (id)
167
+ return doc.getElementById(id);
168
+ const focused = doc.activeElement;
169
+ return focused && container.contains(focused) && focused !== container ? focused : null;
170
+ };
171
+ /* ---- Pressing keys ---- */
172
+ const wait = (ms) => new Promise((done) => setTimeout(done, ms));
173
+ const step = async (run) => {
174
+ const body = async () => {
175
+ run();
176
+ // A popup moves the focus a frame or two after the key.
177
+ await wait(30);
178
+ };
179
+ if (opts.act)
180
+ await opts.act(body);
181
+ else
182
+ await body();
183
+ };
184
+ const press = (target, key) => step(() => {
185
+ const init = { key, bubbles: true, cancelable: true, composed: true };
186
+ target.dispatchEvent(new KeyboardEvent('keydown', init));
187
+ target.dispatchEvent(new KeyboardEvent('keyup', init));
188
+ });
189
+ const focus = (el) => step(() => el.focus());
190
+ const focusHolds = (who, after) => {
191
+ const at = doc.activeElement;
192
+ if (!at || at === doc.body || at === doc.documentElement)
193
+ problems.push(`${who}: after ${after} the focus fell to the page`);
194
+ else if (at.closest('[inert]'))
195
+ problems.push(`${who}: after ${after} the focus is inside inert content`);
196
+ };
197
+ /* ---- The widgets ---- */
198
+ const ROLES = new Set(['listbox', 'menu', 'tablist', 'tree', 'dialog', 'alertdialog', 'combobox', 'radiogroup', 'switch']);
199
+ const start = scope instanceof Element ? [scope] : [];
200
+ const widgets = [...start, ...scope.querySelectorAll('*')].filter((el) => ROLES.has(roleOf(el)) && !hidden(el));
201
+ /* A popup a combobox drives keeps no Tab stop and is pressed through its box. */
202
+ const driven = new Map();
203
+ for (const box of widgets.filter((el) => roleOf(el) === 'combobox')) {
204
+ for (const id of `${box.getAttribute('aria-controls') ?? ''} ${box.getAttribute('aria-owns') ?? ''}`.split(/\s+/)) {
205
+ const popup = id ? doc.getElementById(id) : null;
206
+ if (popup)
207
+ driven.set(popup, box);
208
+ }
209
+ }
210
+ /* A popup is something an expanded trigger names, itself or its frame. */
211
+ const isPopup = (el) => [...doc.querySelectorAll('[aria-expanded="true"][aria-controls]')].some((trigger) => (trigger.getAttribute('aria-controls') ?? '').split(/\s+/).some((id) => {
212
+ const named = id ? doc.getElementById(id) : null;
213
+ return named !== null && named.contains(el);
214
+ })) || roleOf(el) === 'menu';
215
+ for (const el of widgets) {
216
+ const role = roleOf(el);
217
+ const who = said(el, role);
218
+ // Every one of these patterns has a name; a switch takes its from its words.
219
+ if (!nameOf(el, role === 'switch'))
220
+ problems.push(`${who}: has no accessible name`);
221
+ if (native(el))
222
+ continue;
223
+ if (OWNS[role]) {
224
+ const { required, allowed } = OWNS[role];
225
+ const children = owned(el);
226
+ for (const child of children)
227
+ if (!allowed.includes(effectiveRole(child)))
228
+ problems.push(`${who}: owns a ${effectiveRole(child)}, which a ${role} may not hold`);
229
+ if (el.getAttribute('aria-busy') !== 'true' && !items(el, role).some((item) => required.includes(roleOf(item))))
230
+ problems.push(`${who}: owns no ${required[0]}`);
231
+ for (const item of items(el, role))
232
+ if (!nameOf(item, true))
233
+ problems.push(`${who}: an ${roleOf(item)} has no name`);
234
+ const stops = [...el.querySelectorAll('*'), el].filter(tabbable);
235
+ // Native radios of one name are one stop between them.
236
+ const seen = new Set();
237
+ const count = stops.filter((stop) => {
238
+ if (stop.tagName !== 'INPUT' || stop.type !== 'radio' || !stop.name)
239
+ return true;
240
+ const name = stop.name;
241
+ if (seen.has(name))
242
+ return false;
243
+ seen.add(name);
244
+ return true;
245
+ }).length;
246
+ if (driven.has(el)) {
247
+ if (count > 0)
248
+ problems.push(`${who}: a popup its combobox drives holds ${count} Tab stop(s); the focus belongs in the box`);
249
+ }
250
+ else if (role === 'menu' || isPopup(el)) {
251
+ if (count > 1)
252
+ problems.push(`${who}: holds ${count} Tab stops, not one`);
253
+ }
254
+ else if (count !== 1)
255
+ problems.push(`${who}: holds ${count} Tab stops, not one`);
256
+ if (el.hasAttribute('aria-activedescendant') && !tabbable(el) && doc.activeElement !== el)
257
+ problems.push(`${who}: points at its current item with aria-activedescendant but cannot take the focus`);
258
+ }
259
+ if (role === 'combobox') {
260
+ const expanded = el.getAttribute('aria-expanded') === 'true';
261
+ const ids = `${el.getAttribute('aria-controls') ?? ''} ${el.getAttribute('aria-owns') ?? ''}`.trim();
262
+ const popups = ids ? ids.split(/\s+/).map((id) => doc.getElementById(id)) : [];
263
+ if (expanded && !popups.some((popup) => popup && /^(listbox|tree|grid|dialog)$/.test(roleOf(popup))))
264
+ problems.push(`${who}: is expanded but controls no listbox, tree, grid or dialog`);
265
+ const active = el.getAttribute('aria-activedescendant');
266
+ if (active && !doc.getElementById(active))
267
+ problems.push(`${who}: aria-activedescendant names "${active}", which is not on the page`);
268
+ if (disabled(el) === false && !tabbable(el))
269
+ problems.push(`${who}: is not a Tab stop`);
270
+ }
271
+ if (role === 'switch') {
272
+ const checked = el.getAttribute('aria-checked');
273
+ if (checked !== 'true' && checked !== 'false' && !(el.tagName === 'INPUT' && el.type === 'checkbox'))
274
+ problems.push(`${who}: does not say whether it is on (aria-checked)`);
275
+ }
276
+ }
277
+ /* The topmost modal dialog holds the focus. Topmost is the one stacked highest — the largest z-index on it or an
278
+ ancestor — and among equals the one later in the document, which is where a layer opened last is drawn (a portal
279
+ appends; a dialog nested in another comes after it). A page that stacks by neither is not told it is wrong. */
280
+ const stacking = (el) => {
281
+ let z = 0;
282
+ for (let at = el; at; at = at.parentElement) {
283
+ const value = Number(doc.defaultView?.getComputedStyle(at).zIndex);
284
+ if (Number.isFinite(value))
285
+ z = Math.max(z, value);
286
+ }
287
+ return z;
288
+ };
289
+ let top;
290
+ for (const modal of widgets.filter((el) => roleOf(el).endsWith('dialog') && el.getAttribute('aria-modal') === 'true')) {
291
+ if (!top || stacking(modal) >= stacking(top))
292
+ top = modal;
293
+ }
294
+ if (top && !top.contains(doc.activeElement))
295
+ problems.push(`${said(top, 'dialog')}: an open modal dialog does not hold the focus`);
296
+ const resting = doc.activeElement;
297
+ if (resting && resting.closest('[inert]'))
298
+ problems.push('the focus is inside inert content');
299
+ if (opts.keys === false)
300
+ return problems;
301
+ /* ---- The keys, pattern by pattern ---- */
302
+ /* `holder` is the element carrying aria-activedescendant, or null where the focus itself roves. */
303
+ const moves = async (who, holder, container, role, keys) => {
304
+ const all = items(container, role);
305
+ const list = all.filter((item) => !disabled(item));
306
+ if (list.length < 2)
307
+ return;
308
+ const on = () => holder ?? (container.contains(doc.activeElement) ? doc.activeElement : container);
309
+ const now = () => current(holder ?? container, container);
310
+ const before = now();
311
+ await press(on(), keys[1]);
312
+ if (now() === before)
313
+ problems.push(`${who}: ${keys[1]} does not move to another item`);
314
+ focusHolds(who, keys[1]);
315
+ await press(on(), 'Home');
316
+ if (now() !== list[0] && now() !== all[0])
317
+ problems.push(`${who}: Home does not move to the first item`);
318
+ await press(on(), 'End');
319
+ if (now() !== list.at(-1) && now() !== all.at(-1))
320
+ problems.push(`${who}: End does not move to the last item`);
321
+ await press(on(), keys[0]);
322
+ focusHolds(who, keys[0]);
323
+ };
324
+ const closes = async (who, holder, popup, box) => {
325
+ await press(holder, 'Escape');
326
+ const gone = !popup.isConnected || hidden(popup) || (box !== undefined && box.getAttribute('aria-expanded') !== 'true');
327
+ if (!gone)
328
+ problems.push(`${who}: Escape does not close it`);
329
+ focusHolds(who, 'Escape');
330
+ };
331
+ for (const el of widgets) {
332
+ if (!el.isConnected || hidden(el) || native(el))
333
+ continue;
334
+ const role = roleOf(el);
335
+ const who = said(el, role);
336
+ if (role === 'tablist') {
337
+ const tabs = items(el, 'tablist');
338
+ const home = tabs.find(tabbable);
339
+ const live = tabs.filter((tab) => !disabled(tab));
340
+ if (!home || live.length < 2)
341
+ continue;
342
+ // Counted among the tabs an arrow can land on: it skips a disabled one, so counting it would overshoot.
343
+ const back = live.indexOf(home);
344
+ const vertical = el.getAttribute('aria-orientation') === 'vertical';
345
+ await focus(home);
346
+ await press(home, 'End');
347
+ if (doc.activeElement !== tabs.filter((tab) => !disabled(tab)).at(-1))
348
+ problems.push(`${who}: End does not move to the last tab`);
349
+ await press(doc.activeElement ?? home, 'Home');
350
+ if (doc.activeElement !== tabs.find((tab) => !disabled(tab)))
351
+ problems.push(`${who}: Home does not move to the first tab`);
352
+ const first = doc.activeElement;
353
+ await press(first ?? home, vertical ? 'ArrowDown' : 'ArrowRight');
354
+ if (doc.activeElement === first)
355
+ problems.push(`${who}: ${vertical ? 'ArrowDown' : 'ArrowRight'} does not move to the next tab`);
356
+ focusHolds(who, 'the arrow keys');
357
+ // Walk back to the tab that was chosen, so reading the page leaves it as it was.
358
+ await press(doc.activeElement ?? home, 'Home');
359
+ for (let i = 0; i < back; i++)
360
+ await press(doc.activeElement ?? home, vertical ? 'ArrowDown' : 'ArrowRight');
361
+ continue;
362
+ }
363
+ if (role === 'combobox' && el.getAttribute('aria-expanded') === 'true') {
364
+ const popup = [...driven].find(([, box]) => box === el)?.[0];
365
+ if (!popup || hidden(popup))
366
+ continue;
367
+ const kind = roleOf(popup);
368
+ await focus(el);
369
+ const list = kind === 'listbox' || kind === 'tree' ? items(popup, kind).filter((item) => !disabled(item)) : [];
370
+ if (list.length >= 2) {
371
+ const before = current(el, popup);
372
+ await press(el, 'ArrowDown');
373
+ if (current(el, popup) === before)
374
+ problems.push(`${who}: ArrowDown does not move to another item in its ${kind}`);
375
+ await press(el, 'ArrowUp');
376
+ }
377
+ await closes(who, el, popup, el);
378
+ continue;
379
+ }
380
+ if (role === 'menu') {
381
+ const holder = el.contains(doc.activeElement) ? doc.activeElement : null;
382
+ if (!holder) {
383
+ problems.push(`${who}: an open menu does not hold the focus`);
384
+ continue;
385
+ }
386
+ await moves(who, holder.hasAttribute('aria-activedescendant') ? holder : null, el, 'menu', ['ArrowUp', 'ArrowDown']);
387
+ await closes(who, doc.activeElement && el.contains(doc.activeElement) ? doc.activeElement : el, el);
388
+ continue;
389
+ }
390
+ if ((role === 'listbox' || role === 'tree') && !driven.has(el)) {
391
+ let holder = el.contains(doc.activeElement) ? doc.activeElement : null;
392
+ if (!holder) {
393
+ const stop = [el, ...el.querySelectorAll('*')].find(tabbable);
394
+ if (!stop)
395
+ continue;
396
+ await focus(stop);
397
+ holder = stop;
398
+ }
399
+ await moves(who, holder.hasAttribute('aria-activedescendant') ? holder : null, el, role, ['ArrowUp', 'ArrowDown']);
400
+ if (isPopup(el))
401
+ await closes(who, doc.activeElement && el.contains(doc.activeElement) ? doc.activeElement : el, el);
402
+ continue;
403
+ }
404
+ if (role === 'radiogroup') {
405
+ const radios = items(el, 'radiogroup');
406
+ // Native radios move by the browser's own keys, which a dispatched key does not reach.
407
+ if (radios.some((radio) => radio.tagName === 'INPUT'))
408
+ continue;
409
+ const home = radios.find(tabbable);
410
+ if (!home || radios.filter((radio) => !disabled(radio)).length < 2)
411
+ continue;
412
+ await focus(home);
413
+ await press(home, 'ArrowDown');
414
+ if (doc.activeElement === home)
415
+ problems.push(`${who}: ArrowDown does not move to the next radio`);
416
+ focusHolds(who, 'ArrowDown');
417
+ await press(doc.activeElement ?? home, 'ArrowUp');
418
+ }
419
+ }
420
+ return problems;
421
+ }
package/dist/forms.css CHANGED
@@ -69,6 +69,9 @@
69
69
  }
70
70
  /* On is a thicker edge drawn outside the box, not a wider border, so choosing moves nothing. */
71
71
  .choice-pick.is-on, .choice-card.is-on { border-color: var(--choice-on, var(--accent)); box-shadow: 0 0 0 1px var(--choice-on, var(--accent)); background: var(--choice-on-well, var(--accent-soft)); }
72
+ /* A button that is picked has no square to say so, so its face carries it: the host's picked well where it names one
73
+ (--choice-pick-on-well: a quiet form, whose --choice-on-well is its field's own fill), and heavier words. */
74
+ .choice-pick.is-on { background: var(--choice-pick-on-well, var(--choice-on-well, var(--accent-soft))); font-weight: 600; }
72
75
  .choice-pick:has(.choice-input:focus-visible), .choice-card:has(.choice-input:focus-visible), .choice-card:focus-visible { outline: var(--focus-width) solid var(--focus); outline-offset: var(--focus-offset); }
73
76
  .choice-card[aria-disabled="true"] { cursor: not-allowed; opacity: 0.6; }
74
77
  .choice-cards { display: flex; flex-direction: column; gap: var(--space-3); }
package/dist/index.d.ts CHANGED
@@ -7,14 +7,16 @@
7
7
  */
8
8
  export { Button, ButtonLink, buttonClass, type ButtonIntent, type ButtonLinkProps, type ButtonProps, type ButtonSize } from './Button.js';
9
9
  export { Field, type AnswerKind, type FieldControlProps } from './Field.js';
10
+ export { type ChangeDetails, type ChangeSource } from './changeDetails.js';
10
11
  export { Modal, type ModalHandle } from './Modal.js';
11
12
  export { DropMenu, DropGroup, DropItem, DropSeparator } from './DropMenu.js';
12
- export { Dropdown, MultiDropdown, type DropdownAction, type DropdownItem, type DropdownProps, type MultiDropdownProps, } from './Dropdown.js';
13
- export { Typeahead, type TypeaheadProps } from './Typeahead.js';
13
+ export { Dropdown, MultiDropdown, type DropdownAction, type DropdownChange, type DropdownItem, type DropdownProps, type MultiDropdownProps, } from './Dropdown.js';
14
+ export { Typeahead, type TypeaheadProps, type TypeaheadReason } from './Typeahead.js';
14
15
  export { Icon, loadIconsWith, registerIcons, weighIconsWith, type IconGlyph, type IconProps, type IconWeight, type IconWeighting, } from './Icon.js';
15
- export { DateField, type DateFieldProps, type DateFieldWords } from './DateField.js';
16
+ export { DateField, type DateFieldOpenReason, type DateFieldProps, type DateFieldWords } from './DateField.js';
16
17
  export type { FieldFrame } from './fieldFrame.js';
17
18
  export { TextField, MaskedField, MoneyField, ValidMark, type MaskedFieldProps, type TextFieldProps } from './TextField.js';
19
+ export { TextArea, type TextAreaProps } from './TextArea.js';
18
20
  export { SensitiveField, type SensitiveFieldProps } from './SensitiveField.js';
19
21
  export { FileField, type FileFieldProps } from './FileField.js';
20
22
  export { Select, MultiSelect } from './Select.js';
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  export { Button, ButtonLink, buttonClass } from './Button.js';
9
9
  export { Field } from './Field.js';
10
+ /* What every change callback hears second: the reason, the hand, the event. */
11
+ export {} from './changeDetails.js';
10
12
  export { Modal } from './Modal.js';
11
13
  export { DropMenu, DropGroup, DropItem, DropSeparator } from './DropMenu.js';
12
14
  export { Dropdown, MultiDropdown, } from './Dropdown.js';
@@ -14,6 +16,7 @@ export { Typeahead } from './Typeahead.js';
14
16
  export { Icon, loadIconsWith, registerIcons, weighIconsWith, } from './Icon.js';
15
17
  export { DateField } from './DateField.js';
16
18
  export { TextField, MaskedField, MoneyField, ValidMark } from './TextField.js';
19
+ export { TextArea } from './TextArea.js';
17
20
  export { SensitiveField } from './SensitiveField.js';
18
21
  export { FileField } from './FileField.js';
19
22
  export { Select, MultiSelect } from './Select.js';
@@ -11,5 +11,8 @@ export declare const defaultSlots: Record<string, AnyComponent>;
11
11
  export declare const UiKitContext: import("react").Context<Record<string, AnyComponent | undefined>>;
12
12
  /** Puts a kit in place for every render that has no provider above it; called once, before the first render. */
13
13
  export declare function installUiKit(kit: Record<string, AnyComponent | undefined> | undefined): void;
14
- export declare function slotted<C extends AnyComponent>(name: string, Default: C): C;
14
+ /** A slot's change callbacks, by prop: where in the call their details go, and the word to fill in when a kit leaves
15
+ them out. */
16
+ type ChangeFills = Readonly<Record<string, readonly [at: number, reason: string]>>;
17
+ export declare function slotted<C extends AnyComponent>(name: string, Default: C, fills?: ChangeFills): C;
15
18
  export {};
@@ -4,7 +4,8 @@
4
4
  * the installed kit, so a page that installs one before its first render needs no provider anywhere: nothing
5
5
  * re-renders, because nothing changes after paint (a control that swapped once drawn would shift the page).
6
6
  */
7
- import { createContext, createElement, useContext } from 'react';
7
+ import { createContext, createElement, useContext, useRef } from 'react';
8
+ import { changeSource, keptDetails } from '../changeDetails.js';
8
9
  const installed = {};
9
10
  /** The primitives' own drawing, by slot, filled as each slotted module loads. */
10
11
  export const defaultSlots = {};
@@ -17,7 +18,52 @@ export function installUiKit(kit) {
17
18
  }
18
19
  /* The wrapper is the whole cost of the seam on a page without a kit: one context read and one element. React 19
19
20
  carries `ref` as a prop, so a handle (Modal's) and a forwarded element ref (Button's) pass through untouched. */
20
- export function slotted(name, Default) {
21
+ export function slotted(name, Default, fills) {
21
22
  defaultSlots[name] = Default;
22
- return ((props) => createElement(useContext(UiKitContext)[name] ?? Default, props));
23
+ return ((props) => {
24
+ const Kit = useContext(UiKitContext)[name];
25
+ // The kit's change callbacks keep one identity for the life of the control, and read the caller's latest on each call.
26
+ const latest = useRef(props);
27
+ latest.current = props;
28
+ const wrappers = useRef({});
29
+ return createElement(Kit ?? Default, Kit && fills ? filled(props, fills, latest, wrappers.current) : props);
30
+ });
31
+ }
32
+ /* A kit may call a change callback with the value alone, or with details of its own that name no hand (Base UI's); every
33
+ caller reads `{ reason, source }` second, so the seam fills in what is missing. Only under a kit: the defaults always
34
+ give them. A wrapper's identity is stable, so a kit that puts the callback in an effect's dependencies does not rerun it
35
+ on every render. */
36
+ function filled(props, fills, latest, wrappers) {
37
+ let out = props;
38
+ for (const [key, [at, reason]] of Object.entries(fills)) {
39
+ if (typeof props[key] !== 'function')
40
+ continue;
41
+ if (out === props)
42
+ out = { ...props };
43
+ out[key] = wrappers[key] ??= (...args) => {
44
+ const callback = latest.current[key];
45
+ if (typeof callback !== 'function')
46
+ return undefined;
47
+ args[at] = withSource(args[at], reason);
48
+ return callback(...args);
49
+ };
50
+ }
51
+ return out;
52
+ }
53
+ /* Details as the kit gave them, a hand and a word added where they lack one. A raw `none` is Base UI's, and no caller
54
+ hears it. Filled in place where it can be: Base UI's details carry `cancel()` and an `isCanceled` that must stay live. */
55
+ function withSource(given, reason) {
56
+ const kept = keptDetails(reason);
57
+ if (typeof given !== 'object' || given === null)
58
+ return kept;
59
+ const details = given;
60
+ if (details.source !== undefined)
61
+ return given;
62
+ const word = typeof details.reason === 'string' && details.reason !== 'none' ? details.reason : reason;
63
+ // Base UI's stand-in event, named `base-ui`, says the page made the change (changeDetails.ts).
64
+ const source = details.event instanceof Event ? (details.event.type === 'base-ui' ? 'program' : changeSource(details.event)) : kept.source;
65
+ if (!Object.isExtensible(given))
66
+ return { ...details, reason: word, source };
67
+ Object.assign(details, { reason: word, source });
68
+ return given;
23
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/ui",
3
- "version": "1.0.0-rc.47",
3
+ "version": "1.0.0-rc.49",
4
4
  "description": "The standalone React primitives both shells are drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and DateField over Base UI, Switch, Tabs, Drawer, Popover, Avatar, Pagination, Carousel, Resizable, ScrollArea and Tooltip, the form controls built on them (text, masked, money and sensitive boxes, listboxes, choices, slider, progress and action bar; Preview), the landing hero's blocks (badge, photo tiles, icon rows; Preview), their tokens and stylesheet, and the zoom-aware ruler their popups are placed by.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {
@@ -43,6 +43,7 @@
43
43
  "./Resizable.js": "./dist/Resizable.js",
44
44
  "./ScrollArea.js": "./dist/ScrollArea.js",
45
45
  "./Popover.js": "./dist/Popover.js",
46
+ "./TextArea.js": "./dist/TextArea.js",
46
47
  "./FileField.js": "./dist/FileField.js",
47
48
  "./Select.js": "./dist/Select.js",
48
49
  "./SensitiveField.js": "./dist/SensitiveField.js",