@carbon/react 1.84.0-rc.0 → 1.85.0-rc.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 (177) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +943 -943
  2. package/es/components/AILabel/index.js +6 -1
  3. package/es/components/Checkbox/Checkbox.d.ts +2 -2
  4. package/es/components/Checkbox/Checkbox.js +8 -8
  5. package/es/components/CheckboxGroup/CheckboxGroup.d.ts +2 -2
  6. package/es/components/CheckboxGroup/CheckboxGroup.js +9 -8
  7. package/es/components/CodeSnippet/CodeSnippet.js +2 -4
  8. package/es/components/ComboBox/ComboBox.d.ts +1 -1
  9. package/es/components/ComboBox/ComboBox.js +8 -7
  10. package/es/components/ComposedModal/ComposedModal.d.ts +1 -1
  11. package/es/components/ComposedModal/ComposedModal.js +34 -12
  12. package/es/components/ContainedList/ContainedList.d.ts +1 -1
  13. package/es/components/ContainedList/ContainedList.js +4 -2
  14. package/es/components/ContentSwitcher/ContentSwitcher.js +6 -5
  15. package/es/components/DataTable/DataTable.js +3 -0
  16. package/es/components/DataTable/TableDecoratorRow.d.ts +2 -2
  17. package/es/components/DataTable/TableDecoratorRow.js +8 -8
  18. package/es/components/DataTable/TableExpandRow.d.ts +1 -1
  19. package/es/components/DataTable/TableExpandRow.js +15 -6
  20. package/es/components/DataTable/TableHeader.js +10 -10
  21. package/es/components/DataTable/TableRow.js +12 -4
  22. package/es/components/DataTable/tools/normalize.js +2 -1
  23. package/es/components/DatePickerInput/DatePickerInput.js +8 -7
  24. package/es/components/Dialog/index.d.ts +5 -1
  25. package/es/components/Dialog/index.js +20 -0
  26. package/es/components/Dropdown/Dropdown.d.ts +1 -1
  27. package/es/components/Dropdown/Dropdown.js +8 -10
  28. package/es/components/FileUploader/FileUploaderButton.js +2 -2
  29. package/es/components/FileUploader/FileUploaderDropContainer.js +2 -2
  30. package/es/components/FileUploader/FileUploaderItem.js +2 -2
  31. package/es/components/Layer/index.d.ts +1 -3
  32. package/es/components/Layer/index.js +9 -8
  33. package/es/components/Menu/Menu.js +0 -6
  34. package/es/components/Modal/Modal.d.ts +2 -2
  35. package/es/components/Modal/Modal.js +39 -11
  36. package/es/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
  37. package/es/components/MultiSelect/FilterableMultiSelect.js +29 -7
  38. package/es/components/MultiSelect/MultiSelect.d.ts +1 -1
  39. package/es/components/MultiSelect/MultiSelect.js +8 -7
  40. package/es/components/NumberInput/NumberInput.d.ts +1 -1
  41. package/es/components/NumberInput/NumberInput.js +9 -8
  42. package/es/components/OverflowMenu/OverflowMenu.js +4 -5
  43. package/es/components/PageHeader/PageHeader.d.ts +10 -9
  44. package/es/components/PageHeader/PageHeader.js +94 -34
  45. package/es/components/PageHeader/index.d.ts +2 -2
  46. package/es/components/PageHeader/index.js +1 -1
  47. package/es/components/Popover/index.js +2 -1
  48. package/es/components/RadioButton/RadioButton.d.ts +2 -2
  49. package/es/components/RadioButton/RadioButton.js +8 -8
  50. package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +2 -2
  51. package/es/components/RadioButtonGroup/RadioButtonGroup.js +9 -8
  52. package/es/components/RadioTile/RadioTile.d.ts +1 -1
  53. package/es/components/RadioTile/RadioTile.js +8 -7
  54. package/es/components/Search/Search.js +0 -1
  55. package/es/components/Select/Select.d.ts +2 -2
  56. package/es/components/Select/Select.js +8 -7
  57. package/es/components/Slider/Slider.js +6 -0
  58. package/es/components/Tag/DismissibleTag.d.ts +1 -1
  59. package/es/components/Tag/DismissibleTag.js +9 -8
  60. package/es/components/Tag/Tag.d.ts +1 -1
  61. package/es/components/Tag/Tag.js +9 -8
  62. package/es/components/TextArea/TextArea.js +12 -11
  63. package/es/components/TextInput/TextInput.d.ts +1 -1
  64. package/es/components/TextInput/TextInput.js +20 -9
  65. package/es/components/Tile/Tile.d.ts +2 -2
  66. package/es/components/Tile/Tile.js +30 -36
  67. package/es/components/TileGroup/TileGroup.d.ts +4 -4
  68. package/es/components/TileGroup/TileGroup.js +45 -53
  69. package/es/components/TileGroup/index.d.ts +3 -3
  70. package/es/components/Toggletip/index.js +2 -2
  71. package/es/components/Tooltip/DefinitionTooltip.js +1 -0
  72. package/es/components/TreeView/TreeNode.js +3 -3
  73. package/es/components/TreeView/TreeView.js +3 -3
  74. package/es/components/UIShell/Content.d.ts +5 -3
  75. package/es/components/UIShell/HeaderMenuItem.js +2 -1
  76. package/es/components/UIShell/HeaderPanel.d.ts +2 -2
  77. package/es/components/UIShell/HeaderPanel.js +9 -5
  78. package/es/index.js +1 -1
  79. package/es/internal/Selection.js +8 -3
  80. package/es/internal/environment.js +1 -12
  81. package/es/internal/{__mocks__/mockHTMLElement.d.ts → index.d.ts} +2 -4
  82. package/es/internal/useOverflowItems.d.ts +29 -0
  83. package/es/internal/useOverflowItems.js +122 -0
  84. package/es/internal/useResizeObserver.d.ts +1 -1
  85. package/es/internal/utils.d.ts +14 -0
  86. package/es/internal/utils.js +18 -0
  87. package/es/tools/uniqueId.d.ts +1 -6
  88. package/lib/components/AILabel/index.js +6 -1
  89. package/lib/components/Checkbox/Checkbox.d.ts +2 -2
  90. package/lib/components/Checkbox/Checkbox.js +7 -7
  91. package/lib/components/CheckboxGroup/CheckboxGroup.d.ts +2 -2
  92. package/lib/components/CheckboxGroup/CheckboxGroup.js +8 -7
  93. package/lib/components/CodeSnippet/CodeSnippet.js +2 -4
  94. package/lib/components/ComboBox/ComboBox.d.ts +1 -1
  95. package/lib/components/ComboBox/ComboBox.js +11 -10
  96. package/lib/components/ComposedModal/ComposedModal.d.ts +1 -1
  97. package/lib/components/ComposedModal/ComposedModal.js +35 -13
  98. package/lib/components/ContainedList/ContainedList.d.ts +1 -1
  99. package/lib/components/ContainedList/ContainedList.js +4 -2
  100. package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -4
  101. package/lib/components/DataTable/DataTable.js +3 -0
  102. package/lib/components/DataTable/TableDecoratorRow.d.ts +2 -2
  103. package/lib/components/DataTable/TableDecoratorRow.js +8 -8
  104. package/lib/components/DataTable/TableExpandRow.d.ts +1 -1
  105. package/lib/components/DataTable/TableExpandRow.js +14 -5
  106. package/lib/components/DataTable/TableHeader.js +9 -9
  107. package/lib/components/DataTable/TableRow.js +11 -3
  108. package/lib/components/DataTable/tools/normalize.js +2 -1
  109. package/lib/components/DatePickerInput/DatePickerInput.js +7 -6
  110. package/lib/components/Dialog/index.d.ts +5 -1
  111. package/lib/components/Dialog/index.js +20 -0
  112. package/lib/components/Dropdown/Dropdown.d.ts +1 -1
  113. package/lib/components/Dropdown/Dropdown.js +12 -14
  114. package/lib/components/FileUploader/FileUploaderButton.js +2 -2
  115. package/lib/components/FileUploader/FileUploaderDropContainer.js +2 -2
  116. package/lib/components/FileUploader/FileUploaderItem.js +2 -2
  117. package/lib/components/Layer/index.d.ts +1 -3
  118. package/lib/components/Layer/index.js +9 -8
  119. package/lib/components/Menu/Menu.js +0 -6
  120. package/lib/components/Modal/Modal.d.ts +2 -2
  121. package/lib/components/Modal/Modal.js +47 -19
  122. package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
  123. package/lib/components/MultiSelect/FilterableMultiSelect.js +33 -11
  124. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  125. package/lib/components/MultiSelect/MultiSelect.js +13 -12
  126. package/lib/components/NumberInput/NumberInput.d.ts +1 -1
  127. package/lib/components/NumberInput/NumberInput.js +8 -7
  128. package/lib/components/OverflowMenu/OverflowMenu.js +4 -5
  129. package/lib/components/PageHeader/PageHeader.d.ts +10 -9
  130. package/lib/components/PageHeader/PageHeader.js +92 -34
  131. package/lib/components/PageHeader/index.d.ts +2 -2
  132. package/lib/components/PageHeader/index.js +0 -2
  133. package/lib/components/Popover/index.js +2 -1
  134. package/lib/components/RadioButton/RadioButton.d.ts +2 -2
  135. package/lib/components/RadioButton/RadioButton.js +7 -7
  136. package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +2 -2
  137. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +10 -9
  138. package/lib/components/RadioTile/RadioTile.d.ts +1 -1
  139. package/lib/components/RadioTile/RadioTile.js +7 -6
  140. package/lib/components/Search/Search.js +0 -1
  141. package/lib/components/Select/Select.d.ts +2 -2
  142. package/lib/components/Select/Select.js +7 -6
  143. package/lib/components/Slider/Slider.js +6 -0
  144. package/lib/components/Tag/DismissibleTag.d.ts +1 -1
  145. package/lib/components/Tag/DismissibleTag.js +8 -7
  146. package/lib/components/Tag/Tag.d.ts +1 -1
  147. package/lib/components/Tag/Tag.js +8 -7
  148. package/lib/components/TextArea/TextArea.js +11 -10
  149. package/lib/components/TextInput/TextInput.d.ts +1 -1
  150. package/lib/components/TextInput/TextInput.js +19 -8
  151. package/lib/components/Tile/Tile.d.ts +2 -2
  152. package/lib/components/Tile/Tile.js +29 -35
  153. package/lib/components/TileGroup/TileGroup.d.ts +4 -4
  154. package/lib/components/TileGroup/TileGroup.js +44 -52
  155. package/lib/components/TileGroup/index.d.ts +3 -3
  156. package/lib/components/Toggletip/index.js +2 -2
  157. package/lib/components/Tooltip/DefinitionTooltip.js +1 -0
  158. package/lib/components/TreeView/TreeNode.js +3 -3
  159. package/lib/components/TreeView/TreeView.js +3 -3
  160. package/lib/components/UIShell/Content.d.ts +5 -3
  161. package/lib/components/UIShell/HeaderMenuItem.js +2 -1
  162. package/lib/components/UIShell/HeaderPanel.d.ts +2 -2
  163. package/lib/components/UIShell/HeaderPanel.js +8 -4
  164. package/lib/index.js +1 -1
  165. package/lib/internal/Selection.js +8 -3
  166. package/lib/internal/environment.js +1 -12
  167. package/lib/internal/{__mocks__/mockHTMLElement.d.ts → index.d.ts} +2 -4
  168. package/lib/internal/useOverflowItems.d.ts +29 -0
  169. package/lib/internal/useOverflowItems.js +126 -0
  170. package/lib/internal/useResizeObserver.d.ts +1 -1
  171. package/lib/internal/utils.d.ts +14 -0
  172. package/lib/internal/utils.js +22 -0
  173. package/lib/tools/uniqueId.d.ts +1 -6
  174. package/package.json +14 -23
  175. package/telemetry.yml +3 -0
  176. package/es/tools/uniqueId.js +0 -14
  177. package/lib/tools/uniqueId.js +0 -18
