@carbon/react 1.84.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 (151) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +784 -784
  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 +15 -10
  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 +20 -9
  36. package/es/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
  37. package/es/components/MultiSelect/FilterableMultiSelect.js +8 -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/PageHeader/PageHeader.js +2 -2
  43. package/es/components/Popover/index.js +2 -1
  44. package/es/components/RadioButton/RadioButton.d.ts +2 -2
  45. package/es/components/RadioButton/RadioButton.js +8 -8
  46. package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +2 -2
  47. package/es/components/RadioButtonGroup/RadioButtonGroup.js +9 -8
  48. package/es/components/RadioTile/RadioTile.d.ts +1 -1
  49. package/es/components/RadioTile/RadioTile.js +8 -7
  50. package/es/components/Select/Select.d.ts +2 -2
  51. package/es/components/Select/Select.js +8 -7
  52. package/es/components/Tag/DismissibleTag.d.ts +1 -1
  53. package/es/components/Tag/DismissibleTag.js +9 -8
  54. package/es/components/Tag/Tag.d.ts +1 -1
  55. package/es/components/Tag/Tag.js +9 -8
  56. package/es/components/TextArea/TextArea.js +8 -7
  57. package/es/components/TextInput/TextInput.d.ts +1 -1
  58. package/es/components/TextInput/TextInput.js +20 -9
  59. package/es/components/Tile/Tile.d.ts +2 -2
  60. package/es/components/Tile/Tile.js +30 -36
  61. package/es/components/Toggletip/index.js +2 -2
  62. package/es/components/Tooltip/DefinitionTooltip.js +1 -0
  63. package/es/components/TreeView/TreeNode.js +3 -3
  64. package/es/components/TreeView/TreeView.js +3 -3
  65. package/es/components/UIShell/Content.d.ts +5 -3
  66. package/es/components/UIShell/HeaderPanel.d.ts +2 -2
  67. package/es/components/UIShell/HeaderPanel.js +9 -5
  68. package/es/internal/Selection.js +8 -3
  69. package/es/internal/environment.js +1 -12
  70. package/es/internal/{__mocks__/mockHTMLElement.d.ts → index.d.ts} +2 -4
  71. package/es/internal/useResizeObserver.d.ts +1 -1
  72. package/es/internal/utils.d.ts +14 -0
  73. package/es/internal/utils.js +18 -0
  74. package/es/tools/uniqueId.d.ts +1 -6
  75. package/lib/components/AILabel/index.js +6 -1
  76. package/lib/components/Checkbox/Checkbox.d.ts +2 -2
  77. package/lib/components/Checkbox/Checkbox.js +7 -7
  78. package/lib/components/CheckboxGroup/CheckboxGroup.d.ts +2 -2
  79. package/lib/components/CheckboxGroup/CheckboxGroup.js +8 -7
  80. package/lib/components/CodeSnippet/CodeSnippet.js +2 -4
  81. package/lib/components/ComboBox/ComboBox.d.ts +1 -1
  82. package/lib/components/ComboBox/ComboBox.js +11 -10
  83. package/lib/components/ComposedModal/ComposedModal.d.ts +1 -1
  84. package/lib/components/ComposedModal/ComposedModal.js +16 -11
  85. package/lib/components/ContainedList/ContainedList.d.ts +1 -1
  86. package/lib/components/ContainedList/ContainedList.js +4 -2
  87. package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -4
  88. package/lib/components/DataTable/DataTable.js +3 -0
  89. package/lib/components/DataTable/TableDecoratorRow.d.ts +2 -2
  90. package/lib/components/DataTable/TableDecoratorRow.js +8 -8
  91. package/lib/components/DataTable/TableExpandRow.d.ts +1 -1
  92. package/lib/components/DataTable/TableExpandRow.js +14 -5
  93. package/lib/components/DataTable/TableHeader.js +9 -9
  94. package/lib/components/DataTable/TableRow.js +11 -3
  95. package/lib/components/DataTable/tools/normalize.js +2 -1
  96. package/lib/components/DatePickerInput/DatePickerInput.js +7 -6
  97. package/lib/components/Dialog/index.d.ts +5 -1
  98. package/lib/components/Dialog/index.js +20 -0
  99. package/lib/components/Dropdown/Dropdown.d.ts +1 -1
  100. package/lib/components/Dropdown/Dropdown.js +12 -14
  101. package/lib/components/FileUploader/FileUploaderButton.js +2 -2
  102. package/lib/components/FileUploader/FileUploaderDropContainer.js +2 -2
  103. package/lib/components/FileUploader/FileUploaderItem.js +2 -2
  104. package/lib/components/Layer/index.d.ts +1 -3
  105. package/lib/components/Layer/index.js +9 -8
  106. package/lib/components/Menu/Menu.js +0 -6
  107. package/lib/components/Modal/Modal.d.ts +2 -2
  108. package/lib/components/Modal/Modal.js +28 -17
  109. package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +1 -1
  110. package/lib/components/MultiSelect/FilterableMultiSelect.js +12 -11
  111. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  112. package/lib/components/MultiSelect/MultiSelect.js +13 -12
  113. package/lib/components/NumberInput/NumberInput.d.ts +1 -1
  114. package/lib/components/NumberInput/NumberInput.js +8 -7
  115. package/lib/components/PageHeader/PageHeader.js +2 -2
  116. package/lib/components/Popover/index.js +2 -1
  117. package/lib/components/RadioButton/RadioButton.d.ts +2 -2
  118. package/lib/components/RadioButton/RadioButton.js +7 -7
  119. package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +2 -2
  120. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +10 -9
  121. package/lib/components/RadioTile/RadioTile.d.ts +1 -1
  122. package/lib/components/RadioTile/RadioTile.js +7 -6
  123. package/lib/components/Select/Select.d.ts +2 -2
  124. package/lib/components/Select/Select.js +7 -6
  125. package/lib/components/Tag/DismissibleTag.d.ts +1 -1
  126. package/lib/components/Tag/DismissibleTag.js +8 -7
  127. package/lib/components/Tag/Tag.d.ts +1 -1
  128. package/lib/components/Tag/Tag.js +8 -7
  129. package/lib/components/TextArea/TextArea.js +7 -6
  130. package/lib/components/TextInput/TextInput.d.ts +1 -1
  131. package/lib/components/TextInput/TextInput.js +19 -8
  132. package/lib/components/Tile/Tile.d.ts +2 -2
  133. package/lib/components/Tile/Tile.js +29 -35
  134. package/lib/components/Toggletip/index.js +2 -2
  135. package/lib/components/Tooltip/DefinitionTooltip.js +1 -0
  136. package/lib/components/TreeView/TreeNode.js +3 -3
  137. package/lib/components/TreeView/TreeView.js +3 -3
  138. package/lib/components/UIShell/Content.d.ts +5 -3
  139. package/lib/components/UIShell/HeaderPanel.d.ts +2 -2
  140. package/lib/components/UIShell/HeaderPanel.js +8 -4
  141. package/lib/internal/Selection.js +8 -3
  142. package/lib/internal/environment.js +1 -12
  143. package/lib/internal/{__mocks__/mockHTMLElement.d.ts → index.d.ts} +2 -4
  144. package/lib/internal/useResizeObserver.d.ts +1 -1
  145. package/lib/internal/utils.d.ts +14 -0
  146. package/lib/internal/utils.js +22 -0
  147. package/lib/tools/uniqueId.d.ts +1 -6
  148. package/package.json +11 -20
  149. package/telemetry.yml +1 -0
  150. package/es/tools/uniqueId.js +0 -14
  151. package/lib/tools/uniqueId.js +0 -18
