@brightlocal/ui-components 2.12.0 → 2.13.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 (43) hide show
  1. package/component-meta.json +312 -16
  2. package/dist/blocks/sidebar.cjs +1 -1
  3. package/dist/blocks/sidebar.d.ts +203 -4
  4. package/dist/blocks/sidebar.d.ts.map +1 -1
  5. package/dist/blocks/sidebar.js +667 -393
  6. package/dist/combobox.cjs +3 -3
  7. package/dist/combobox.d.ts +8 -0
  8. package/dist/combobox.d.ts.map +1 -1
  9. package/dist/combobox.js +227 -226
  10. package/dist/dropdown-menu.cjs +1 -1
  11. package/dist/dropdown-menu.js +1 -1
  12. package/dist/index.cjs +1 -1
  13. package/dist/index.js +296 -288
  14. package/dist/list.cjs +1 -1
  15. package/dist/list.d.ts +25 -4
  16. package/dist/list.d.ts.map +1 -1
  17. package/dist/list.js +71 -53
  18. package/dist/popover.cjs +1 -1
  19. package/dist/popover.js +7 -7
  20. package/dist/rating.cjs +1 -1
  21. package/dist/rating.js +13 -13
  22. package/dist/select.cjs +2 -2
  23. package/dist/select.d.ts +10 -2
  24. package/dist/select.d.ts.map +1 -1
  25. package/dist/select.js +36 -30
  26. package/dist/table.cjs +1 -1
  27. package/dist/table.d.ts +14 -0
  28. package/dist/table.d.ts.map +1 -1
  29. package/dist/table.js +57 -39
  30. package/dist/tabs.cjs +1 -1
  31. package/dist/tabs.d.ts +25 -9
  32. package/dist/tabs.d.ts.map +1 -1
  33. package/dist/tabs.js +128 -113
  34. package/package.json +1 -1
  35. package/src/blocks/sidebar.tsx +596 -9
  36. package/src/components/combobox.tsx +10 -0
  37. package/src/components/dropdown-menu.tsx +1 -1
  38. package/src/components/list.tsx +45 -2
  39. package/src/components/popover.tsx +1 -1
  40. package/src/components/rating.tsx +1 -1
  41. package/src/components/select.tsx +24 -2
  42. package/src/components/table.tsx +39 -2
  43. package/src/components/tabs.tsx +195 -146
@@ -1352,6 +1352,14 @@ export interface ComboboxItemProps extends Omit<
1352
1352
  highlightClassName?: string;
1353
1353
  /** Additional keywords to match against when filtering. The item label is always included automatically. */
1354
1354
  keywords?: string[];
1355
+ /**
1356
+ * Callback fired when the item is activated (clicked or chosen via keyboard).
1357
+ * Fires on every activation, including when the item is being deselected
1358
+ * (toggled off). Always receives the item's own value, not the resulting
1359
+ * combobox value — use `Combobox`'s `onValueChange` for selection state.
1360
+ * @param value - The value of the activated item
1361
+ */
1362
+ onSelect?: (value: string) => void;
1355
1363
  }
1356
1364
 
1357
1365
  const ComboboxItem = React.forwardRef<
@@ -1368,6 +1376,7 @@ const ComboboxItem = React.forwardRef<
1368
1376
  highlight,
1369
1377
  highlightClassName,
1370
1378
  keywords,
1379
+ onSelect,
1371
1380
  ...props
1372
1381
  },
1373
1382
  ref
@@ -1407,6 +1416,7 @@ const ComboboxItem = React.forwardRef<
1407
1416
  const newValue = itemValue === value ? "" : itemValue;
1408
1417
  onValueChange(newValue);
1409
1418
  setOpen(false);
1419
+ onSelect?.(itemValue);
1410
1420
  };
1411
1421
 
1412
1422
  // Render children with optional highlighting
@@ -61,10 +61,10 @@ const DropdownMenuTrigger = React.forwardRef<
61
61
  <DropdownMenuPrimitive.Trigger
62
62
  ref={ref}
63
63
  className={className}