@@ -6,16 +6,19 @@
6
6
  */
7
7
 
8
8
  import PropTypes from 'prop-types';
9
- import React, { useState, useContext, useRef, useEffect } from 'react';
9
+ import React, { useRef, useState, useEffect, useContext, cloneElement } from 'react';
10
10
  import cx from 'classnames';
11
11
  import { useNormalizedInputProps } from '../../internal/useNormalizedInputProps.js';
12
12
  import deprecate from '../../prop-types/deprecate.js';
13
13
  import { textInputProps } from './util.js';
14
14
  import '../FluidForm/FluidForm.js';
15
15
  import { FormContext } from '../FluidForm/FormContext.js';
16
+ import { useMergedRefs } from '../../internal/useMergedRefs.js';
16
17
  import { usePrefix } from '../../internal/usePrefix.js';
17
18
  import { getAnnouncement } from '../../internal/getAnnouncement.js';
18
19
  import '../Text/index.js';
20
+ import { AILabel } from '../AILabel/index.js';
21
+ import { isComponentElement } from '../../internal/utils.js';
19
22
  import { Text } from '../Text/Text.js';
20
23
 
21
24
  const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
@@ -48,7 +51,16 @@ const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
48
51
  defaultValue,
49
52
  value
50
53
  } = rest;