@@ -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, { ReactNode } from 'react';
7
+ import React, { type ReactNode } from 'react';
8
8
  import { PolymorphicProps } from '../../types/common';
9
9
  import { SIZES, TYPES } from './Tag';
10
10
  export interface DismissibleTagBaseProps {
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React, { forwardRef, useRef, useState, useLayoutEffect } from 'react';
10
+ import React, { forwardRef, useRef, useState, useLayoutEffect, cloneElement } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { useId } from '../../internal/useId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -19,6 +19,8 @@ import { Tooltip } from '../Tooltip/Tooltip.js';
19
19
  import '../Text/index.js';
20
20
  import { isEllipsisActive } from './isEllipsisActive.js';
21
21
  import mergeRefs from '../../tools/mergeRefs.js';
22
+ import { AILabel } from '../AILabel/index.js';
23
+ import { isComponentElement } from '../../internal/utils.js';
22
24
  import { Text } from '../Text/Text.js';
23
25
 
24
26
  var _Close;
@@ -54,13 +56,12 @@ const DismissibleTag = /*#__PURE__*/forwardRef(({
54
56
  onClose(event);
55
57
  }
56
58
  };
57
- let normalizedDecorator = /*#__PURE__*/React.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
58
- if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
59
- normalizedDecorator = /*#__PURE__*/React.cloneElement(normalizedDecorator, {
60
- size: 'sm',
61
- kind: 'inline'
62
- });
63
- }
59
+ const candidate = slug ?? decorator;
60
+ const candidateIsAILabel = isComponentElement(candidate, AILabel);
61
+ const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
62
+ size: 'sm',
63
+ kind: 'inline'
64
+ }) : null;
64
65
  const tooltipClasses = cx(`${prefix}--icon-tooltip`, `${prefix}--tag-label-tooltip`);