64
- data-hook={dataHook}
65
64
  data-slot="dropdown-menu-trigger"
66
65
  data-tracking-el={trackingEl}
67
66
  data-tracking-label={trackingLabel}
67
+ {...(dataHook != null && { "data-hook": dataHook })}
68
68
  {...props}
69
69
  />
70
70
  );
@@ -25,6 +25,7 @@ const itemVariants = cva(
25
25
  {
26
26
  variants: {
27
27
  variant: {
28
+ default: [],
28
29
  filled: ["bg-card"],
29
30
  outline: ["bg-background", "border", "border-border"],
30
31
  loading: ["flex-col", "gap-2", "px-0", "pt-0", "pb-3"],
@@ -107,12 +108,13 @@ export type ItemProps = React.ComponentProps<"li"> & {
107
108
  asChild?: boolean;
108
109
  /**
109
110
  * Visual style of the item row.
111
+ * - `default` — plain row without background or border
110
112
  * - `filled` — card background (default)
111
113
  * - `outline` — bordered row on page background
112
114
  * - `loading` — skeleton placeholder
113
115
  * @default "filled"
114
116
  */
115
- variant?: "filled" | "outline" | "loading";
117
+ variant?: "default" | "filled" | "outline" | "loading";
116
118
  /**
117
119
  * Data hook for automated testing.
118
120
  */
@@ -128,7 +130,7 @@ export type ItemProps = React.ComponentProps<"li"> & {
128
130
  };
129
131
 
130
132
  /**
131
- * Row component within a List. Supports `filled`, `outline`, and `loading` variants.
133
+ * Row component within a List. Supports `default`, `filled`, `outline`, and `loading` variants.
132
134
  * Compose with ItemMedia, ItemContent, ItemTitle, ItemDescription, and ItemActions.
133
135
  */
134
136
  const Item = React.forwardRef<HTMLLIElement, ItemProps>(
@@ -285,6 +287,46 @@ const ItemActions = React.forwardRef<HTMLDivElement, ItemActionsProps>(
285
287
  );
286
288
  ItemActions.displayName = "ItemActions";
287
289
 
290
+ /* -------------------------------------------------------------------------------------------------
291
+ * ItemSubheader
292
+ * -----------------------------------------------------------------------------------------------*/
293
+
294
+ /** Props for the ItemSubheader sub-component — section heading within a List. */
295
+ export type ItemSubheaderProps = React.ComponentProps<"li"> & {
296
+ /**
297
+ * Data hook for automated testing.
298
+ */
299
+ dataHook?: string;
300
+ };
301
+
302
+ /**
303
+ * Section heading for grouping related items within a List.
304
+ * Renders as a non-interactive `<li>` with muted label styling.
305
+ *
306
+ * @example
307
+ * ```tsx
308
+ * <List dataHook="actions-list">
309
+ * <ItemSubheader>Suggestions</ItemSubheader>
310
+ * <Item variant="default" dataHook="item-1">...</Item>
311
+ * </List>
312
+ * ```
313
+ */
314
+ const ItemSubheader = React.forwardRef<HTMLLIElement, ItemSubheaderProps>(
315
+ ({ className, dataHook, ...props }, ref) => (
316
+ <li
317
+ ref={ref}
318
+ className={cn(
319
+ "text-muted-foreground flex items-center py-2 pr-2 pl-4 text-base leading-none font-medium",
320
+ className
321
+ )}
322
+ data-hook={dataHook}
323
+ data-slot="item-subheader"
324
+ {...props}
325
+ />
326
+ )
327
+ );
328
+ ItemSubheader.displayName = "ItemSubheader";
329
+
288
330
  /* -------------------------------------------------------------------------------------------------
289
331
  * Exports
290
332
  * -----------------------------------------------------------------------------------------------*/
@@ -297,5 +339,6 @@ export {
297
339
  ItemTitle,
298
340
  ItemDescription,
299
341
  ItemActions,
342
+ ItemSubheader,
300
343
  itemVariants,
301
344
  };
@@ -44,8 +44,8 @@ const PopoverTrigger = React.forwardRef<
44
44
  >(({ dataHook, ...props }, ref) => (
45
45
  <PopoverPrimitive.Trigger
46
46
  ref={ref}
47
- data-hook={dataHook}
48
47
  data-slot="popover-trigger"
48
+ {...(dataHook != null && { "data-hook": dataHook })}
49
49
  {...props}
50
50
  />
51
51
  ));
@@ -92,7 +92,7 @@ const Rating = React.forwardRef<HTMLDivElement, RatingProps>(
92
92
  width: `${fillPercentage}%`,
93
93
  }}
94
94
  >
95
- <StarRating className="fill-yellow-400 stroke-yellow-400" />
95
+ <StarRating />
96
96
  </div>
97
97
  )}
98
98
  </div>
@@ -19,6 +19,17 @@ interface SelectProps extends React.ComponentProps<
19
19
  children?: React.ReactNode;
20
20
  }
21
21
 
22
+ interface SelectContentProps extends React.ComponentProps<
23
+ typeof SelectPrimitive.Content
24
+ > {
25
+ /**
26
+ * Maximum height of the dropdown in pixels.
27
+ * Constrains the dropdown height and shows scroll indicators when content overflows.
28
+ * The dropdown uses the smaller of this value and the available viewport space.
29
+ */
30
+ maxHeight?: number;
31
+ }
32
+
22
33
  // ============================================================================
23
34
  // Main Select Component
24
35
  // ============================================================================
@@ -191,8 +202,10 @@ function SelectContent({
191
202
  className,
192
203
  children,
193
204
  position = "popper",
205
+ maxHeight,
206
+ style,
194
207
  ...props
195
- }: React.ComponentProps<typeof SelectPrimitive.Content>) {
208
+ }: SelectContentProps) {
196
209
  const viewportRef = React.useRef<HTMLDivElement>(null);
197
210
 
198
211
  useDevWarning(
@@ -238,12 +251,21 @@ function SelectContent({
238
251
  "data-[side=top]:-translate-y-1"
239
252
  );
240
253
 
254
+ const contentStyle: React.CSSProperties | undefined =
255
+ maxHeight !== undefined
256
+ ? {
257
+ ...style,
258
+ maxHeight: `min(${maxHeight}px, var(--radix-select-content-available-height))`,
259
+ }
260
+ : style;
261
+
241
262
  return (
242
263
  <SelectPrimitive.Portal>
243
264
  <SelectPrimitive.Content
244
265
  className={cn(baseStyles, popperStyles, className)}
245
266
  data-slot="select-content"
246
267
  position={position}
268
+ style={contentStyle}
247
269
  {...props}
248
270
  >
249
271
  <SelectScrollUpButton />
@@ -420,4 +442,4 @@ export {
420
442
  SelectValue,
421
443
  };
422
444
 
423
- export type { SelectProps, SelectTriggerProps };
445
+ export type { SelectContentProps, SelectProps, SelectTriggerProps };
@@ -64,14 +64,50 @@ interface TableProps extends React.ComponentProps<"table"> {
64
64
  * Tracking label for analytics context
65
65
  */
66
66
  trackingLabel?: string;
67
+ /**
68
+ * Minimum width for the table (e.g., "600px", "40rem").
69
+ * Prevents columns from compressing on narrow viewports and enables
70
+ * horizontal scroll via the built-in overflow container.
71
+ * When set, the scroll container becomes a focusable region for
72
+ * keyboard accessibility.
73
+ */
74
+ minWidth?: string;
75
+ /**
76
+ * Accessible label for the scroll container region.
77
+ * Used when `minWidth` is set to provide context for keyboard users.
78
+ * @default "Scrollable table"
79
+ */
80
+ scrollRegionLabel?: string;
67
81
  }
68
82
 
69
83
  const Table = React.forwardRef<HTMLTableElement, TableProps>(
70
- ({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
84
+ (
85
+ {
86
+ className,
87
+ dataHook,
88
+ trackingEl,
89
+ trackingLabel,
90
+ minWidth,
91
+ scrollRegionLabel,
92
+ style,
93
+ ...props
94
+ },
95
+ ref
96
+ ) => {
71
97
  return (
72
98
  <div
73
- className="relative w-full overflow-x-auto"
99
+ className={cn(
100
+ "relative w-full overflow-x-auto",
101
+ minWidth && "focus-visible:shadow-default rounded-md outline-none"
102
+ )}
74
103
  data-slot="table-container"
104
+ {...(minWidth
105
+ ? {
106
+ role: "region",
107
+ "aria-label": scrollRegionLabel ?? "Scrollable table",
108
+ tabIndex: 0,
109
+ }
110
+ : undefined)}
75
111
  >
76
112
  <table
77
113
  ref={ref}
@@ -80,6 +116,7 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
80
116
  data-slot="table"
81
117
  data-tracking-el={trackingEl}
82
118
  data-tracking-label={trackingLabel}
119
+ style={{ minWidth, ...style }}
83
120
  {...props}
84
121
  />
85
122
  </div>
@@ -20,9 +20,14 @@ const TabsContext = React.createContext<TabsContextValue>({
20
20
  });
21
21
 
22
22
  /**
23
- * Props for the Tabs component
23
+ * Props for the Tabs component.
24
+ * Generic over the tab value type for type-safe `value` and `onValueChange`.
25
+ * @typeParam T - The type of tab values, defaults to `string`
24
26
  */
25
- interface TabsProps extends React.ComponentProps<typeof TabsPrimitive.Root> {
27
+ interface TabsProps<T extends string = string> extends Omit<
28
+ React.ComponentProps<typeof TabsPrimitive.Root>,
29
+ "value" | "defaultValue" | "onValueChange"
30
+ > {
26
31
  /** Data hook for automated testing (required) */
27
32
  dataHook: string;
28
33
  /** Tracking element identifier for analytics */
@@ -33,81 +38,91 @@ interface TabsProps extends React.ComponentProps<typeof TabsPrimitive.Root> {
33
38
  lazyMount?: boolean;
34
39
  /** Unmount tab panel content when the tab becomes inactive */
35
40
  unmountOnExit?: boolean;
41
+ /** The controlled value of the active tab */
42
+ value?: T;
43
+ /** The default value of the active tab (uncontrolled) */
44
+ defaultValue?: T;
45
+ /** Callback when the active tab changes */
46
+ onValueChange?: (value: T) => void;
36
47
  }
37
48
 
38
- const Tabs = React.forwardRef<
39
- React.ComponentRef<typeof TabsPrimitive.Root>,
40
- TabsProps
41
- >(
42
- (
43
- {
44
- className,
45
- dataHook,
46
- trackingEl,
47
- trackingLabel,
48
- lazyMount = false,
49
- unmountOnExit = false,
50
- value: controlledValue,
51
- defaultValue,
52
- onValueChange,
53
- ...props
49
+ function TabsInner<T extends string = string>(
50
+ {
51
+ className,
52
+ dataHook,
53
+ trackingEl,
54
+ trackingLabel,
55
+ lazyMount = false,
56
+ unmountOnExit = false,
57
+ value: controlledValue,
58
+ defaultValue,
59
+ onValueChange,
60
+ ...props
61
+ }: TabsProps<T>,
62
+ ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Root>>
63
+ ) {
64
+ const needsTracking = lazyMount || unmountOnExit;
65
+ const [internalValue, setInternalValue] = React.useState(defaultValue);
66
+ const activeValue = controlledValue ?? internalValue;
67
+
68
+ const [visitedTabs, setVisitedTabs] = React.useState<Set<string>>(
69
+ () => new Set(activeValue != null ? [activeValue] : [])
70
+ );
71
+
72
+ const handleValueChange = React.useCallback(
73
+ (newValue: string) => {
74
+ setInternalValue(newValue as T);
75
+ if (lazyMount) {
76
+ setVisitedTabs((prev) => {
77
+ if (prev.has(newValue)) return prev;
78
+ const next = new Set(prev);
79
+ next.add(newValue);
80
+ return next;
81
+ });
82
+ }
83
+ onValueChange?.(newValue as T);
54
84
  },
55
- ref
56
- ) => {
57
- const needsTracking = lazyMount || unmountOnExit;
58
- const [internalValue, setInternalValue] = React.useState(defaultValue);
59
- const activeValue = controlledValue ?? internalValue;
85
+ [lazyMount, onValueChange]
86
+ );
60
87
 
61
- const [visitedTabs, setVisitedTabs] = React.useState<Set<string>>(
62
- () => new Set(activeValue != null ? [activeValue] : [])
63
- );
88
+ const contextValue = React.useMemo(
89
+ () => ({
90
+ lazyMount,
91
+ unmountOnExit,
92
+ activeValue,
93
+ visitedTabs,
94
+ }),
95
+ [lazyMount, unmountOnExit, activeValue, visitedTabs]
96
+ );
64
97
 
65
- const handleValueChange = React.useCallback(
66
- (newValue: string) => {
67
- setInternalValue(newValue);
68
- if (lazyMount) {
69
- setVisitedTabs((prev) => {
70
- if (prev.has(newValue)) return prev;
71
- const next = new Set(prev);
72
- next.add(newValue);
73
- return next;
74
- });
98
+ return (
99
+ <TabsContext.Provider value={contextValue}>
100
+ <TabsPrimitive.Root
101
+ ref={ref}
102
+ className={cn("flex flex-col gap-2", className)}
103
+ data-hook={dataHook}
104
+ data-slot="tabs"
105
+ data-tracking-el={trackingEl}
106
+ data-tracking-label={trackingLabel}
107
+ defaultValue={needsTracking ? undefined : defaultValue}
108
+ value={needsTracking ? activeValue : controlledValue}
109
+ onValueChange={
110
+ needsTracking
111
+ ? handleValueChange
112
+ : (onValueChange as ((value: string) => void) | undefined)
75
113
  }
76
- onValueChange?.(newValue);
77
- },
78
- [lazyMount, onValueChange]
79
- );
80
-
81
- const contextValue = React.useMemo(
82
- () => ({
83
- lazyMount,
84
- unmountOnExit,
85
- activeValue,
86
- visitedTabs,
87
- }),
88
- [lazyMount, unmountOnExit, activeValue, visitedTabs]
89
- );
114
+ {...props}
115
+ />
116
+ </TabsContext.Provider>
117
+ );
118
+ }
90
119
 
91
- return (
92
- <TabsContext.Provider value={contextValue}>
93
- <TabsPrimitive.Root
94
- ref={ref}
95
- className={cn("flex flex-col gap-2", className)}
96
- data-hook={dataHook}
97
- data-slot="tabs"
98
- data-tracking-el={trackingEl}
99
- data-tracking-label={trackingLabel}
100
- defaultValue={needsTracking ? undefined : defaultValue}
101
- value={needsTracking ? activeValue : controlledValue}
102
- onValueChange={needsTracking ? handleValueChange : onValueChange}
103
- {...props}
104
- />
105
- </TabsContext.Provider>
106
- );
107
- }
108
- );
120
+ const Tabs = React.forwardRef(TabsInner) as <T extends string = string>(
121
+ props: TabsProps<T> &
122
+ React.RefAttributes<React.ComponentRef<typeof TabsPrimitive.Root>>
123
+ ) => React.ReactElement | null;
109
124
 
110
- Tabs.displayName = "Tabs";
125
+ (Tabs as React.FC).displayName = "Tabs";
111
126
 
112
127
  /**
113
128
  * Props for the TabsList component
@@ -149,10 +164,13 @@ const TabsList = React.forwardRef<
149
164
  TabsList.displayName = "TabsList";
150
165
 
151
166
  /**
152
- * Props for the TabsTrigger component
167
+ * Props for the TabsTrigger component.
168
+ * Generic over the tab value type for type-safe `value` prop.
169
+ * @typeParam T - The type of tab values, defaults to `string`
153
170
  */
154
- interface TabsTriggerProps extends React.ComponentProps<
155
- typeof TabsPrimitive.Trigger
171
+ interface TabsTriggerProps<T extends string = string> extends Omit<
172
+ React.ComponentProps<typeof TabsPrimitive.Trigger>,
173
+ "value"
156
174
  > {
157
175
  /** Data hook for automated testing */
158
176
  dataHook?: string;
@@ -160,54 +178,74 @@ interface TabsTriggerProps extends React.ComponentProps<
160
178
  trackingEl?: string;
161
179
  /** Tracking label for analytics context */
162
180
  trackingLabel?: string;
181
+ /** The value that identifies this tab */
182
+ value: T;
163
183
  }
164
184
 
165
- const TabsTrigger = React.forwardRef<
166
- React.ComponentRef<typeof TabsPrimitive.Trigger>,
167
- TabsTriggerProps
168
- >(({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => (
169
- <TabsPrimitive.Trigger
170
- ref={ref}
171
- className={cn(
172
- // Layout
173
- "inline-flex items-center justify-center gap-2 px-2 py-1",
174
- // Typography
175
- "text-sm font-medium whitespace-nowrap",
176
- // Border radius
177
- "rounded-md",
178
- // Border
179
- "border border-transparent",
180
- // Text color
181
- "text-foreground",
182
- // Transition with explicit duration and easing
183
- "transition-[color,box-shadow] duration-150 ease-in-out",
184
- // Active state
185
- "data-[state=active]:bg-background data-[state=active]:shadow-sm",
186
- // Focus state - use compound selector for active+focused to override shadow-sm with shadow-default
187
- "focus-visible:border-ring focus-visible:outline-none",
188
- "data-[state=inactive]:focus-visible:shadow-default",
189
- "data-[state=active]:focus-visible:shadow-default",
190
- // Dark mode active state
191
- "dark:data-[state=active]:border-white/15 dark:data-[state=active]:bg-white/5",
192
- // Disabled state
193
- "disabled:pointer-events-none disabled:opacity-50",
194
- className
195
- )}
196
- data-hook={dataHook}
197
- data-slot="tabs-trigger"
198
- data-tracking-el={trackingEl}
199
- data-tracking-label={trackingLabel}
200
- {...props}
201
- />
202
- ));
185
+ function TabsTriggerInner<T extends string = string>(
186
+ {
187
+ className,
188
+ dataHook,
189
+ trackingEl,
190
+ trackingLabel,
191
+ ...props
192
+ }: TabsTriggerProps<T>,
193
+ ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Trigger>>
194
+ ) {
195
+ return (
196
+ <TabsPrimitive.Trigger
197
+ ref={ref}
198
+ className={cn(
199
+ // Layout
200
+ "inline-flex items-center justify-center gap-2 px-2 py-1",
201
+ // Typography
202
+ "text-sm font-medium whitespace-nowrap",
203
+ // Border radius
204
+ "rounded-md",
205
+ // Border
206
+ "border border-transparent",
207
+ // Text color
208
+ "text-foreground",
209
+ // Transition with explicit duration and easing
210
+ "transition-[color,box-shadow] duration-150 ease-in-out",
211
+ // Active state
212
+ "data-[state=active]:bg-background data-[state=active]:shadow-sm",
213
+ // Focus state - use compound selector for active+focused to override shadow-sm with shadow-default
214
+ "focus-visible:border-ring focus-visible:outline-none",
215
+ "data-[state=inactive]:focus-visible:shadow-default",
216
+ "data-[state=active]:focus-visible:shadow-default",
217
+ // Dark mode active state
218
+ "dark:data-[state=active]:border-white/15 dark:data-[state=active]:bg-white/5",
219
+ // Disabled state
220
+ "disabled:pointer-events-none disabled:opacity-50",
221
+ className
222
+ )}
223
+ data-hook={dataHook}
224
+ data-slot="tabs-trigger"
225
+ data-tracking-el={trackingEl}
226
+ data-tracking-label={trackingLabel}
227
+ {...props}
228
+ />
229
+ );
230
+ }
203
231
 
204
- TabsTrigger.displayName = "TabsTrigger";
232
+ const TabsTrigger = React.forwardRef(TabsTriggerInner) as <
233
+ T extends string = string,
234
+ >(
235
+ props: TabsTriggerProps<T> &
236
+ React.RefAttributes<React.ComponentRef<typeof TabsPrimitive.Trigger>>
237
+ ) => React.ReactElement | null;
238
+
239
+ (TabsTrigger as React.FC).displayName = "TabsTrigger";
205
240
 
206
241
  /**
207
- * Props for the TabsContent component
242
+ * Props for the TabsContent component.
243
+ * Generic over the tab value type for type-safe `value` prop.
244
+ * @typeParam T - The type of tab values, defaults to `string`
208
245
  */
209
- interface TabsContentProps extends React.ComponentProps<
210
- typeof TabsPrimitive.Content
246
+ interface TabsContentProps<T extends string = string> extends Omit<
247
+ React.ComponentProps<typeof TabsPrimitive.Content>,
248
+ "value"
211
249
  > {
212
250
  /** Data hook for automated testing */
213
251
  dataHook?: string;
@@ -215,45 +253,56 @@ interface TabsContentProps extends React.ComponentProps<
215
253
  trackingEl?: string;
216
254
  /** Tracking label for analytics context */
217
255
  trackingLabel?: string;
256
+ /** The value that identifies which tab this content belongs to */
257
+ value: T;
218
258
  }
219
259
 
220
- const TabsContent = React.forwardRef<
221
- React.ComponentRef<typeof TabsPrimitive.Content>,
222
- TabsContentProps
223
- >(
224
- (
225
- { className, dataHook, trackingEl, trackingLabel, value, ...props },
226
- ref
227
- ) => {
228
- const { lazyMount, unmountOnExit, activeValue, visitedTabs } =
229
- React.useContext(TabsContext);
260
+ function TabsContentInner<T extends string = string>(
261
+ {
262
+ className,
263
+ dataHook,
264
+ trackingEl,
265
+ trackingLabel,
266
+ value,
267
+ ...props
268
+ }: TabsContentProps<T>,
269
+ ref: React.ForwardedRef<React.ComponentRef<typeof TabsPrimitive.Content>>
270
+ ) {
271
+ const { lazyMount, unmountOnExit, activeValue, visitedTabs } =
272
+ React.useContext(TabsContext);
230
273
 
231
- const isActive = value === activeValue;
274
+ const isActive = value === activeValue;
232
275
 
233
- if (lazyMount && !visitedTabs.has(value!)) {
234
- return null;
235
- }
236
-
237
- if (unmountOnExit && !isActive) {
238
- return null;
239
- }
276
+ if (lazyMount && !visitedTabs.has(value)) {
277
+ return null;
278
+ }
240
279
 
241
- return (
242
- <TabsPrimitive.Content
243
- ref={ref}
244
- className={cn("flex-1 outline-none", className)}
245
- data-hook={dataHook}
246
- data-slot="tabs-content"
247
- data-tracking-el={trackingEl}
248
- data-tracking-label={trackingLabel}
249
- value={value}
250
- {...props}
251
- />
252
- );
280
+ if (unmountOnExit && !isActive) {
281
+ return null;
253
282
  }
254
- );
255
283
 
256
- TabsContent.displayName = "TabsContent";
284
+ return (
285
+ <TabsPrimitive.Content
286
+ ref={ref}
287
+ className={cn("flex-1 outline-none", className)}
288
+ data-hook={dataHook}
289
+ data-slot="tabs-content"
290
+ data-tracking-el={trackingEl}
291
+ data-tracking-label={trackingLabel}
292
+ value={value}
293
+ {...props}
294
+ />
295
+ );
296
+ }
297
+
298
+ const TabsContent = React.forwardRef(TabsContentInner) as <
299
+ T extends string = string,
300
+ >(
301
+ props: TabsContentProps<T> &
302
+ React.RefAttributes<React.ComponentRef<typeof TabsPrimitive.Content>>
303
+ ) => React.ReactElement | null;
304
+
305
+ (TabsContent as React.FC).displayName = "TabsContent";
257
306
 
258
307
  export { Tabs, TabsList, TabsTrigger, TabsContent };
259
308