@brightlocal/ui-components 3.3.0 → 3.5.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 (207) hide show
  1. package/AI_USAGE.md +22 -3
  2. package/README.md +177 -109
  3. package/component-meta.json +1307 -113
  4. package/dist/alert-dialog.cjs +1 -1
  5. package/dist/alert-dialog.d.ts +13 -2
  6. package/dist/alert-dialog.d.ts.map +1 -1
  7. package/dist/alert-dialog.js +4 -3
  8. package/dist/banner.cjs +1 -1
  9. package/dist/banner.d.ts +47 -11
  10. package/dist/banner.d.ts.map +1 -1
  11. package/dist/banner.js +156 -79
  12. package/dist/blocks/empty-state.cjs +1 -1
  13. package/dist/blocks/empty-state.d.ts +40 -5
  14. package/dist/blocks/empty-state.d.ts.map +1 -1
  15. package/dist/blocks/empty-state.js +59 -52
  16. package/dist/blocks/input-list.cjs +1 -1
  17. package/dist/blocks/input-list.d.ts +1 -0
  18. package/dist/blocks/input-list.d.ts.map +1 -1
  19. package/dist/blocks/input-list.js +39 -39
  20. package/dist/blocks/sidebar.cjs +1 -1
  21. package/dist/blocks/sidebar.d.ts +12 -6
  22. package/dist/blocks/sidebar.d.ts.map +1 -1
  23. package/dist/blocks/sidebar.js +64 -63
  24. package/dist/button.cjs +1 -1
  25. package/dist/button.d.ts.map +1 -1
  26. package/dist/button.js +47 -43
  27. package/dist/card.cjs +1 -1
  28. package/dist/card.d.ts +12 -0
  29. package/dist/card.d.ts.map +1 -1
  30. package/dist/card.js +115 -97
  31. package/dist/chart.cjs +6 -6
  32. package/dist/chart.d.ts +6 -10
  33. package/dist/chart.d.ts.map +1 -1
  34. package/dist/chart.js +281 -296
  35. package/dist/combobox.cjs +3 -3
  36. package/dist/combobox.d.ts.map +1 -1
  37. package/dist/combobox.js +430 -343
  38. package/dist/command.cjs +1 -1
  39. package/dist/command.d.ts +23 -2
  40. package/dist/command.d.ts.map +1 -1
  41. package/dist/command.js +212 -207
  42. package/dist/count-indicator.cjs +1 -0
  43. package/dist/count-indicator.d.ts +85 -0
  44. package/dist/count-indicator.d.ts.map +1 -0
  45. package/dist/count-indicator.js +72 -0
  46. package/dist/data-table.cjs +1 -1
  47. package/dist/data-table.d.ts +101 -11
  48. package/dist/data-table.d.ts.map +1 -1
  49. package/dist/data-table.js +593 -523
  50. package/dist/description-list.cjs +1 -0
  51. package/dist/description-list.d.ts +142 -0
  52. package/dist/description-list.d.ts.map +1 -0
  53. package/dist/description-list.js +173 -0
  54. package/dist/dialog.cjs +1 -1
  55. package/dist/dialog.d.ts +26 -3
  56. package/dist/dialog.d.ts.map +1 -1
  57. package/dist/dialog.js +62 -47
  58. package/dist/drawer.cjs +1 -1
  59. package/dist/drawer.d.ts +8 -4
  60. package/dist/drawer.d.ts.map +1 -1
  61. package/dist/drawer.js +37 -38
  62. package/dist/file-upload.cjs +1 -0
  63. package/dist/file-upload.d.ts +546 -0
  64. package/dist/file-upload.d.ts.map +1 -0
  65. package/dist/file-upload.js +1103 -0
  66. package/dist/global-layout.cjs +1 -1
  67. package/dist/global-layout.d.ts +7 -2
  68. package/dist/global-layout.d.ts.map +1 -1
  69. package/dist/global-layout.js +52 -52
  70. package/dist/hooks/use-file-dropzone.cjs +1 -0
  71. package/dist/hooks/use-file-dropzone.d.ts +75 -0
  72. package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
  73. package/dist/hooks/use-file-dropzone.js +133 -0
  74. package/dist/hover-card.cjs +1 -1
  75. package/dist/hover-card.d.ts +29 -16
  76. package/dist/hover-card.d.ts.map +1 -1
  77. package/dist/hover-card.js +153 -36
  78. package/dist/index.cjs +1 -1
  79. package/dist/index.d.ts +4 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +681 -623
  82. package/dist/input-chip.cjs +1 -1
  83. package/dist/input-chip.d.ts +30 -1
  84. package/dist/input-chip.d.ts.map +1 -1
  85. package/dist/input-chip.js +131 -115
  86. package/dist/input-group.cjs +1 -1
  87. package/dist/input-group.d.ts +37 -2
  88. package/dist/input-group.d.ts.map +1 -1
  89. package/dist/input-group.js +131 -114
  90. package/dist/input-password.cjs +1 -1
  91. package/dist/input-password.js +6 -6
  92. package/dist/lib/empty-canvas.cjs +1 -1
  93. package/dist/lib/empty-canvas.d.ts +27 -1
  94. package/dist/lib/empty-canvas.d.ts.map +1 -1
  95. package/dist/lib/empty-canvas.js +27 -23
  96. package/dist/lib/empty-chip.cjs +1 -1
  97. package/dist/lib/empty-chip.d.ts +19 -2
  98. package/dist/lib/empty-chip.d.ts.map +1 -1
  99. package/dist/lib/empty-chip.js +14 -9
  100. package/dist/lib/field-aria.cjs +1 -1
  101. package/dist/lib/field-aria.d.ts +4 -4
  102. package/dist/lib/field-aria.d.ts.map +1 -1
  103. package/dist/lib/field-aria.js +7 -5
  104. package/dist/lib/media-viewer-content.cjs +1 -1
  105. package/dist/lib/media-viewer-content.js +1 -1
  106. package/dist/lib/motion.cjs +1 -1
  107. package/dist/lib/motion.js +15 -10
  108. package/dist/lib/table-internal.cjs +1 -1
  109. package/dist/lib/table-internal.d.ts +19 -0
  110. package/dist/lib/table-internal.d.ts.map +1 -1
  111. package/dist/lib/table-internal.js +22 -7
  112. package/dist/list.cjs +1 -1
  113. package/dist/list.d.ts +230 -40
  114. package/dist/list.d.ts.map +1 -1
  115. package/dist/list.js +301 -66
  116. package/dist/logo-mark.cjs +1 -1
  117. package/dist/logo-mark.d.ts +18 -2
  118. package/dist/logo-mark.d.ts.map +1 -1
  119. package/dist/logo-mark.js +159 -79
  120. package/dist/media-empty.cjs +1 -1
  121. package/dist/media-empty.d.ts +50 -7
  122. package/dist/media-empty.d.ts.map +1 -1
  123. package/dist/media-empty.js +14 -13
  124. package/dist/media-viewer.cjs +1 -1
  125. package/dist/media-viewer.js +6 -6
  126. package/dist/multi-select-filter.cjs +1 -1
  127. package/dist/multi-select-filter.d.ts.map +1 -1
  128. package/dist/multi-select-filter.js +92 -101
  129. package/dist/pagination.cjs +1 -1
  130. package/dist/pagination.d.ts +11 -0
  131. package/dist/pagination.d.ts.map +1 -1
  132. package/dist/pagination.js +17 -17
  133. package/dist/relative-date.d.ts +6 -0
  134. package/dist/relative-date.d.ts.map +1 -1
  135. package/dist/resizable.d.ts +1 -1
  136. package/dist/result-count.cjs +1 -1
  137. package/dist/result-count.d.ts +13 -16
  138. package/dist/result-count.d.ts.map +1 -1
  139. package/dist/result-count.js +24 -33
  140. package/dist/route-progress.cjs +1 -1
  141. package/dist/route-progress.js +24 -23
  142. package/dist/sheet.cjs +1 -1
  143. package/dist/sheet.d.ts +22 -3
  144. package/dist/sheet.d.ts.map +1 -1
  145. package/dist/sheet.js +152 -125
  146. package/dist/single-select-filter.cjs +1 -1
  147. package/dist/single-select-filter.d.ts.map +1 -1
  148. package/dist/single-select-filter.js +67 -76
  149. package/dist/table.cjs +1 -1
  150. package/dist/table.d.ts.map +1 -1
  151. package/dist/table.js +77 -76
  152. package/dist/tabs.cjs +1 -1
  153. package/dist/tabs.d.ts +39 -3
  154. package/dist/tabs.d.ts.map +1 -1
  155. package/dist/tabs.js +127 -76
  156. package/dist/textarea.cjs +1 -1
  157. package/dist/textarea.d.ts +34 -0
  158. package/dist/textarea.d.ts.map +1 -1
  159. package/dist/textarea.js +115 -19
  160. package/dist/tooltip.cjs +1 -1
  161. package/dist/tooltip.d.ts.map +1 -1
  162. package/dist/tooltip.js +137 -131
  163. package/dist/typography-text.cjs +1 -1
  164. package/dist/typography-text.d.ts +6 -2
  165. package/dist/typography-text.d.ts.map +1 -1
  166. package/dist/typography-text.js +14 -13
  167. package/package.json +2 -3
  168. package/src/blocks/empty-state.tsx +108 -48
  169. package/src/blocks/input-list.tsx +15 -9
  170. package/src/blocks/sidebar.tsx +39 -16
  171. package/src/components/alert-dialog.tsx +18 -2
  172. package/src/components/banner.tsx +247 -68
  173. package/src/components/button.tsx +27 -10
  174. package/src/components/card.tsx +89 -7
  175. package/src/components/chart.tsx +47 -67
  176. package/src/components/combobox.tsx +221 -12
  177. package/src/components/command.tsx +83 -37
  178. package/src/components/count-indicator.tsx +188 -0
  179. package/src/components/data-table.tsx +506 -159
  180. package/src/components/description-list.tsx +445 -0
  181. package/src/components/dialog.tsx +74 -5
  182. package/src/components/drawer.tsx +52 -32
  183. package/src/components/file-upload.tsx +2574 -0
  184. package/src/components/global-layout.tsx +18 -5
  185. package/src/components/hover-card.tsx +395 -65
  186. package/src/components/input-chip.tsx +67 -2
  187. package/src/components/input-group.tsx +89 -6
  188. package/src/components/list.tsx +720 -72
  189. package/src/components/logo-mark.tsx +109 -25
  190. package/src/components/media-empty.tsx +62 -7
  191. package/src/components/multi-select-filter.tsx +9 -16
  192. package/src/components/pagination.tsx +15 -2
  193. package/src/components/relative-date.tsx +6 -0
  194. package/src/components/result-count.tsx +27 -54
  195. package/src/components/sheet.tsx +86 -8
  196. package/src/components/single-select-filter.tsx +9 -16
  197. package/src/components/table.tsx +16 -1
  198. package/src/components/tabs.tsx +223 -41
  199. package/src/components/textarea.tsx +271 -4
  200. package/src/components/tooltip.tsx +29 -2
  201. package/src/components/typography-text.tsx +7 -2
  202. package/src/hooks/use-file-dropzone.ts +325 -0
  203. package/src/index.ts +4 -0
  204. package/src/lib/empty-canvas.tsx +47 -20
  205. package/src/lib/empty-chip.tsx +38 -3
  206. package/src/lib/field-aria.tsx +11 -6
  207. package/src/lib/table-internal.ts +38 -0