65
66
 
66
67
  // Removing onClick from the spread operator
@@ -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, { ReactNode } from 'react';
7
+ import React, { type ReactNode } from 'react';
8
8
  import { PolymorphicComponentPropWithRef } from '../../internal/PolymorphicProps';
9
9
  import { SelectableTagBaseProps } from './SelectableTag';
10
10
  import { OperationalTagBaseProps } from './OperationalTag';
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React, { useRef, useState, useLayoutEffect } from 'react';
10
+ import React, { useRef, useState, useLayoutEffect, cloneElement } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { Close } from '@carbon/icons-react';
13
13
  import { useId } from '../../internal/useId.js';
@@ -18,6 +18,8 @@ import { DefinitionTooltip } from '../Tooltip/DefinitionTooltip.js';
18
18
  import '../Tooltip/Tooltip.js';
19
19
  import { isEllipsisActive } from './isEllipsisActive.js';
20
20
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
21
+ import { AILabel } from '../AILabel/index.js';
22
+ import { isComponentElement } from '../../internal/utils.js';
21
23
  import { Text } from '../Text/Text.js';
22
24
 
23
25
  var _Close;
@@ -94,13 +96,12 @@ const TagBase = /*#__PURE__*/React.forwardRef(({
94
96
  };
95
97
 
96
98
  // AILabel is always size `sm` and `inline`
97
- let normalizedDecorator = /*#__PURE__*/React.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
98
- if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel' && !isInteractiveTag) {
99
- normalizedDecorator = /*#__PURE__*/React.cloneElement(normalizedDecorator, {
100
- size: 'sm',
101
- kind: 'inline'
102
- });
103
- }
99
+ const candidate = slug ?? decorator;
100
+ const candidateIsAILabel = isComponentElement(candidate, AILabel);
101
+ const normalizedDecorator = candidateIsAILabel && !isInteractiveTag ? /*#__PURE__*/cloneElement(candidate, {
102
+ size: 'sm',
103
+ kind: 'inline'
104
+ }) : null;
104
105
  if (filter) {
105
106
  const ComponentTag = BaseComponent ?? 'div';
106
107
  return /*#__PURE__*/React.createElement(ComponentTag, _extends({
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React, { useContext, useRef, useState, useEffect, forwardRef } from 'react';
10
+ import React, { useContext, useRef, useState, useEffect, forwardRef, cloneElement } from 'react';
11
11
  import cx from 'classnames';
12
12
  import deprecate from '../../prop-types/deprecate.js';
13
13
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
@@ -20,6 +20,8 @@ import { useMergedRefs } from '../../internal/useMergedRefs.js';
20
20
  import { useId } from '../../internal/useId.js';
21
21
  import { noopFn } from '../../internal/noopFn.js';
22
22
  import '../Text/index.js';
23
+ import { AILabel } from '../AILabel/index.js';
24
+ import { isComponentElement } from '../../internal/utils.js';
23
25
  import { Text } from '../Text/Text.js';
24
26
 
25
27
  const frFn = forwardRef;
@@ -258,12 +260,11 @@ const TextArea = frFn((props, forwardRef) => {
258
260
  }));
259
261
 
260
262
  // AILabel is always size `mini`
261
- let normalizedDecorator = /*#__PURE__*/React.isValidElement(slug ?? decorator) ? slug ?? decorator : null;
262
- if (normalizedDecorator && normalizedDecorator['type']?.displayName === 'AILabel') {
263
- normalizedDecorator = /*#__PURE__*/React.cloneElement(normalizedDecorator, {
264
- size: 'mini'
265
- });
266
- }
263
+ const candidate = slug ?? decorator;
264
+ const candidateIsAILabel = isComponentElement(candidate, AILabel);
265
+ const normalizedDecorator = candidateIsAILabel ? /*#__PURE__*/cloneElement(candidate, {
266
+ size: 'mini'
267
+ }) : null;
267
268
  return /*#__PURE__*/React.createElement("div", {
268
269
  className: formItemClasses
269
270
  }, /*#__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, { ReactNode } from 'react';
7
+ import React, { type ReactNode } from 'react';
8
8
  type ExcludedAttributes = 'defaultValue' | 'id' | 'size' | 'value';
9
9
  export interface TextInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
10
10
  /**
@@ -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
@@ -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;
@@ -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
  }
@@ -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';
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { RefObject } from 'react';
8
8
  export declare const useResizeObserver: ({ ref, onResize, }: {
9
- ref: RefObject<HTMLElement>;
9
+ ref: RefObject<HTMLElement | null>;
10
10
  onResize?: (rect: DOMRectReadOnly) => void;
11
11
  }) => {
12
12
  width: number;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright IBM Corp. 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 { type ComponentType, type ReactElement, type ReactNode } from 'react';
8
+ /**
9
+ * Checks if an element is a valid React element of a given component type.
10
+ *
11
+ * @param element - The element to test.
12
+ * @param component - The component to match.
13
+ */
14
+ export declare const isComponentElement: <P>(element: ReactNode, component: ComponentType<P>) => element is ReactElement<P>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
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
+
8
+ import { isValidElement } from 'react';
9
+
10
+ /**
11
+ * Checks if an element is a valid React element of a given component type.
12
+ *
13
+ * @param element - The element to test.
14
+ * @param component - The component to match.
15
+ */
16
+ const isComponentElement = (element, component) => /*#__PURE__*/isValidElement(element) && element.type === component;
17
+
18
+ export { isComponentElement };
@@ -1,7 +1,2 @@
1
- /**
2
- * Copyright IBM Corp. 2016, 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
- */
1
+ export declare const uniqueIdDeprecationMessage = "The `uniqueId()` helper function from @carbon/react was called. This function should no longer be used.\n\n@carbon/react components should use the internal/useId.js hook instead. Other projects can use React's `useId()` hook: https://react.dev/reference/react/useId";
7
2
  export declare const uniqueId: (prefix?: string) => string;
@@ -37,7 +37,12 @@ const AILabelContent = /*#__PURE__*/React__default["default"].forwardRef(functio
37
37
  const prefix = usePrefix.usePrefix();
38
38
  const hasAILabelActions = React__default["default"].Children.toArray(children).some(child => {
39
39
  const item = child;
40
- item.type?.displayName === 'AILabelActions';
40
+ // TODO: Is there supposed to be a `return` here? If so, this issue would
41
+ // have been caught by ESLint. It's concerning that this code is 7 months
42
+ // old and no one has noticed any issues with it. It also makes me question
43
+ // whether the code is necessary.
44
+ // https://github.com/carbon-design-system/carbon/issues/18991
45
+ item.type === AILabelActions;
41
46
  });
42
47
  const aiLabelContentClasses = cx__default["default"](className, {
43
48
  [`${prefix}--ai-label-content`]: true,