51
- const [textCount, setTextCount] = useState(defaultValue?.toString().length || value?.toString().length || 0);
54
+ const inputRef = useRef(null);
55
+ const mergedRef = useMergedRefs([ref, inputRef]);
56
+ function getInitialTextCount() {
57
+ const targetValue = defaultValue || value || inputRef.current?.value || '';
58
+ return targetValue.toString().length;
59
+ }
60
+ const [textCount, setTextCount] = useState(getInitialTextCount());
61
+ useEffect(() => {
62
+ setTextCount(getInitialTextCount());
63
+ }, [value, defaultValue, enableCounter]);
52
64
  const normalizedProps = useNormalizedInputProps({
53
65
  id,
54
66
  readOnly,
@@ -81,7 +93,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
81
93
  },
82
94
  placeholder,
83
95
  type,
84
- ref,
96
+ ref: mergedRef,
85
97
  className: textInputClasses,
86
98
  title: placeholder,
87
99
  disabled: normalizedProps.disabled,
@@ -179,12 +191,11 @@ const TextInput = /*#__PURE__*/React.forwardRef(function TextInput({
179
191
  const Icon = normalizedProps.icon;
180
192
 
181
193
  // AILabel is always size `mini`
182
- let normalizedDecorator = /*#__PURE__*/React.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
183
- if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
184
- normalizedDecorator = /*#__PURE__*/React.cloneElement(normalizedDecorator, {
185
- size: 'mini'
186
- });
187
- }
194
+ const candidate = slug ?? decorator;
195
+ const candidateIsAILabel = isComponentElement(candidate, AILabel);
196
+ const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
197
+ size: 'mini'
198
+ }) : null;
188
199
  return /*#__PURE__*/React.createElement("div", {
189
200
  className: inputWrapperClasses
190
201
  }, !inline ? labelWrapper : /*#__PURE__*/React.createElement("div", {
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { type ChangeEvent, type HTMLAttributes, type KeyboardEvent, type MouseEvent, type ReactNode } from 'react';
7
+ import React, { type HTMLAttributes, type KeyboardEvent, type MouseEvent, type ReactNode } from 'react';
8
8
  export interface TileProps extends HTMLAttributes<HTMLDivElement> {
9
9
  children?: ReactNode;
10
10
  className?: string;
@@ -105,7 +105,7 @@ export interface SelectableTileProps extends HTMLAttributes<HTMLDivElement> {
105
105
  /**
106
106
  * The empty handler of the `<input>`.
107
107
  */
108
- onChange?(event: ChangeEvent<HTMLDivElement>, selected?: boolean, id?: string): void;
108
+ onChange?(event: MouseEvent<HTMLDivElement> | KeyboardEvent<HTMLDivElement>, selected?: boolean, id?: string): void;
109
109
  /**
110
110
  * Specify the function to run when the SelectableTile is clicked
111
111
  */
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React, { useState, useRef, useEffect } from 'react';
9
+ import React, { useState, useEffect, useCallback, useRef, cloneElement } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
12
  import { AiLabel, CheckboxCheckedFilled, Checkbox, ChevronDown, ArrowRight, Error } from '@carbon/icons-react';
@@ -22,6 +22,8 @@ import { useMergedRefs } from '../../internal/useMergedRefs.js';
22
22
  import { useFeatureFlag } from '../FeatureFlags/index.js';
23
23
  import { useId } from '../../internal/useId.js';
24
24
  import '../Text/index.js';
25
+ import { AILabel } from '../AILabel/index.js';
26
+ import { isComponentElement } from '../../internal/utils.js';
25
27
  import { Text } from '../Text/Text.js';
26
28
 
27
29
  var _CheckboxCheckedFille, _Checkbox, _ChevronDown, _ChevronDown2;
@@ -224,7 +226,11 @@ const SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile({
224
226
  const clickHandler = onClick;
225
227
  const keyDownHandler = onKeyDown;
226
228
  const [isSelected, setIsSelected] = useState(selected);
227
- const [prevSelected, setPrevSelected] = useState(selected);
229
+
230
+ // Use useEffect to sync with prop changes instead of render-time logic
231
+ useEffect(() => {
232
+ setIsSelected(selected);
233
+ }, [selected]);
228
234
  const classes = cx(`${prefix}--tile`, `${prefix}--tile--selectable`, {
229
235
  [`${prefix}--tile--is-selected`]: isSelected,
230
236
  [`${prefix}--tile--light`]: light,
@@ -234,50 +240,40 @@ const SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile({
234
240
  [`${prefix}--tile--decorator`]: decorator,
235
241
  [`${prefix}--tile--decorator-rounded`]: decorator && hasRoundedCorners
236
242
  }, className);
243
+
244
+ // Single function to handle selection changes
245
+ const handleSelectionChange = useCallback((evt, newSelected) => {
246
+ setIsSelected(newSelected);
247
+ onChange(evt, newSelected, id);
248
+ }, [onChange, id]);
237
249
  function handleClick(evt) {
238
250
  evt.preventDefault();
239
251
  evt?.persist?.();
240
- if (normalizedDecorator && decoratorRef.current && decoratorRef.current.contains(evt.target)) {
252
+ if (normalizedDecorator && decoratorRef.current && evt.target instanceof Node && decoratorRef.current.contains(evt.target)) {
241
253
  return;
242
254
  }
243
- setIsSelected(prevSelected => {
244
- const newSelected = !prevSelected;
245
- onChange(evt, newSelected, id);
246
- return newSelected;
247
- });
255
+ const newSelected = !isSelected;
256
+ handleSelectionChange(evt, newSelected);
248
257
  clickHandler(evt);
249
258
  }
250
259
  function handleKeyDown(evt) {
251
260
  evt?.persist?.();
252
261
  if (matches(evt, [Enter, Space])) {
253
262
  evt.preventDefault();
254
- setIsSelected(prevSelected => {
255
- const newSelected = !prevSelected;
256
- onChange(evt, newSelected, id);
257
- return newSelected;
258
- });
263
+ const newSelected = !isSelected;
264
+ handleSelectionChange(evt, newSelected);
259
265
  }
260
266
  keyDownHandler(evt);
261
267
  }
262
- function handleChange(event) {
263
- const newSelected = event.target.checked;
264
- setIsSelected(newSelected);
265
- onChange(event, newSelected, id);
266
- }
267
- if (selected !== prevSelected) {
268
- setIsSelected(selected);
269
- setPrevSelected(selected);
270
- }
271
268
 
272
269
  // AILabel is always size `xs`
273
270
  const decoratorRef = useRef(null);
274
- let normalizedDecorator = /*#__PURE__*/React.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
275
- if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
276
- normalizedDecorator = /*#__PURE__*/React.cloneElement(normalizedDecorator, {
277
- size: 'xs',
278
- ref: decoratorRef
279
- });
280
- }
271
+ const candidate = slug ?? decorator;
272
+ const candidateIsAILabel = isComponentElement(candidate, AILabel);
273
+ const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
274
+ size: 'xs',
275
+ ref: decoratorRef
276
+ }) : null;
281
277
  return (
282
278
  /*#__PURE__*/
283
279
  // eslint-disable-next-line jsx-a11y/interactive-supports-focus
@@ -292,7 +288,6 @@ const SelectableTile = /*#__PURE__*/React.forwardRef(function SelectableTile({
292
288
  tabIndex: !disabled ? tabIndex : undefined,
293
289
  ref: ref,
294
290
  id: id,
295
- onChange: !disabled ? handleChange : undefined,
296
291
  title: title
297
292
  }, rest), /*#__PURE__*/React.createElement("span", {
298
293
  className: `${prefix}--tile__checkmark ${prefix}--tile__checkmark--persistent`
@@ -505,12 +500,11 @@ const ExpandableTile = /*#__PURE__*/React.forwardRef(function ExpandableTile({
505
500
  const belowTheFoldId = useId('expandable-tile-interactive');
506
501
 
507
502
  // AILabel is always size `xs`
508
- let normalizedDecorator = /*#__PURE__*/React.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
509
- if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
510
- normalizedDecorator = /*#__PURE__*/React.cloneElement(normalizedDecorator, {
511
- size: 'xs'
512
- });
513
- }
503
+ const candidate = slug ?? decorator;
504
+ const candidateIsAILabel = isComponentElement(candidate, AILabel);
505
+ const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
506
+ size: 'xs'
507
+ }) : null;
514
508
  return interactive ? /*#__PURE__*/React.createElement("div", _extends({
515
509
  ref: ref,
516
510
  className: interactiveClassNames
@@ -45,8 +45,9 @@ export interface TileGroupProps extends Omit<HTMLAttributes<HTMLFieldSetElement>
45
45
  */
46
46
  required?: boolean;
47
47
  }
48
- declare const TileGroup: {
49
- (props: any): import("react/jsx-runtime").JSX.Element;
48
+ export declare const TileGroup: {
49
+ ({ children, className, defaultSelected, disabled, legend, name, onChange, valueSelected, required, }: TileGroupProps): import("react/jsx-runtime").JSX.Element;
50
+ displayName: string;
50
51
  propTypes: {
51
52
  /**
52
53
  * Provide a collection of <RadioTile> components to render in the group
@@ -86,6 +87,5 @@ declare const TileGroup: {
86
87
  */
87
88
  valueSelected: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
88
89
  };
89
- displayName: string;
90
90
  };
91
- export default TileGroup;
91
+ export {};
@@ -7,40 +7,42 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React, { useState } from 'react';
10
+ import React, { useState, useEffect, Children, isValidElement, cloneElement } from 'react';
11
11
  import RadioTile from '../RadioTile/RadioTile.js';
12
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
13
  import { noopFn } from '../../internal/noopFn.js';
14
14
 
15
- const TileGroup = props => {
16
- const {
17
- children,
18
- className,
19
- defaultSelected,
20
- disabled,
21
- legend,
22
- name,
23
- onChange = noopFn,
24
- valueSelected,
25
- required
26
- } = props;
15
+ const TileGroup = ({
16
+ children,
17
+ className,
18
+ defaultSelected,
19
+ disabled,
20
+ legend,
21
+ name,
22
+ onChange = noopFn,
23
+ valueSelected,
24
+ required
25
+ }) => {
27
26
  const prefix = usePrefix();
28
27
  const [selected, setSelected] = useState(valueSelected ?? defaultSelected);
29
- const [prevValueSelected, setPrevValueSelected] = useState(valueSelected);
28
+ useEffect(() => {
29
+ if (typeof valueSelected !== 'undefined' && valueSelected !== selected) {
30
+ setSelected(valueSelected);
31
+ }
32
+ }, [valueSelected, selected]);
33
+ const handleChange = (value, name, evt) => {
34
+ if (value !== selected) {
35
+ setSelected(value);
36
+ onChange(value, name ?? '', evt);
37
+ }
38
+ };
39
+ const getRadioTilesWithWrappers = elements => {
40
+ const traverseAndModifyChildren = elements => {
41
+ return Children.map(elements, child => {
42
+ if (! /*#__PURE__*/isValidElement(child)) return child;
30
43
 
31
- /**
32
- * prop + state alignment - getDerivedStateFromProps
33
- * only update if selected prop changes
34
- */
35
- if (valueSelected !== prevValueSelected) {
36
- setSelected(valueSelected);
37
- setPrevValueSelected(valueSelected);
38
- }
39
- const getRadioTilesWithWrappers = children => {
40
- const traverseAndModifyChildren = children => {
41
- return React.Children.map(children, child => {
42
- // If RadioTile found, return it with necessary props
43
- if (child?.type === RadioTile) {
44
+ // If a `RadioTile` is found, return it with necessary props,
45
+ if (/*#__PURE__*/isValidElement(child) && child.type === RadioTile) {
44
46
  const {
45
47
  value,
46
48
  ...otherProps
@@ -53,38 +55,29 @@ const TileGroup = props => {
53
55
  onChange: handleChange,
54
56
  checked: value === selected
55
57
  }));
56
- } else if (child?.props?.children) {
57
- // If the child is not RadioTile and has children, recheck the children
58
- return /*#__PURE__*/React.cloneElement(child, {
59
- ...child.props,
60
- children: traverseAndModifyChildren(child.props.children)
61
- });
62
- } else {
63
- // If the child is neither a RadioTile nor has children, return it as is
64
- return child;
65
58
  }
59
+
60
+ // If the child is not RadioTile and has children, recheck the children
61
+ const children = child.props.children;
62
+ const hasChildren = Children.count(children) > 0;
63
+ if (hasChildren) {
64
+ return /*#__PURE__*/cloneElement(child, undefined, traverseAndModifyChildren(children));
65
+ }
66
+
67
+ // If the child is neither a RadioTile nor has children, return it as is
68
+ return child;
66
69
  });
67
70
  };
68
- return /*#__PURE__*/React.createElement(React.Fragment, null, traverseAndModifyChildren(children));
69
- };
70
- const handleChange = (newSelection, value, evt) => {
71
- if (newSelection !== selected) {
72
- setSelected(newSelection);
73
- onChange(newSelection, name, evt);
74
- }
75
- };
76
- const renderLegend = legend => {
77
- if (legend) {
78
- return /*#__PURE__*/React.createElement("legend", {
79
- className: `${prefix}--label`
80
- }, legend);
81
- }
71
+ return /*#__PURE__*/React.createElement(React.Fragment, null, traverseAndModifyChildren(elements));
82
72
  };
83
73
  return /*#__PURE__*/React.createElement("fieldset", {
84
74
  className: className ?? `${prefix}--tile-group`,
85
75
  disabled: disabled
86
- }, renderLegend(legend), /*#__PURE__*/React.createElement("div", null, getRadioTilesWithWrappers(children)));
76
+ }, legend && /*#__PURE__*/React.createElement("legend", {
77
+ className: `${prefix}--label`
78
+ }, legend), /*#__PURE__*/React.createElement("div", null, getRadioTilesWithWrappers(children)));
87
79
  };
80
+ TileGroup.displayName = 'TileGroup';
88
81
  TileGroup.propTypes = {
89
82
  /**
90
83
  * Provide a collection of <RadioTile> components to render in the group
@@ -124,6 +117,5 @@ TileGroup.propTypes = {
124
117
  */
125
118
  valueSelected: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
126
119
  };
127
- TileGroup.displayName = 'TileGroup';
128
120
 
129
- export { TileGroup as default };
121
+ export { TileGroup };
@@ -1,9 +1,9 @@
1
1
  /**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2025
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import TileGroup, { type TileGroupProps } from './TileGroup';
7
+ import { TileGroup } from './TileGroup';
8
8
  export default TileGroup;
9
- export { TileGroup, type TileGroupProps };
9
+ export * from './TileGroup';
@@ -88,6 +88,7 @@ function Toggletip({
88
88
  buttonProps: {
89
89
  'aria-expanded': open,
90
90
  'aria-controls': id,
91
+ 'aria-describedby': open ? id : undefined,
91
92
  onClick: actions.toggle
92
93
  },
93
94
  contentProps: {
@@ -259,8 +260,7 @@ const ToggletipContent = /*#__PURE__*/React.forwardRef(function ToggletipContent
259
260
  return /*#__PURE__*/React.createElement(PopoverContent, _extends({
260
261
  className: customClassName
261
262
  }, toggletip?.contentProps, {
262
- ref: ref,
263
- "aria-live": "polite"
263
+ ref: ref
264
264
  }), /*#__PURE__*/React.createElement("div", {
265
265
  className: `${prefix}--toggletip-content`
266
266
  }, children));
@@ -57,6 +57,7 @@ const DefinitionTooltip = ({
57
57
  }, /*#__PURE__*/React.createElement("button", _extends({}, rest, {
58
58
  className: cx(`${prefix}--definition-term`, triggerClassName),
59
59
  "aria-controls": tooltipId,
60
+ "aria-describedby": tooltipId,
60
61
  "aria-expanded": isOpen,
61
62
  onBlur: () => {
62
63
  setOpen(false);
@@ -14,7 +14,7 @@ import { ArrowLeft, ArrowRight, Enter, Space } from '../../internal/keyboard/key
14
14
  import { matches, match } from '../../internal/keyboard/match.js';
15
15
  import { useControllableState } from '../../internal/useControllableState.js';
16
16
  import { usePrefix } from '../../internal/usePrefix.js';
17
- import { uniqueId } from '../../tools/uniqueId.js';
17
+ import { useId } from '../../internal/useId.js';
18
18
  import { useFeatureFlag } from '../FeatureFlags/index.js';
19
19
 
20
20
  const TreeNode = /*#__PURE__*/React.forwardRef(({
@@ -43,7 +43,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
43
43
  const enableTreeviewControllable = useFeatureFlag('enable-treeview-controllable');
44
44
  const {
45
45
  current: id
46
- } = useRef(nodeId || uniqueId());
46
+ } = useRef(nodeId || useId());
47
47
  const controllableExpandedState = useControllableState({
48
48
  value: isExpanded,
49
49
  onChange: newValue => {
@@ -72,7 +72,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
72
72
  function enhanceTreeNodes(children) {
73
73
  return React.Children.map(children, node => {
74
74
  if (! /*#__PURE__*/React.isValidElement(node)) return node;
75
- const isTreeNode = node.type.displayName === 'TreeNode';
75
+ const isTreeNode = node.type === TreeNode;
76
76
  if (isTreeNode) {
77
77
  return /*#__PURE__*/React.cloneElement(node, {
78
78
  active,
@@ -13,7 +13,7 @@ import { ArrowUp, ArrowDown, Home, End } from '../../internal/keyboard/keys.js';
13
13
  import { matches, match } from '../../internal/keyboard/match.js';
14
14
  import { useControllableState } from '../../internal/useControllableState.js';
15
15
  import { usePrefix } from '../../internal/usePrefix.js';
16
- import { uniqueId } from '../../tools/uniqueId.js';
16
+ import { useId } from '../../internal/useId.js';
17
17
  import { useFeatureFlag } from '../FeatureFlags/index.js';
18
18
  import TreeNode from './TreeNode.js';
19
19
 
@@ -33,7 +33,7 @@ const TreeView = ({
33
33
  const enableTreeviewControllable = useFeatureFlag('enable-treeview-controllable');
34
34
  const {
35
35
  current: treeId
36
- } = useRef(rest.id || uniqueId());
36
+ } = useRef(rest.id || useId());
37
37
  const prefix = usePrefix();
38
38
  const treeClasses = cx(className, `${prefix}--tree`, {
39
39
  // @ts-ignore - will always be false according to prop types
@@ -112,7 +112,7 @@ const TreeView = ({
112
112
  function enhanceTreeNodes(children) {
113
113
  return React.Children.map(children, child => {
114
114
  if (! /*#__PURE__*/React.isValidElement(child)) return child;
115
- const isTreeNode = child.type.displayName === 'TreeNode';
115
+ const isTreeNode = child.type === TreeNode;
116
116
  if (isTreeNode) {
117
117
  const node = child;
118
118
  const sharedNodeProps = {
@@ -75,6 +75,8 @@ declare const Content: {
75
75
  inert?: boolean | undefined;
76
76
  inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined;
77
77
  is?: string | undefined;
78
+ exportparts?: string | undefined;
79
+ part?: string | undefined;
78
80
  "aria-activedescendant"?: string | undefined;
79
81
  "aria-atomic"?: (boolean | "true" | "false") | undefined;
80
82
  "aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined;
@@ -149,7 +151,7 @@ declare const Content: {
149
151
  onBlurCapture?: React.FocusEventHandler<HTMLElement> | undefined;
150
152
  onChange?: React.FormEventHandler<HTMLElement> | undefined;
151
153
  onChangeCapture?: React.FormEventHandler<HTMLElement> | undefined;
152
- onBeforeInput?: React.FormEventHandler<HTMLElement> | undefined;
154
+ onBeforeInput?: React.InputEventHandler<HTMLElement> | undefined;
153
155
  onBeforeInputCapture?: React.FormEventHandler<HTMLElement> | undefined;
154
156
  onInput?: React.FormEventHandler<HTMLElement> | undefined;
155
157
  onInputCapture?: React.FormEventHandler<HTMLElement> | undefined;
@@ -199,8 +201,6 @@ declare const Content: {
199
201
  onProgressCapture?: React.ReactEventHandler<HTMLElement> | undefined;
200
202
  onRateChange?: React.ReactEventHandler<HTMLElement> | undefined;
201
203
  onRateChangeCapture?: React.ReactEventHandler<HTMLElement> | undefined;
202
- onResize?: React.ReactEventHandler<HTMLElement> | undefined;
203
- onResizeCapture?: React.ReactEventHandler<HTMLElement> | undefined;
204
204
  onSeeked?: React.ReactEventHandler<HTMLElement> | undefined;
205
205
  onSeekedCapture?: React.ReactEventHandler<HTMLElement> | undefined;
206
206
  onSeeking?: React.ReactEventHandler<HTMLElement> | undefined;
@@ -281,6 +281,8 @@ declare const Content: {
281
281
  onLostPointerCaptureCapture?: React.PointerEventHandler<HTMLElement> | undefined;
282
282
  onScroll?: React.UIEventHandler<HTMLElement> | undefined;
283
283
  onScrollCapture?: React.UIEventHandler<HTMLElement> | undefined;
284
+ onScrollEnd?: React.UIEventHandler<HTMLElement> | undefined;
285
+ onScrollEndCapture?: React.UIEventHandler<HTMLElement> | undefined;
284
286
  onWheel?: React.WheelEventHandler<HTMLElement> | undefined;
285
287
  onWheelCapture?: React.WheelEventHandler<HTMLElement> | undefined;
286
288
  onAnimationStart?: React.AnimationEventHandler<HTMLElement> | undefined;
@@ -24,6 +24,7 @@ const HeaderMenuItem = /*#__PURE__*/forwardRef(function HeaderMenuItem({
24
24
  ...rest
25
25
  }, ref) {
26
26
  const prefix = usePrefix();
27
+ const resolvedTabIndex = tabIndex ?? 0;
27
28
  if (isCurrentPage) {
28
29
  isActive = isCurrentPage;
29
30
  }
@@ -42,7 +43,7 @@ const HeaderMenuItem = /*#__PURE__*/forwardRef(function HeaderMenuItem({
42
43
  "aria-current": hasCurrentClass ? true : ariaCurrent,
43
44
  className: linkClassName,
44
45
  ref: ref,
45
- tabIndex: tabIndex
46
+ tabIndex: resolvedTabIndex
46
47
  }), /*#__PURE__*/React.createElement("span", {
47
48
  className: `${prefix}--text-truncate--end`
48
49
  }, children)));
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2025
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, { ReactNode } from 'react';
7
+ import React, { type ReactNode } from 'react';
8
8
  export interface HeaderPanelProps {
9
9
  /**
10
10
  * Specify whether focus and blur listeners are added. They are by default.
@@ -8,12 +8,13 @@
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
- import React, { useRef, useState } from 'react';
11
+ import React, { useRef, useState, isValidElement } from 'react';
12
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
13
  import { Escape } from '../../internal/keyboard/keys.js';
14
14
  import { match } from '../../internal/keyboard/match.js';
15
15
  import { useWindowEvent } from '../../internal/useEvent.js';
16
16
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
17
+ import Switcher from './Switcher.js';
17
18
 
18
19
  const noopFn = () => {};
19
20
  const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel({
@@ -58,10 +59,13 @@ const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel({
58
59
  };
59
60
  }
60
61
  useWindowEvent('click', () => {
61
- const focusedElement = document.activeElement;
62
- setLastClickedElement(focusedElement);
63
- const childJsxElement = children;
64
- if (childJsxElement?.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelReference?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
62
+ const {
63
+ activeElement
64
+ } = document;
65
+ if (!(activeElement instanceof HTMLElement)) return;
66
+ setLastClickedElement(activeElement);
67
+ const isChildASwitcher = /*#__PURE__*/isValidElement(children) && typeof children.type !== 'string' && children.type === Switcher;
68
+ if (isChildASwitcher && !activeElement.closest(`.${prefix}--header-panel--expanded`) && !activeElement.closest(`.${prefix}--header__action`) && !headerPanelReference?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
65
69
  setExpandedState(false);
66
70
  onHeaderPanelFocus();
67
71
  }
package/es/index.js CHANGED
@@ -148,7 +148,7 @@ export { default as TextAreaSkeleton } from './components/TextArea/TextArea.Skel
148
148
  export { default as TextInput } from './components/TextInput/TextInput.js';
149
149
  export { default as TextInputSkeleton } from './components/TextInput/TextInput.Skeleton.js';
150
150
  export { ClickableTile, ExpandableTile, SelectableTile, Tile, TileAboveTheFoldContent, TileBelowTheFoldContent } from './components/Tile/Tile.js';
151
- export { default as TileGroup } from './components/TileGroup/TileGroup.js';
151
+ export { TileGroup } from './components/TileGroup/TileGroup.js';
152
152
  export { default as TimePicker } from './components/TimePicker/TimePicker.js';
153
153
  export { default as TimePickerSelect } from './components/TimePickerSelect/TimePickerSelect.js';
154
154
  export { Toggle } from './components/Toggle/Toggle.js';
@@ -17,9 +17,14 @@ const callOnChangeHandler = ({
17
17
  }) => {
18
18
  if (isControlled) {
19
19
  if (isMounted && onChangeHandlerControlled) {
20
- onChangeHandlerControlled({
21
- selectedItems
22
- });
20
+ // Use setTimeout to defer the controlled onChange call,
21
+ // avoiding React’s warning: "Cannot update a component while rendering a different component".
22
+ // This ensures the parent state updates after rendering completes.
23
+ setTimeout(() => {
24
+ onChangeHandlerControlled({
25
+ selectedItems
26
+ });
27
+ }, 0);
23
28
  }
24
29
  } else {
25
30
  onChangeHandlerUncontrolled(selectedItems);
@@ -10,17 +10,6 @@
10
10
  *
11
11
  * @see https://github.com/facebook/fbjs/blob/4d1751311d3f67af2dcce2e40df8512a23c7b9c6/packages/fbjs/src/core/ExecutionEnvironment.js#L12
12
12
  */
13
- const canUseDOM = !!(typeof window !== 'undefined' &&
14
- // TODO: `ssr-friendly` doesn't support ESLint v9.
15
- // https://github.com/kopiro/eslint-plugin-ssr-friendly/issues/30
16
- // https://github.com/carbon-design-system/carbon/issues/18991
17
- /*
18
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
19
- */
20
- window.document &&
21
- /*
22
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
23
- */
24
- window.document.createElement);
13
+ const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
25
14
 
26
15
  export { canUseDOM };
@@ -1,9 +1,7 @@
1
1
  /**
2
- * Copyright IBM Corp. 2025, 2025
2
+ * Copyright IBM Corp. 2025
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- export declare const mockHTMLElement: (options: HTMLElement) => {
8
- mockRestore: () => void;
9
- };
7
+ export * from './utils';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright IBM Corp. 2025, 2025
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { ReactNode, RefObject } from 'react';
8
+ type Item = {
9
+ id: string;
10
+ };
11
+ /**
12
+ * Manages overflow items in a container by automatically hiding items that don't fit.
13
+ * @param items - Array of items to manage for overflow, each must have an `id` property.
14
+ * @param containerRef - React ref to the container element that holds the items.
15
+ * @param offsetRef - Optional ref to an offset element (like a "more" button) whose width is reserved when calculating available space.
16
+ * @param maxItems - Optional maximum number of visible items. If undefined, only container space constrains visibility.
17
+ * @param onChange - Optional callback called when hidden items change. Receives array of currently hidden items.
18
+ * @returns Object with `visibleItems` (items to display), `hiddenItems` (items that don't fit), and `itemRefHandler` (function to attach refs to items for width measurement).
19
+ */
20
+ declare const useOverflowItems: <T extends Item>(items: T[] | ReactNode, containerRef: RefObject<HTMLDivElement>, offsetRef?: RefObject<HTMLDivElement>, maxItems?: number, onChange?: (hiddenItems: T[]) => void) => {
21
+ visibleItems: T[];
22
+ hiddenItems: T[];
23
+ itemRefHandler: () => void;
24
+ } | {
25
+ visibleItems: T[];
26
+ itemRefHandler: (id: string, node: HTMLDivElement | null) => () => void;
27
+ hiddenItems: T[];
28
+ };
29
+ export default useOverflowItems;