@@ -8,6 +8,7 @@ import { ChevronDown, ChevronUp, X } from "@brightlocal/icons";
8
8
  import { cn } from "@brightlocal/ui-components/lib/utils";
9
9
  import { Button } from "@brightlocal/ui-components/button";
10
10
  import { ScrollArea } from "@brightlocal/ui-components/scroll-area";
11
+ import { Spinner } from "@brightlocal/ui-components/spinner";
11
12
  import { useOverlayPointerLock } from "@brightlocal/ui-components/hooks/use-overlay-pointer-lock";
12
13
 
13
14
  /**
@@ -26,8 +27,10 @@ export type SheetSide = "top" | "right" | "bottom" | "left";
26
27
  * partly visible behind it on phones (used by the Sidebar mobile nav)
27
28
  * - lg: Panel fills 75% of the viewport up to 512px — detail panels with
28
29
  * dense content (date pickers, thumbnail rows)
30
+ * - xl: Full width on phones, 480px from the `sm` breakpoint and 640px from
31
+ * `xl` — edit forms with a table or a row of selects (DS-1245)
29
32
  */
30
- export type SheetSize = "default" | "sm" | "lg";
33
+ export type SheetSize = "default" | "sm" | "lg" | "xl";
31
34
 
32
35
  const sheetContentVariants = cva(
33
36
  [
@@ -90,6 +93,7 @@ const sheetContentVariants = cva(
90
93
  default: [],
91
94
  sm: [],
92
95
  lg: [],
96
+ xl: [],
93
97
  },
94
98
  },
95
99
  compoundVariants: [
@@ -119,6 +123,15 @@ const sheetContentVariants = cva(
119
123
  size: "lg",
120
124
  className: ["w-3/4", "sm:max-w-lg"],
121
125
  },
126
+ // xl side panels are the form width (DS-1245): full width on phones,
127
+ // where 75% is too narrow for fields, then two fixed steps on the DS
128
+ // breakpoints — 480px from sm, 640px from xl — so the panel does not
129
+ // shift as the window resizes.
130
+ {
131
+ side: ["left", "right"],
132
+ size: "xl",
133
+ className: ["w-full", "sm:w-120", "xl:w-160"],
134
+ },
122
135
  ],
123
136
  defaultVariants: {
124
137
  side: "right",
@@ -223,7 +236,8 @@ interface SheetContentProps
223
236
  /**
224
237
  * Width preset for side panels. `sm` hugs the content between 288 and
225
238
  * 320px; `default` keeps the classic 75%-up-to-384px drawer width; `lg`
226
- * widens to 75%-up-to-512px for dense detail panels.
239
+ * widens to 75%-up-to-512px for dense detail panels; `xl` is the form
240
+ * width — full width on phones, 480px from `sm`, 640px from `xl`.
227
241
  * Ignored for top/bottom sheets.
228
242
  * @default "default"
229
243
  */
@@ -367,6 +381,22 @@ interface SheetPaginationProps extends Omit<
367
381
  */
368
382
  renderPosition?:
369
383
  ((info: SheetPaginationPositionInfo) => React.ReactNode) | null;
384
+ /**
385
+ * Marks the step the user just requested as in flight — e.g. the next item
386
+ * sits on a page that is still being fetched. The button that requested
387
+ * the step (by click or arrow key) swaps its chevron for a spinner and sets
388
+ * `aria-busy`; both buttons ignore clicks and arrow keys until the flag
389
+ * clears, without a disabled look, so focus stays where it is. Screen
390
+ * readers hear `loadingLabel`. Keep `hasPrevious` / `hasNext` describing
391
+ * the list, not the fetch.
392
+ * @default false
393
+ */
394
+ loading?: boolean;
395
+ /**
396
+ * Text announced to screen readers while `loading` is true.
397
+ * @default "Loading item"
398
+ */
399
+ loadingLabel?: string;
370
400
  /**
371
401
  * Accessible label for the item navigation group.
372
402
  * @default "Item navigation"
@@ -414,6 +444,8 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
414
444
  hasPrevious,
415
445
  hasNext,
416
446
  renderPosition,
447
+ loading = false,
448
+ loadingLabel,
417
449
  ariaLabel,
418
450
  prevAriaLabel,
419
451
  nextAriaLabel,
@@ -433,11 +465,30 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
433
465
  // The button that just triggered a step. Set only by our own
434
466
  // navigation, consumed on the next commit.
435
467
  const pendingRef = React.useRef<HTMLButtonElement | null>(null);
468
+ // The direction of the last requested step — the button that owns the
469
+ // spinner while `loading` (an arrow key on Previous can request Next).
470
+ const [requested, setRequested] = React.useState<
471
+ "previous" | "next" | null
472
+ >(null);
473
+
474
+ // Once the step lands (the position or a boundary changes, or `loading`
475
+ // finishes), forget the requester so a later refetch raised from outside
476
+ // does not spin the old button. Adjusted during render, not in an effect.
477
+ const settleKey = `${loading}|${current}|${total}|${canPrevious}|${canNext}`;
478
+ const [prevSettleKey, setPrevSettleKey] = React.useState(settleKey);
479
+ if (settleKey !== prevSettleKey) {
480
+ setPrevSettleKey(settleKey);
481
+ if (!loading) setRequested(null);
482
+ }
436
483
 
437
484
  // Reaching a boundary disables the button that was just pressed, which
438
485
  // drops focus to <body>. Hand it to the sibling instead so keyboard users
439
- // stay in the control.
486
+ // stay in the control. While a step is loading the boundary is not known
487
+ // yet — keep the pending hand-off until it lands. Runs only when the
488
+ // position, a boundary or `loading` changes, so the render caused by
489
+ // recording a request does not consume the hand-off early.
440
490
  React.useEffect(() => {
491
+ if (loading) return;
441
492
  const pending = pendingRef.current;
442
493
  pendingRef.current = null;
443
494
  if (!pending) return;
@@ -448,7 +499,7 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
448
499
  } else if (!canNext && pending === nextRef.current && canPrevious) {
449
500
  prevRef.current?.focus();
450
501
  }
451
- });
502
+ }, [loading, current, total, canPrevious, canNext]);
452
503
 
453
504
  const handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {
454
505
  // Focus left on purpose (to anything but the sibling) — drop any
@@ -463,17 +514,26 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
463
514
  direction: "previous" | "next",
464
515
  trigger: HTMLButtonElement
465
516
  ) => {
517
+ // Inert while a step is in flight — prevents a double fetch.
518
+ if (loading) return;
466
519
  if (direction === "previous") {
467
520
  if (!canPrevious) return;
468
521
  pendingRef.current = trigger;
522
+ setRequested("previous");
469
523
  onPrevious();
470
524
  } else {
471
525
  if (!canNext) return;
472
526
  pendingRef.current = trigger;
527
+ setRequested("next");
473
528
  onNext();
474
529
  }
475
530
  };
476
531
 
532
+ // Without a recorded request (loading set from outside), no button gets
533
+ // the spinner — the status still announces busy and input is ignored.
534
+ const previousBusy = loading && requested === "previous";
535
+ const nextBusy = loading && requested === "next";
536
+
477
537
  const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
478
538
  if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
479
539
  event.preventDefault();
@@ -496,8 +556,8 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
496
556
  ref={ref}
497
557
  aria-label={ariaLabel ?? "Item navigation"}
498
558
  // mb-2 on top of SheetContent's gap-4 gives the 24px Figma gap to
499
- // the header below.
500
- className={cn("mb-2 flex items-center gap-1", className)}
559
+ // the header below. `relative` anchors the sr-only status below.
560
+ className={cn("relative mb-2 flex items-center gap-1", className)}
501
561
  data-hook={dataHook}
502
562
  data-slot="sheet-pagination"
503
563
  data-tracking-el={trackingEl}
@@ -507,6 +567,7 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
507
567
  >
508
568
  <Button
509
569
  ref={prevRef}
570
+ aria-busy={previousBusy ? "true" : undefined}
510
571
  ariaLabel={prevAriaLabel ?? "Previous item"}
511
572
  dataHook={`${dataHook}-previous`}
512
573
  disabled={!canPrevious}
@@ -515,10 +576,15 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
515
576
  onClick={(event) => step("previous", event.currentTarget)}
516
577
  onKeyDown={handleKeyDown}
517
578
  >
518
- <ChevronUp />
579
+ {previousBusy ? (
580
+ <Spinner dataHook={`${dataHook}-previous-loading`} />
581
+ ) : (
582
+ <ChevronUp />
583
+ )}
519
584
  </Button>
520
585
  <Button
521
586
  ref={nextRef}
587
+ aria-busy={nextBusy ? "true" : undefined}
522
588
  ariaLabel={nextAriaLabel ?? "Next item"}
523
589
  dataHook={`${dataHook}-next`}
524
590
  disabled={!canNext}
@@ -527,7 +593,11 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
527
593
  onClick={(event) => step("next", event.currentTarget)}
528
594
  onKeyDown={handleKeyDown}
529
595
  >
530
- <ChevronDown />
596
+ {nextBusy ? (
597
+ <Spinner dataHook={`${dataHook}-next-loading`} />
598
+ ) : (
599
+ <ChevronDown />
600
+ )}
531
601
  </Button>
532
602
  {position != null && (
533
603
  <span
@@ -538,6 +608,14 @@ const SheetPagination = React.forwardRef<HTMLDivElement, SheetPaginationProps>(
538
608
  {position}
539
609
  </span>
540
610
  )}
611
+ {/* Always mounted so the announcement fires when loading starts. */}
612
+ <span
613
+ className="sr-only"
614
+ data-slot="sheet-pagination-status"
615
+ role="status"
616
+ >
617
+ {loading ? (loadingLabel ?? "Loading item") : null}
618
+ </span>
541
619
  </div>
542
620
  );
