@charcuterie/ui 4.28.3 → 4.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/CatalogPicker/CatalogPicker.d.ts +105 -0
  2. package/dist/CatalogPicker/CatalogPicker.d.ts.map +1 -0
  3. package/dist/CatalogPicker/CatalogPicker.js +152 -0
  4. package/dist/CatalogPicker/CatalogPicker.js.map +1 -0
  5. package/dist/CatalogPicker/CatalogPickerMark.d.ts +29 -0
  6. package/dist/CatalogPicker/CatalogPickerMark.d.ts.map +1 -0
  7. package/dist/CatalogPicker/CatalogPickerMark.js +35 -0
  8. package/dist/CatalogPicker/CatalogPickerMark.js.map +1 -0
  9. package/dist/CatalogPicker/CatalogPickerOption.d.ts +40 -0
  10. package/dist/CatalogPicker/CatalogPickerOption.d.ts.map +1 -0
  11. package/dist/CatalogPicker/CatalogPickerOption.js +42 -0
  12. package/dist/CatalogPicker/CatalogPickerOption.js.map +1 -0
  13. package/dist/CatalogPicker/CatalogPickerPanel.d.ts +60 -0
  14. package/dist/CatalogPicker/CatalogPickerPanel.d.ts.map +1 -0
  15. package/dist/CatalogPicker/CatalogPickerPanel.js +409 -0
  16. package/dist/CatalogPicker/CatalogPickerPanel.js.map +1 -0
  17. package/dist/CatalogPicker/CatalogPickerRail.d.ts +50 -0
  18. package/dist/CatalogPicker/CatalogPickerRail.d.ts.map +1 -0
  19. package/dist/CatalogPicker/CatalogPickerRail.js +114 -0
  20. package/dist/CatalogPicker/CatalogPickerRail.js.map +1 -0
  21. package/dist/CatalogPicker/catalogPickerDrawings.d.ts +10 -0
  22. package/dist/CatalogPicker/catalogPickerDrawings.d.ts.map +1 -0
  23. package/dist/CatalogPicker/catalogPickerDrawings.js +29 -0
  24. package/dist/CatalogPicker/catalogPickerDrawings.js.map +1 -0
  25. package/dist/CatalogPicker/catalogPickerView.d.ts +173 -0
  26. package/dist/CatalogPicker/catalogPickerView.d.ts.map +1 -0
  27. package/dist/CatalogPicker/catalogPickerView.js +235 -0
  28. package/dist/CatalogPicker/catalogPickerView.js.map +1 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/package.json +3 -3
  34. package/src/CatalogPicker/CatalogPicker.mdx +157 -0
  35. package/src/CatalogPicker/CatalogPicker.stories.tsx +218 -0
  36. package/src/CatalogPicker/CatalogPicker.test.tsx +1352 -0
  37. package/src/CatalogPicker/CatalogPicker.tsx +376 -0
  38. package/src/CatalogPicker/CatalogPickerMark.tsx +89 -0
  39. package/src/CatalogPicker/CatalogPickerOption.tsx +138 -0
  40. package/src/CatalogPicker/CatalogPickerPanel.tsx +780 -0
  41. package/src/CatalogPicker/CatalogPickerRail.tsx +214 -0
  42. package/src/CatalogPicker/catalogPicker.storyHelpers.tsx +276 -0
  43. package/src/CatalogPicker/catalogPickerDrawings.tsx +51 -0
  44. package/src/CatalogPicker/catalogPickerView.test.ts +346 -0
  45. package/src/CatalogPicker/catalogPickerView.ts +457 -0
  46. package/src/Dialog/Dialog.test.tsx +20 -289
  47. package/src/Field/Field.test.tsx +11 -405
  48. package/src/index.ts +6 -0
  49. package/src/sourceRules.test.ts +5 -1
@@ -4,70 +4,16 @@ import { inject, test } from "vitest"
4
4
 
5
5
  import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
6
6
  import { mountStory } from "../mountStory.testHelpers.ts"
7
- import {
8
- expectAgentDrivable,
9
- expectHiddenFromAgents,
10
- } from "../testing/index.ts"
7
+ import { expectAgentDrivable } from "../testing/index.ts"
11
8
  import * as stories from "./Dialog.stories.tsx"
12
9
 
13
- const {
14
- PickerDraft,
15
- AllStates,
16
- AllVariants,
17
- Playground,
18
- InitialFocus,
19
- Interactive,
20
- NoBody,
21
- Responsive,
22
- Stacked,
23
- } = composeStories(stories)
24
-
25
- test("a dialog with no body renders from heading and footer alone", async () => {
26
- const { body, canvas } = await mountStory(NoBody)
27
-
28
- await userEvent.click(
29
- expectAgentDrivable(canvas, {
30
- name: "Delete the file",
31
- role: "button",
32
- }),
33
- )
34
-
35
- // `children` is optional: the question is the accessible name and
36
- // the answers are the footer, with nothing in between.
37
- const dialog = expectAgentDrivable(body, {
38
- name: "Delete this file? This cannot be undone.",
39
- role: "dialog",
40
- })
41
-
42
- await expect(
43
- expectAgentDrivable(body, {
44
- name: "Delete",
45
- role: "button",
46
- }),
47
- ).toBeInTheDocument()
48
-
49
- await expectNoAxeViolations(dialog)
50
- })
51
-
52
- test("the dialog is reachable from a body-scoped query", async () => {
53
- const { body, canvas } = await mountStory(Playground)
54
-
55
- await userEvent.click(
56
- expectAgentDrivable(canvas, {
57
- name: "Show the read error",
58
- role: "button",
59
- }),
60
- )
61
-
62
- // Portalled now, so the panel is found through `body`; the trigger
63
- // stays in the canvas.
64
- const dialog = expectAgentDrivable(body, {
65
- name: "Read error on title 4",
66
- role: "dialog",
67
- })
68
-
69
- await expectNoAxeViolations(dialog)
70
- })
10
+ /**
11
+ * Layout and paint only. The Dialog's behavior, what a person can do
12
+ * and hear, is `REQ-UI-007` to `REQ-UI-015` in
13
+ * `packages/docs/requirements/dialog.feature`.
14
+ */
15
+ const { AllStates, AllVariants, Responsive, Stacked } =
16
+ composeStories(stories)
71
17
 
72
18
  const isNarrow = inject("viewport") === "narrow"
73
19
 
@@ -119,45 +65,6 @@ test.runIf(isNarrow)(
119
65
  },
120
66
  )
121
67
 