543
621
  }
@@ -23,7 +23,7 @@ import {
23
23
  InputGroupInput,
24
24
  } from "@brightlocal/ui-components/input-group";
25
25
  import { Label } from "@brightlocal/ui-components/label";
26
- import { EmptyChip } from "../lib/empty-chip";
26
+ import { EmptyState } from "../blocks/empty-state";
27
27
  import {
28
28
  RadioGroup,
29
29
  RadioGroupItem,
@@ -384,21 +384,14 @@ function SingleSelectFilterInner<Value extends string = string>({
384
384
  ) : null}
385
385
  <DrawerBody className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto pt-1 pb-2">
386
386
  {searching && visibleOptions.length === 0 ? (
387
- <div
388
- className="text-body-sm flex flex-col items-center gap-1 py-6 text-center"
389
- data-hook={`${dataHook}-empty`}
390
- >
391
- <EmptyChip
392
- className="mb-1"
393
- dataHook={`${dataHook}-empty-icon`}
394
- icon={<SearchX />}
395
- slot="single-select-filter-empty-icon"
396
- />
397
- <p>{emptyLabel ?? "No options found."}</p>
398
- <p className="text-muted-foreground">
399
- {emptyDescription ?? "Try another search."}
400
- </p>
401
- </div>
387
+ <EmptyState
388
+ className="py-6"
389
+ dataHook={`${dataHook}-empty`}
390
+ description={emptyDescription ?? "Try another search."}
391
+ icon={<SearchX />}
392
+ size="sm"
393
+ title={emptyLabel ?? "No options found."}
394
+ />
402
395
  ) : (
403
396
  <RadioGroup
404
397
  className="grid grid-cols-2 gap-x-4 gap-y-3"
@@ -11,6 +11,7 @@ import {
11
11
  scrollRegionProps,
12
12
  type TableFrame,
13
13
  type TableSize,
14
+ useTableViewInlineSize,
14
15
  } from "../lib/table-internal";
15
16
 
16
17
  /* -------------------------------------------------------------------------------------------------
@@ -187,9 +188,14 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
187
188
  ) => {
188
189
  const ownsScroll = scrollOwner === "self";
189
190
  const ownFrame = frame === "own";
191
+ // DS-1105: as the scroll container, publish the visible width TableEmpty
192
+ // caps its message at.
193
+ const wrapperRef = React.useRef<HTMLDivElement>(null);
194
+ useTableViewInlineSize(wrapperRef, ownsScroll);
190
195
  return (
191
196
  <TableSizeContext.Provider value={size}>
192
197
  <div
198
+ ref={wrapperRef}
193
199
  className={cn(
194
200
  "relative w-full",
195
201
  // `overflow-x-auto` makes the wrapper a scroll container in BOTH
@@ -568,7 +574,16 @@ const TableEmpty = React.forwardRef<HTMLTableRowElement, TableEmptyProps>(
568
574
  {/* Polite live region: the outcome of the reader's own query. */}
569
575
  <div
570
576
  aria-live="polite"
571
- className={cn(!isLine && "py-6")}
577
+ className={cn(
578
+ !isLine && "py-6",
579
+ // DS-1105: pinned to the visible part of a table that scrolls
580
+ // sideways. The scroll container publishes its visible width as
581
+ // `--table-view-inline-size` (useTableViewInlineSize); capped at
582
+ // it, this block is exactly one viewport wide, so its centred
583
+ // content sits in view at any scroll offset. Unset (nothing
584
+ // measuring) the cap is `none` — the plain full-width row.
585
+ "sticky left-0 max-w-(--table-view-inline-size,none)"
586
+ )}
572
587
  data-slot="table-empty-message"
573
588
  role="status"
574
589
  >
@@ -29,24 +29,79 @@ const TabsContext = React.createContext<TabsContextValue>({
29
29
  variant: "default",
30
30
  });
31
31
 
32
- const tabsListVariants = cva("inline-flex items-center justify-center", {
33
- variants: {
34
- variant: {
35
- default: "h-9 w-fit bg-muted rounded-lg p-1",
36
- underline: "border-border w-full gap-1 rounded-none border-b",
32
+ /**
33
+ * Horizontal alignment of triggers inside the tab list.
34
+ * - `"start"` — triggers sit at the left edge (default for underline)
35
+ * - `"center"` — triggers are centred; falls back to start on overflow
36
+ * (default for pill)
37
+ *
38
+ * @deprecated No consumer uses this — the variant-aware defaults cover every
39
+ * real case. Will be removed in a future major. Use `className="justify-center"`
40
+ * if you need to override.
41
+ */
42
+ type TabsListAlign = "start" | "center";
43
+
44
+ const tabsListVariants = cva(
45
+ [
46
+ "inline-flex max-w-full items-center",
47
+ // A row wider than its container scrolls sideways instead of widening
48
+ // the page (six tabs on a phone). Only an overflowing list becomes a
49
+ // scroll container (data-overflowing), because a scroll container clips
50
+ // the focus ring of a list that fits. The scrollbar stays hidden; touch,
51
+ // trackpad and arrow keys scroll the row. overscroll-x-contain is scoped
52
+ // to the list, so the page keeps its back/forward swipe gestures.
53
+ "overscroll-x-contain [scrollbar-width:none]",
54
+ "data-overflowing:overflow-x-auto data-overflowing:overflow-y-hidden",
55
+ ],
56
+ {
57
+ variants: {
58
+ variant: {
59
+ default: "h-9 w-fit bg-muted rounded-lg p-1",
60
+ // The bottom rule is an inset shadow, not a border: a scrolling list
61
+ // clips at its padding box, so a border would cut the active
62
+ // underline in half.
63
+ underline:
64
+ "w-full gap-1 rounded-none shadow-[inset_0_-1px_0_var(--border)]",
65
+ },
66
+ align: {
67
+ start: "justify-start",
68
+ center: "justify-center-safe",
69
+ },
70
+ fullWidth: {
71
+ // Triggers share the row equally (basis-0 + grow) and wrap long labels
72
+ // inside their cell instead of overflowing or truncating.
73
+ true: [
74
+ "flex w-full items-stretch",
75
+ // wrap-anywhere breaks a single long word too, so it never spills
76
+ // into the next trigger.
77
+ "*:min-w-0 *:flex-1 *:basis-0 *:whitespace-normal *:wrap-anywhere *:text-center",
78
+ ],
79
+ false: "",
80
+ },
37
81
  },
38
- },
39
- defaultVariants: {
40
- variant: "default",
41
- },
42
- });
82
+ compoundVariants: [
83
+ // The pill row grows with wrapped labels instead of clipping at 36px.
84
+ // py-0.5 keeps a one-line row at h-9: stretched triggers (30px tall)
85
+ // fit the 32px content box instead of pushing the row to 38px.
86
+ {
87
+ variant: "default",
88
+ fullWidth: true,
89
+ className: "h-auto min-h-9 py-0.5",
90
+ },
91
+ ],
92
+ defaultVariants: {
93
+ variant: "default",
94
+ fullWidth: false,
95
+ },
96
+ }
97
+ );
43
98
 
44
99
  const tabsTriggerVariants = cva(
45
100
  [
46
101
  "inline-flex items-center justify-center gap-2",
47
102
  "text-label whitespace-nowrap",
48
103
  "cursor-pointer",
49
- "focus-visible:outline-none",
104
+ "outline-none",
50
105
  "disabled:pointer-events-none disabled:opacity-50",
51
106
  ],
52
107
  {
@@ -64,13 +119,15 @@ const tabsTriggerVariants = cva(
64
119
  "dark:data-[state=active]:border-white/15 dark:data-[state=active]:bg-white/5",
65
120
  ],
66
121
  underline: [
67
- "-mb-px px-3 py-1.5",
122
+ "px-3 py-1.5",
68
123
  "rounded-none border-b-2 border-transparent bg-transparent",
69
124
  "first:rounded-l-none last:rounded-r-none",
70
125
  "text-muted-foreground hover:bg-transparent hover:text-foreground",
71
126
  "data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground",
72
127
  "transition-[color,border-color,box-shadow] duration-fast ease-out",
73
128
  "focus-visible:rounded-md focus-visible:shadow-default",
129
+ "[&:focus:not(:focus-visible)]:shadow-none",
130
+ "[&[data-pointer-focus]:focus-visible]:shadow-none [&[data-pointer-focus]:focus-visible]:rounded-none",
74
131
  ],
75
132
  },
76
133
  },
@@ -100,9 +157,18 @@ interface TabsProps<T extends string = string> extends Omit<
100
157
  * @default "default"
101
158
  */
102
159
  variant?: TabsVariant;
103
- /** Only mount tab panel content when the tab is first activated (opt-in) */
160
+ /**
161
+ * Only mount a panel when its tab is first activated; once visited it stays
162
+ * mounted (hidden while inactive) unless `unmountOnExit` is also set.
163
+ * @default false
164
+ */
104
165
  lazyMount?: boolean;
105
- /** Unmount tab panel content when the tab becomes inactive */
166
+ /**
167
+ * Unmount a panel's content when its tab becomes inactive. Off by default:
168
+ * inactive panels stay mounted and hidden, so form edits, scroll position
169
+ * and other local state survive a tab switch.
170
+ * @default false
171
+ */
106
172
  unmountOnExit?: boolean;
107
173
  /** The controlled value of the active tab */
108
174
  value?: T;
@@ -136,20 +202,20 @@ function TabsInner<T extends string = string>(
136
202
  () => new Set(activeValue != null ? [activeValue] : [])
137
203
  );
138
204
 
205
+ // Record the active tab as visited however it became active: a trigger
206
+ // click or a parent changing the controlled `value`. Updating state during
207
+ // render (guarded, so it settles in one pass) keeps the panel from being
208
+ // dropped when it is left.
209
+ if (lazyMount && activeValue != null && !visitedTabs.has(activeValue)) {
210
+ setVisitedTabs(new Set(visitedTabs).add(activeValue));
211
+ }
212
+
139
213
  const handleValueChange = React.useCallback(
140
214
  (newValue: string) => {
141
215
  setInternalValue(newValue as T);
142
- if (lazyMount) {
143
- setVisitedTabs((prev) => {
144
- if (prev.has(newValue)) return prev;
145
- const next = new Set(prev);
146
- next.add(newValue);
147
- return next;
148
- });
149
- }
150
216
  onValueChange?.(newValue as T);
151
217
  },
152
- [lazyMount, onValueChange]
218
+ [onValueChange]
153
219
  );
154
220
 
155
221
  const contextValue = React.useMemo(
@@ -167,7 +233,11 @@ function TabsInner<T extends string = string>(
167
233
  <TabsContext.Provider value={contextValue}>
168
234
  <TabsPrimitive.Root
169
235
  ref={ref}
170
- className={cn("flex flex-col gap-2", className)}
236
+ className={cn(
237
+ "flex max-w-full min-w-0 flex-col",
238
+ variant === "underline" ? "gap-6" : "gap-2",
239
+ className
240
+ )}
171
241
  data-hook={dataHook}
172
242
  data-slot="tabs"
173
243
  data-tracking-el={trackingEl}
@@ -192,6 +262,44 @@ const Tabs = React.forwardRef(TabsInner) as <T extends string = string>(
192
262
 
193
263
  (Tabs as React.FC).displayName = "Tabs";
194
264
 
265
+ /**
266
+ * True while an element's children are wider than the element itself.
267
+ * Re-measures when the element or any child resizes, and when children are
268
+ * added or removed.
269
+ */
270
+ function useHorizontalOverflow(element: HTMLElement | null) {
271
+ const [overflowing, setOverflowing] = React.useState(false);
272
+
273
+ React.useLayoutEffect(() => {
274
+ if (!element || typeof ResizeObserver === "undefined") return;
275
+
276
+ const measure = () =>
277
+ setOverflowing(element.scrollWidth > element.clientWidth + 1);
278
+
279
+ const resize = new ResizeObserver(measure);
280
+ const observeAll = () => {
281
+ resize.disconnect();
282
+ resize.observe(element);
283
+ for (const child of Array.from(element.children)) resize.observe(child);
284
+ };
285
+ const mutation = new MutationObserver(() => {
286
+ observeAll();
287
+ measure();
288
+ });
289
+
290
+ observeAll();
291
+ mutation.observe(element, { childList: true });
292
+ measure();
293
+
294
+ return () => {
295
+ resize.disconnect();
296
+ mutation.disconnect();
297
+ };
298
+ }, [element]);
299
+
300
+ return overflowing;
301
+ }
302
+
195
303
  /**
196
304
  * Props for the TabsList component
197
305
  */
@@ -204,26 +312,72 @@ interface TabsListProps extends React.ComponentProps<
204
312
  trackingEl?: string;
205
313
  /** Tracking label for analytics context */
206
314
  trackingLabel?: string;
315
+ /**
316
+ * Horizontal alignment of triggers inside the list.
317
+ * Defaults to `"start"` for the underline variant and `"center"` for the
318
+ * pill variant.
319
+ *
320
+ * @deprecated No consumer uses this — the variant-aware defaults cover every
321
+ * real case. Will be removed in a future major. Use `className` if you need
322
+ * to override alignment.
323
+ */
324
+ align?: TabsListAlign;
325
+ /**
326
+ * Stretch the list to its container and give every trigger an equal share
327
+ * of the width. Long labels wrap inside their trigger; they never truncate.
328
+ * @default false
329
+ */
330
+ fullWidth?: boolean;
207
331
  }
208
332
 
209
333
  const TabsList = React.forwardRef<
210
334
  React.ComponentRef<typeof TabsPrimitive.List>,
211
335
  TabsListProps
212
- >(({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
213
- const { variant } = React.useContext(TabsContext);
214
-
215
- return (
216
- <TabsPrimitive.List
217
- ref={ref}
218
- className={cn(tabsListVariants({ variant }), className)}
219
- data-hook={dataHook}
220
- data-slot="tabs-list"
221
- data-tracking-el={trackingEl}
222
- data-tracking-label={trackingLabel}
223
- {...props}
224
- />
225
- );
226
- });
336
+ >(
337
+ (
338
+ {
339
+ className,
340
+ dataHook,
341
+ trackingEl,
342
+ trackingLabel,
343
+ align: alignProp,
344
+ fullWidth = false,
345
+ ...props
346
+ },
347
+ ref
348
+ ) => {
349
+ const { variant } = React.useContext(TabsContext);
350
+ const resolvedAlign =
351
+ alignProp ?? (variant === "underline" ? "start" : "center");
352
+ const [list, setList] = React.useState<HTMLDivElement | null>(null);
353
+ const overflowing = useHorizontalOverflow(list);
354
+
355
+ const setRefs = React.useCallback(
356
+ (node: HTMLDivElement | null) => {
357
+ setList(node);
358
+ if (typeof ref === "function") ref(node);
359
+ else if (ref) ref.current = node;
360
+ },
361
+ [ref]
362
+ );
363
+
364
+ return (
365
+ <TabsPrimitive.List
366
+ ref={setRefs}
367
+ className={cn(
368
+ tabsListVariants({ variant, align: resolvedAlign, fullWidth }),
369
+ className
370
+ )}
371
+ data-hook={dataHook}
372
+ data-overflowing={overflowing ? "" : undefined}
373
+ data-slot="tabs-list"
374
+ data-tracking-el={trackingEl}
375
+ data-tracking-label={trackingLabel}
376
+ {...props}
377
+ />
378
+ );
379
+ }
380
+ );
227
381
 
228
382
  TabsList.displayName = "TabsList";
229
383
 
@@ -252,12 +406,30 @@ function TabsTriggerInner<T extends string = string>(
252
406
  dataHook,
253
407
  trackingEl,
254
408
  trackingLabel,
409
+ onPointerDown: onPointerDownProp,
410
+ onBlur: onBlurProp,
255
411
  ...props
256
412
  }: TabsTriggerProps<T>,
257
413
  ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Trigger>>
258
414
  ) {
259
415
  const { variant } = React.useContext(TabsContext);
260
416
 
417
+ const handlePointerDown = React.useCallback(
418
+ (e: React.PointerEvent<HTMLButtonElement>) => {
419
+ e.currentTarget.setAttribute("data-pointer-focus", "");
420
+ onPointerDownProp?.(e);
421
+ },
422
+ [onPointerDownProp]
423
+ );
424
+
425
+ const handleBlur = React.useCallback(
426
+ (e: React.FocusEvent<HTMLButtonElement>) => {
427
+ e.currentTarget.removeAttribute("data-pointer-focus");
428
+ onBlurProp?.(e);
429
+ },
430
+ [onBlurProp]
431
+ );
432
+
261
433
  return (
262
434
  <TabsPrimitive.Trigger
263
435
  ref={ref}
@@ -266,6 +438,8 @@ function TabsTriggerInner<T extends string = string>(
266
438
  data-slot="tabs-trigger"
267
439
  data-tracking-el={trackingEl}
268
440
  data-tracking-label={trackingLabel}
441
+ onBlur={handleBlur}
442
+ onPointerDown={handlePointerDown}
269
443
  {...props}
270
444
  />
271
445
  );
@@ -315,7 +489,7 @@ function TabsContentInner<T extends string = string>(
315
489
 
316
490
  const isActive = value === activeValue;
317
491
 
318
- if (lazyMount && !visitedTabs.has(value)) {
492
+ if (lazyMount && !isActive && !visitedTabs.has(value)) {
319
493
  return null;
320
494
  }
321
495
 
@@ -326,11 +500,18 @@ function TabsContentInner<T extends string = string>(
326
500
  return (
327
501
  <TabsPrimitive.Content
328
502
  ref={ref}
329
- className={cn("flex-1 outline-none", className)}
503
+ className={cn(
504
+ "flex-1 outline-none data-[state=inactive]:hidden",
505
+ className
506
+ )}
330
507
  data-hook={dataHook}
331
508
  data-slot="tabs-content"
332
509
  data-tracking-el={trackingEl}
333
510
  data-tracking-label={trackingLabel}
511
+ // Radix unmounts inactive content unless forceMount. Keep it mounted
512
+ // (unless unmountOnExit); the class above hides it with display: none,
513
+ // which also takes it out of the accessibility tree and the tab order.
514
+ forceMount={unmountOnExit ? undefined : true}
334
515
  value={value}
335
516
  {...props}
336
517
  />
@@ -351,6 +532,7 @@ export { Tabs, TabsList, TabsTrigger, TabsContent };
351
532
  export type {
352
533
  TabsProps,
353
534
  TabsListProps,
535
+ TabsListAlign,
354
536
  TabsTriggerProps,
355
537
  TabsContentProps,
356
538
  TabsVariant,