122
- test("a non-dismissable dialog ignores Escape rather than closing", async () => {
123
- const { body, canvas } = await mountStory(AllStates)
124
-
125
- await userEvent.click(
126
- expectAgentDrivable(canvas, {
127
- name: "Not dismissable",
128
- role: "button",
129
- }),
130
- )
131
-
132
- const _dialog = expectAgentDrivable(body, {
133
- name: "This erases eight completed titles",
134
- role: "dialog",
135
- })
136
-
137
- // There is no Close button, and Escape is disabled at the dismiss
138
- // layer (`isDismissable={false}` → `useDismiss` escapeKey off), so
139
- // the browser cannot close a dialog the app still owns.
140
- await expect(
141
- body.queryByRole("button", { name: "Close" }),
142
- ).toBeNull()
143
-
144
- await userEvent.keyboard("{Escape}")
145
-
146
- const keepButton = await body.findByRole("button", {
147
- name: "Keep the titles",
148
- })
149
-
150
- await expect(body.getByRole("dialog")).toBeInTheDocument()
151
-
152
- // The differential half. Without it, "still open" would also be
153
- // satisfied by a dialog nothing can close at all.
154
- await userEvent.click(keepButton)
155
-
156
- await waitFor(() => {
157
- expect(body.queryByRole("dialog")).toBeNull()
158
- })
159
- })
160
-
161
68
  test("a long body scrolls inside the clamp", async () => {
162
69
  const { body, canvas } = await mountStory(AllStates)
163
70
 
@@ -230,230 +137,54 @@ test("the scrim is the token, rendered as the shared backdrop", async () => {
230
137
  })
231
138
 
232
139
  /**
233
- * The keyboard contract, driven — and Escape is pressable for real
234
- * now, unlike the old native `<dialog>`. `useDismiss` listens for a
235
- * keydown rather than relying on a UA default action, so
236
- * `userEvent.keyboard("{Escape}")` is a real close request.
140
+ * Stacking draws one scrim behind both dialogs, and the scrim leaves
141
+ * with the last of them. The behavior, which dialog is live and which
142
+ * closes first, is `REQ-UI-012` in `packages/docs/requirements/dialog.feature`;
143
+ * the scrim is paint, so it is checked here.
237
144
  */
238
- test("focus is trapped inside, and Escape restores it to the trigger", async () => {
239
- const { body, canvas } = await mountStory(Interactive)
240
-
241
- const trigger = expectAgentDrivable(canvas, {
242
- name: "Stop the rip",
243
- role: "button",
244
- })
245
-
246
- await userEvent.click(trigger)
247
-
248
- const dialog = expectAgentDrivable(body, {
249
- name: "Stop the rip?",
250
- role: "dialog",
251
- })
252
-
253
- await waitFor(() => {
254
- expect(dialog.contains(document.activeElement)).toBe(
255
- true,
256
- )
257
- })
258
-
259
- await userEvent.keyboard("{Escape}")
260
-
261
- await waitFor(() => {
262
- expect(body.queryByRole("dialog")).toBeNull()
263
- })
264
-
265
- // Focus restored to what opened it — `FloatingFocusManager`'s
266
- // `returnFocus`, the thing hand-rolled modals in the fleet lose.
267
- await expect(document.activeElement).toBe(trigger)
268
- })
269
-
270
- /**
271
- * Stacking: one scrim behind two dialogs, the lower one `inert`, and
272
- * a top-first dismissal on both an outside press and Escape.
273
- */
274
- test("stacked dialogs share one scrim and dismiss top-first", async () => {
145
+ test("stacked dialogs share one scrim, and it leaves with the last", async () => {
275
146
  const { body, canvas } = await mountStory(Stacked)
276
147
 
277
148
  await userEvent.click(
278
- expectAgentDrivable(canvas, {
149
+ canvas.getByRole("button", {
279
150
  name: "Open the first dialog",
280
- role: "button",
281
151
  }),
282
152
  )
283
153
 
284
- // Captured while it is still the only dialog: once the second opens,
285
- // the first goes `inert` and a role query no longer sees it.
286
- const first = expectAgentDrivable(body, {
287
- name: "First dialog",
288
- role: "dialog",
289
- })
290
-
291
154
  await userEvent.click(
292
- expectAgentDrivable(body, {
155
+ body.getByRole("button", {
293
156
  name: "Open a second over it",
294
- role: "button",
295
157
  }),
296
158
  )
297
159
 
298
- const second = expectAgentDrivable(body, {
299
- name: "Second dialog",
300
- role: "dialog",
301
- })
160
+ await expect(
161
+ body.getByRole("dialog", { name: "Second dialog" }),
162
+ ).toBeInTheDocument()
302
163
 
303
164
  // One scrim for both — the whole point of the provider.
304
165
  await expect(
305
166
  document.body.querySelectorAll(".bg-scrim"),
306
167
  ).toHaveLength(1)
307
168
 
308
- // The lower dialog is hidden from assistive tech while the top is
309
- // open, and focus is trapped in the top.
310
- expectHiddenFromAgents(first)
311
-
312
- await waitFor(() => {
313
- expect(second.contains(document.activeElement)).toBe(
314
- true,
315
- )
316
- })
317
-
318
- // The top dialog's own controls are actually **hittable** — the
319
- // scrim sits a layer below the panels, so it does not intercept a
320
- // real click. `userEvent` fires on the element directly and would
321
- // miss this; `elementFromPoint` is the check that a covering scrim
322
- // fails.
323
- const closeButton = expectAgentDrivable(body, {
324
- name: "Close this one",
325
- role: "button",
326
- })
327
-
328
- const buttonRect = closeButton.getBoundingClientRect()
329
-
330
- const atPoint = document.elementFromPoint(
331
- buttonRect.left + buttonRect.width / 2,
332
- buttonRect.top + buttonRect.height / 2,
333
- )
334
-
335
- await expect(
336
- atPoint !== null && closeButton.contains(atPoint),
337
- ).toBe(true)
338
-
339
- // An outside press closes the top only.
340
- await userEvent.click(document.body)
169
+ await userEvent.keyboard("{Escape}")
341
170
 
342
171
  await waitFor(() => {
343
172
  expect(
344
- body.queryByRole("dialog", {
345
- name: "Second dialog",
346
- }),
173
+ body.queryByRole("dialog", { name: "Second dialog" }),
347
174
  ).toBeNull()
348
175
  })
349
176
 
350
- // The first is live again — no longer inert, and the scrim stays.
351
177
  await expect(
352
178
  document.body.querySelectorAll(".bg-scrim"),
353
179
  ).toHaveLength(1)
354
180
 
355
- const firstAgain = expectAgentDrivable(body, {
356
- name: "First dialog",
357
- role: "dialog",
358
- })
359
-
360
- // Escape closes the last one, and the scrim goes with it.
361
181
  await userEvent.keyboard("{Escape}")
362
182
 
363
183
  await waitFor(() => {
364
184
  expect(body.queryByRole("dialog")).toBeNull()
365
185
  })
366
186
 
367
- await expect(firstAgain).not.toBeInTheDocument()
368
-
369
187
  await expect(
370
188
  document.body.querySelector(".bg-scrim"),
371
189
  ).toBeNull()
372
190
  })
373
-
374
- test("initialFocus puts the caret in the field, not on Close", async () => {
375
- // Without it the focus manager takes the first tabbable element,
376
- // which is the Close button — so a dialog wrapping a form eats
377
- // whatever is typed first. The consumer cannot fix that from
378
- // outside: focusing in its own effect races the manager and
379
- // loses, which reads as the app ignoring you.
380
- const { body, canvas } = await mountStory(InitialFocus)
381
-
382
- await userEvent.click(
383
- expectAgentDrivable(canvas, {
384
- name: "Add a title",
385
- role: "button",
386
- }),
387
- )
388
-
389
- const field = expectAgentDrivable(body, {
390
- name: "Title",
391
- role: "textbox",
392
- })
393
-
394
- await waitFor(async () => {
395
- await expect(field).toHaveFocus()
396
- })
397
-
398
- await userEvent.keyboard("Sharpen the chisels")
399
-
400
- await expect(field).toHaveValue("Sharpen the chisels")
401
- })
402
-
403
- test("a picker cancels its selection without closing the enclosing draft", async () => {
404
- const { body } = await mountStory(PickerDraft)
405
- const input = expectAgentDrivable(body, {
406
- role: "textbox",
407
- name: "Draft name",
408
- })
409
- await userEvent.clear(input)
410
- await userEvent.type(input, "An unsaved change")
411
- const trigger = body.getByRole("button", {
412
- name: "Draft parent: No parent",
413
- })
414
- await userEvent.click(trigger)
415
- const option = body.getByRole("option", {
416
- name: "No parent",
417
- })
418
- await expect(option).toHaveFocus()
419
- await userEvent.keyboard("{Escape}")
420
- await expect(
421
- body.getByRole("dialog", { name: "Edit a draft" }),
422
- ).toBeVisible()
423
- await expect(input).toHaveValue("An unsaved change")
424
- await expect(trigger).toHaveFocus()
425
- await expect(
426
- body.queryByRole("listbox"),
427
- ).not.toBeInTheDocument()
428
- // A press elsewhere in the draft also dismisses only the picker.
429
- await userEvent.click(trigger)
430
- await expect(
431
- body.getByRole("option", { name: "No parent" }),
432
- ).toHaveFocus()
433
- await userEvent.click(input)
434
- await expect(
435
- body.queryByRole("listbox"),
436
- ).not.toBeInTheDocument()
437
- await expect(
438
- body.getByRole("dialog", { name: "Edit a draft" }),
439
- ).toBeVisible()
440
- await expect(input).toHaveValue("An unsaved change")
441
- await userEvent.click(trigger)
442
- await userEvent.click(
443
- body.getByRole("option", { name: "Another draft" }),
444
- )
445
- await expect(
446
- body.getByRole("dialog", { name: "Edit a draft" }),
447
- ).toBeVisible()
448
- await expect(
449
- body.getByRole("button", {
450
- name: "Draft parent: Another draft",
451
- }),
452
- ).toHaveFocus()
453
- await userEvent.keyboard("{Escape}")
454
- await waitFor(() =>
455
- expect(
456
- body.queryByRole("dialog", { name: "Edit a draft" }),
457
- ).not.toBeInTheDocument(),
458
- )
459
- })