@carbon/react 1.81.0-rc.0 → 1.82.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 (222) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +784 -784
  2. package/es/components/AILabel/index.d.ts +1 -1
  3. package/es/components/AILabel/index.js +2 -9
  4. package/es/components/Breadcrumb/Breadcrumb.d.ts +2 -3
  5. package/es/components/Breadcrumb/Breadcrumb.js +4 -4
  6. package/es/components/Breadcrumb/BreadcrumbItem.d.ts +3 -4
  7. package/es/components/Breadcrumb/BreadcrumbItem.js +5 -4
  8. package/es/components/Button/Button.js +2 -10
  9. package/es/components/ButtonSet/ButtonSet.d.ts +2 -3
  10. package/es/components/ButtonSet/ButtonSet.js +4 -4
  11. package/es/components/CodeSnippet/CodeSnippet.d.ts +1 -1
  12. package/es/components/CodeSnippet/CodeSnippet.js +3 -19
  13. package/es/components/ComboBox/ComboBox.d.ts +1 -1
  14. package/es/components/ComboBox/ComboBox.js +54 -32
  15. package/es/components/ComboButton/index.d.ts +1 -1
  16. package/es/components/ComboButton/index.js +2 -18
  17. package/es/components/ComposedModal/ComposedModal.js +5 -3
  18. package/es/components/Copy/Copy.d.ts +1 -1
  19. package/es/components/Copy/Copy.js +2 -18
  20. package/es/components/CopyButton/CopyButton.d.ts +1 -1
  21. package/es/components/CopyButton/CopyButton.js +2 -18
  22. package/es/components/DataTable/DataTable.d.ts +7 -12
  23. package/es/components/DataTable/DataTable.js +0 -5
  24. package/es/components/DataTable/TableCell.js +28 -4
  25. package/es/components/DataTable/TableToolbarAction.d.ts +2 -4
  26. package/es/components/DataTable/TableToolbarAction.js +5 -4
  27. package/es/components/DataTable/tools/cells.d.ts +13 -0
  28. package/es/components/DataTable/tools/cells.js +3 -6
  29. package/es/components/DataTable/tools/filter.d.ts +26 -0
  30. package/es/components/DataTable/tools/filter.js +8 -17
  31. package/es/components/DataTable/tools/sorting.d.ts +42 -0
  32. package/es/components/DataTable/tools/sorting.js +24 -53
  33. package/es/components/DatePicker/DatePicker.d.ts +1 -1
  34. package/es/components/DatePicker/DatePicker.js +19 -19
  35. package/es/components/Dialog/index.d.ts +1 -1
  36. package/es/components/Dropdown/Dropdown.Skeleton.d.ts +2 -2
  37. package/es/components/Dropdown/Dropdown.Skeleton.js +2 -2
  38. package/es/components/Dropdown/Dropdown.d.ts +7 -6
  39. package/es/components/Dropdown/Dropdown.js +13 -9
  40. package/es/components/FileUploader/FileUploaderButton.d.ts +1 -1
  41. package/es/components/FileUploader/FileUploaderButton.js +1 -1
  42. package/es/components/FileUploader/FileUploaderDropContainer.js +1 -1
  43. package/es/components/FileUploader/FileUploaderItem.js +1 -1
  44. package/es/components/FluidDatePickerInput/FluidDatePickerInput.d.ts +1 -1
  45. package/es/components/FluidDatePickerInput/FluidDatePickerInput.js +5 -6
  46. package/es/components/FluidDropdown/FluidDropdown.d.ts +1 -1
  47. package/es/components/FluidSearch/FluidSearch.d.ts +3 -6
  48. package/es/components/IconButton/index.d.ts +1 -1
  49. package/es/components/IconButton/index.js +2 -18
  50. package/es/components/ListBox/ListBox.d.ts +4 -5
  51. package/es/components/ListBox/ListBox.js +8 -7
  52. package/es/components/ListBox/ListBoxMenu.d.ts +4 -4
  53. package/es/components/ListBox/ListBoxMenu.js +4 -2
  54. package/es/components/ListBox/ListBoxMenuItem.d.ts +9 -8
  55. package/es/components/ListBox/ListBoxPropTypes.d.ts +3 -3
  56. package/es/components/ListBox/ListBoxPropTypes.js +3 -3
  57. package/es/components/ListBox/index.d.ts +7 -5
  58. package/es/components/ListBox/index.js +1 -1
  59. package/es/components/Menu/Menu.js +9 -14
  60. package/es/components/Menu/MenuItem.js +15 -4
  61. package/es/components/Modal/Modal.js +9 -9
  62. package/es/components/MultiSelect/FilterableMultiSelect.d.ts +3 -2
  63. package/es/components/MultiSelect/FilterableMultiSelect.js +3 -2
  64. package/es/components/MultiSelect/MultiSelect.d.ts +8 -2
  65. package/es/components/MultiSelect/MultiSelect.js +7 -4
  66. package/es/components/Notification/Notification.js +1 -1
  67. package/es/components/OverflowMenu/OverflowMenu.js +2 -21
  68. package/es/components/OverflowMenu/index.d.ts +1 -1
  69. package/es/components/OverflowMenu/index.js +2 -3
  70. package/es/components/OverflowMenu/next/index.js +2 -18
  71. package/es/components/OverflowMenuItem/OverflowMenuItem.d.ts +2 -4
  72. package/es/components/OverflowMenuItem/OverflowMenuItem.js +5 -4
  73. package/es/components/PageHeader/PageHeader.d.ts +160 -8
  74. package/es/components/PageHeader/PageHeader.js +155 -21
  75. package/es/components/PageHeader/index.d.ts +2 -2
  76. package/es/components/PageHeader/index.js +1 -1
  77. package/es/components/Popover/index.js +4 -21
  78. package/es/components/Search/Search.d.ts +2 -5
  79. package/es/components/Search/Search.js +24 -8
  80. package/es/components/Stack/HStack.d.ts +2 -3
  81. package/es/components/Stack/HStack.js +4 -7
  82. package/es/components/Stack/Stack.d.ts +3 -4
  83. package/es/components/Stack/Stack.js +3 -6
  84. package/es/components/Stack/VStack.d.ts +2 -3
  85. package/es/components/Stack/VStack.js +3 -2
  86. package/es/components/Stack/index.d.ts +4 -4
  87. package/es/components/TextArea/TextArea.js +3 -5
  88. package/es/components/TimePicker/TimePicker.d.ts +3 -4
  89. package/es/components/TimePicker/TimePicker.js +5 -4
  90. package/es/components/TimePickerSelect/TimePickerSelect.d.ts +23 -4
  91. package/es/components/TimePickerSelect/TimePickerSelect.js +5 -4
  92. package/es/components/TreeView/TreeNode.js +13 -1
  93. package/es/components/TreeView/TreeView.js +1 -1
  94. package/es/index.js +1 -1
  95. package/es/internal/FloatingMenu.js +9 -5
  96. package/es/internal/environment.js +7 -0
  97. package/es/internal/keyboard/navigation.d.ts +0 -10
  98. package/es/internal/keyboard/navigation.js +1 -13
  99. package/es/internal/useId.js +1 -1
  100. package/es/internal/useNoInteractiveChildren.js +7 -0
  101. package/es/internal/useOutsideClick.js +3 -0
  102. package/es/internal/wrapFocus.d.ts +49 -0
  103. package/es/internal/wrapFocus.js +64 -51
  104. package/es/tools/events.d.ts +17 -0
  105. package/es/tools/events.js +10 -13
  106. package/es/tools/mapPopoverAlign.d.ts +15 -0
  107. package/es/tools/mapPopoverAlign.js +28 -0
  108. package/es/tools/uniqueId.d.ts +7 -0
  109. package/es/tools/uniqueId.js +3 -3
  110. package/es/types/common.d.ts +0 -2
  111. package/lib/components/AILabel/index.d.ts +1 -1
  112. package/lib/components/AILabel/index.js +2 -9
  113. package/lib/components/Breadcrumb/Breadcrumb.d.ts +2 -3
  114. package/lib/components/Breadcrumb/Breadcrumb.js +3 -3
  115. package/lib/components/Breadcrumb/BreadcrumbItem.d.ts +3 -4
  116. package/lib/components/Breadcrumb/BreadcrumbItem.js +4 -3
  117. package/lib/components/Button/Button.js +1 -9
  118. package/lib/components/ButtonSet/ButtonSet.d.ts +2 -3
  119. package/lib/components/ButtonSet/ButtonSet.js +3 -3
  120. package/lib/components/CodeSnippet/CodeSnippet.d.ts +1 -1
  121. package/lib/components/CodeSnippet/CodeSnippet.js +3 -19
  122. package/lib/components/ComboBox/ComboBox.d.ts +1 -1
  123. package/lib/components/ComboBox/ComboBox.js +53 -31
  124. package/lib/components/ComboButton/index.d.ts +1 -1
  125. package/lib/components/ComboButton/index.js +2 -18
  126. package/lib/components/ComposedModal/ComposedModal.js +5 -3
  127. package/lib/components/Copy/Copy.d.ts +1 -1
  128. package/lib/components/Copy/Copy.js +2 -18
  129. package/lib/components/CopyButton/CopyButton.d.ts +1 -1
  130. package/lib/components/CopyButton/CopyButton.js +2 -18
  131. package/lib/components/DataTable/DataTable.d.ts +7 -12
  132. package/lib/components/DataTable/DataTable.js +0 -5
  133. package/lib/components/DataTable/TableCell.js +28 -3
  134. package/lib/components/DataTable/TableToolbarAction.d.ts +2 -4
  135. package/lib/components/DataTable/TableToolbarAction.js +4 -3
  136. package/lib/components/DataTable/tools/cells.d.ts +13 -0
  137. package/lib/components/DataTable/tools/cells.js +3 -6
  138. package/lib/components/DataTable/tools/filter.d.ts +26 -0
  139. package/lib/components/DataTable/tools/filter.js +8 -17
  140. package/lib/components/DataTable/tools/sorting.d.ts +42 -0
  141. package/lib/components/DataTable/tools/sorting.js +23 -53
  142. package/lib/components/DatePicker/DatePicker.d.ts +1 -1
  143. package/lib/components/DatePicker/DatePicker.js +19 -19
  144. package/lib/components/Dialog/index.d.ts +1 -1
  145. package/lib/components/Dropdown/Dropdown.Skeleton.d.ts +2 -2
  146. package/lib/components/Dropdown/Dropdown.Skeleton.js +1 -1
  147. package/lib/components/Dropdown/Dropdown.d.ts +7 -6
  148. package/lib/components/Dropdown/Dropdown.js +12 -8
  149. package/lib/components/FileUploader/FileUploaderButton.d.ts +1 -1
  150. package/lib/components/FileUploader/FileUploaderButton.js +1 -1
  151. package/lib/components/FileUploader/FileUploaderDropContainer.js +1 -1
  152. package/lib/components/FileUploader/FileUploaderItem.js +1 -1
  153. package/lib/components/FluidDatePickerInput/FluidDatePickerInput.d.ts +1 -1
  154. package/lib/components/FluidDatePickerInput/FluidDatePickerInput.js +4 -5
  155. package/lib/components/FluidDropdown/FluidDropdown.d.ts +1 -1
  156. package/lib/components/FluidSearch/FluidSearch.d.ts +3 -6
  157. package/lib/components/IconButton/index.d.ts +1 -1
  158. package/lib/components/IconButton/index.js +2 -18
  159. package/lib/components/ListBox/ListBox.d.ts +4 -5
  160. package/lib/components/ListBox/ListBox.js +7 -6
  161. package/lib/components/ListBox/ListBoxMenu.d.ts +4 -4
  162. package/lib/components/ListBox/ListBoxMenu.js +3 -1
  163. package/lib/components/ListBox/ListBoxMenuItem.d.ts +9 -8
  164. package/lib/components/ListBox/ListBoxPropTypes.d.ts +3 -3
  165. package/lib/components/ListBox/ListBoxPropTypes.js +4 -4
  166. package/lib/components/ListBox/index.d.ts +7 -5
  167. package/lib/components/ListBox/index.js +2 -2
  168. package/lib/components/Menu/Menu.js +9 -14
  169. package/lib/components/Menu/MenuItem.js +15 -4
  170. package/lib/components/Modal/Modal.js +9 -9
  171. package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +3 -2
  172. package/lib/components/MultiSelect/FilterableMultiSelect.js +2 -1
  173. package/lib/components/MultiSelect/MultiSelect.d.ts +8 -2
  174. package/lib/components/MultiSelect/MultiSelect.js +6 -3
  175. package/lib/components/Notification/Notification.js +1 -1
  176. package/lib/components/OverflowMenu/OverflowMenu.js +2 -21
  177. package/lib/components/OverflowMenu/index.d.ts +1 -1
  178. package/lib/components/OverflowMenu/index.js +2 -3
  179. package/lib/components/OverflowMenu/next/index.js +2 -18
  180. package/lib/components/OverflowMenuItem/OverflowMenuItem.d.ts +2 -4
  181. package/lib/components/OverflowMenuItem/OverflowMenuItem.js +4 -3
  182. package/lib/components/PageHeader/PageHeader.d.ts +160 -8
  183. package/lib/components/PageHeader/PageHeader.js +159 -19
  184. package/lib/components/PageHeader/index.d.ts +2 -2
  185. package/lib/components/PageHeader/index.js +6 -0
  186. package/lib/components/Popover/index.js +4 -21
  187. package/lib/components/Search/Search.d.ts +2 -5
  188. package/lib/components/Search/Search.js +24 -8
  189. package/lib/components/Stack/HStack.d.ts +2 -3
  190. package/lib/components/Stack/HStack.js +3 -6
  191. package/lib/components/Stack/Stack.d.ts +3 -4
  192. package/lib/components/Stack/Stack.js +2 -5
  193. package/lib/components/Stack/VStack.d.ts +2 -3
  194. package/lib/components/Stack/VStack.js +2 -1
  195. package/lib/components/Stack/index.d.ts +4 -4
  196. package/lib/components/TextArea/TextArea.js +2 -4
  197. package/lib/components/TimePicker/TimePicker.d.ts +3 -4
  198. package/lib/components/TimePicker/TimePicker.js +4 -3
  199. package/lib/components/TimePickerSelect/TimePickerSelect.d.ts +23 -4
  200. package/lib/components/TimePickerSelect/TimePickerSelect.js +4 -3
  201. package/lib/components/TreeView/TreeNode.js +13 -1
  202. package/lib/components/TreeView/TreeView.js +1 -1
  203. package/lib/index.js +2 -2
  204. package/lib/internal/FloatingMenu.js +9 -5
  205. package/lib/internal/environment.js +7 -0
  206. package/lib/internal/keyboard/navigation.d.ts +0 -10
  207. package/lib/internal/keyboard/navigation.js +0 -14
  208. package/lib/internal/useNoInteractiveChildren.js +7 -0
  209. package/lib/internal/useOutsideClick.js +3 -0
  210. package/lib/internal/wrapFocus.d.ts +49 -0
  211. package/lib/internal/wrapFocus.js +66 -53
  212. package/lib/tools/events.d.ts +17 -0
  213. package/lib/tools/events.js +10 -13
  214. package/lib/tools/mapPopoverAlign.d.ts +15 -0
  215. package/lib/tools/mapPopoverAlign.js +32 -0
  216. package/lib/tools/uniqueId.d.ts +7 -0
  217. package/lib/tools/uniqueId.js +3 -3
  218. package/lib/types/common.d.ts +0 -2
  219. package/package.json +9 -9
  220. package/telemetry.yml +3 -1
  221. package/es/tools/createPropAdapter.js +0 -40
  222. package/lib/tools/createPropAdapter.js +0 -44
@@ -13,20 +13,23 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
13
13
  var React = require('react');
14
14
  var cx = require('classnames');
15
15
  var usePrefix = require('../../internal/usePrefix.js');
16
+ var PropTypes = require('prop-types');
16
17
 
17
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
19
 
19
20
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
21
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
22
+ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
21
23
 
22
- const TableCell = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) => {
23
- let {
24
+ const frFn = React.forwardRef;
25
+ const TableCell = frFn((props, ref) => {
26
+ const {
24
27
  children,
25
28
  className,
26
29
  hasAILabelHeader,
27
30
  colSpan,
28
31
  ...rest
29
- } = _ref;
32
+ } = props;
30
33
  const prefix = usePrefix.usePrefix();
31
34
  const tableCellClassNames = cx__default["default"](className, {
32
35
  [`${prefix}--table-cell--column-slug`]: hasAILabelHeader
@@ -38,5 +41,27 @@ const TableCell = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref)
38
41
  }, rest), children);
39
42
  });
40
43
  TableCell.displayName = 'TableCell';
44
+ TableCell.propTypes = {
45
+ /**
46
+ * Pass in children that will be embedded in the table header label
47
+ */
48
+ children: PropTypes__default["default"].node,
49
+ /**
50
+ * Specify an optional className to be applied to the container node
51
+ */
52
+ className: PropTypes__default["default"].string,
53
+ /**
54
+ * The width of the expanded row's internal cell
55
+ */
56
+ colSpan: PropTypes__default["default"].number,
57
+ /**
58
+ * Specify if the table cell is in an AI column
59
+ */
60
+ hasAILabelHeader: PropTypes__default["default"].bool,
61
+ /**
62
+ * The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
63
+ */
64
+ headers: PropTypes__default["default"].string
65
+ };
41
66
 
42
67
  exports["default"] = TableCell;
@@ -1,11 +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
7
  import React from 'react';
8
- import { ForwardRefReturn } from '../../types/common';
9
8
  export interface TableToolbarActionProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onClick'> {
10
9
  /**
11
10
  * Pass in the children that will be rendered inside the TableToolbarAction
@@ -16,6 +15,5 @@ export interface TableToolbarActionProps extends Omit<React.HTMLAttributes<HTMLD
16
15
  */
17
16
  onClick: (event: React.MouseEvent<HTMLDivElement>) => void;
18
17
  }
19
- export type TableToolbarActionComponent = ForwardRefReturn<HTMLDivElement, TableToolbarActionProps>;
20
- declare const TableToolbarAction: TableToolbarActionComponent;
18
+ declare const TableToolbarAction: React.ForwardRefExoticComponent<TableToolbarActionProps & React.RefAttributes<HTMLDivElement>>;
21
19
  export default TableToolbarAction;
@@ -19,11 +19,12 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
19
19
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
20
20
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
21
21
 
22
- const TableToolbarAction = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) => {
23
- let {
22
+ const frFn = React.forwardRef;
23
+ const TableToolbarAction = frFn((props, ref) => {
24
+ const {
24
25
  children,
25
26
  ...rest
26
- } = _ref;
27
+ } = props;
27
28
  return /*#__PURE__*/React__default["default"].createElement(OverflowMenuItem["default"], _rollupPluginBabelHelpers["extends"]({
28
29
  ref: ref,
29
30
  itemText: children
@@ -0,0 +1,13 @@
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
+ */
7
+ /**
8
+ * Generates a unique cell ID by combining the row ID and header.
9
+ *
10
+ * Generic helper used to consolidate all call sites for getting a cell ID into
11
+ * one method.
12
+ */
13
+ export declare const getCellId: (rowId: string, header: string) => string;
@@ -10,13 +10,10 @@
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  /**
13
- * Generic helper used to consolidate all call sites for getting a cell id into
14
- * one method. The strategy currently is that a "cellId" is just the combination
15
- * of the row id and the header key used to access this field in a row.
13
+ * Generates a unique cell ID by combining the row ID and header.
16
14
  *
17
- * @param {string} rowId
18
- * @param {string} header
19
- * @returns {string}
15
+ * Generic helper used to consolidate all call sites for getting a cell ID into
16
+ * one method.
20
17
  */
21
18
  const getCellId = (rowId, header) => `${rowId}:${header}`;
22
19
 
@@ -0,0 +1,26 @@
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
+ */
7
+ /**
8
+ * Filters row IDs based on whether any of the cell values in the row include
9
+ * the input value as a substring. Boolean cell values are ignored.
10
+ */
11
+ export declare const defaultFilterRows: ({ rowIds, headers, cellsById, inputValue, getCellId, }: {
12
+ /** Table row IDs. */
13
+ rowIds: string[];
14
+ /** Table headers. */
15
+ headers: {
16
+ key: string;
17
+ }[];
18
+ /** Mapping of cell IDs to their corresponding cells. */
19
+ cellsById: Record<string, {
20
+ value: unknown;
21
+ }>;
22
+ /** Input value to search for. */
23
+ inputValue: string;
24
+ /** Function that returns a cell ID given a row ID and a header. */
25
+ getCellId: (rowId: string, header: string) => string;
26
+ }) => string[];
@@ -10,18 +10,8 @@
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  /**
13
- * Default implementation of how we filter rows internally. The idea behind this
14
- * implementation is to use the given list of row ids and headers to get the
15
- * individual cell values for a row. Then, we go through each cell value and see
16
- * if any of them includes the given inputValue.
17
- *
18
- * @param {object} config
19
- * @param {Array<string>} config.rowIds array of all the row ids in the table
20
- * @param {Array<object>} config.headers
21
- * @param {object} config.cellsById object containing a map of cell id to cell
22
- * @param {string} config.inputValue the current input value in the Table Search
23
- * @param {Function} config.getCellId
24
- * @returns {Array<string>} rowIds
13
+ * Filters row IDs based on whether any of the cell values in the row include
14
+ * the input value as a substring. Boolean cell values are ignored.
25
15
  */
26
16
  const defaultFilterRows = _ref => {
27
17
  let {
@@ -31,15 +21,16 @@ const defaultFilterRows = _ref => {
31
21
  inputValue,
32
22
  getCellId
33
23
  } = _ref;
24
+ const normalizedInput = inputValue.trim().toLowerCase();
25
+ if (!normalizedInput) return rowIds;
34
26
  return rowIds.filter(rowId => headers.some(_ref2 => {
35
27
  let {
36
28
  key
37
29
  } = _ref2;
38
- const id = getCellId(rowId, key);
39
- if (typeof cellsById[id].value === 'boolean') {
40
- return false;
41
- }
42
- return ('' + cellsById[id].value).toLowerCase().includes(inputValue.toLowerCase());
30
+ const cellId = getCellId(rowId, key);
31
+ const cell = cellsById[cellId];
32
+ if (typeof cell.value === 'boolean') return false;
33
+ return String(cell.value).toLowerCase().includes(normalizedInput);
43
34
  }));
44
35
  };
45
36
 
@@ -0,0 +1,42 @@
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
+ */
7
+ import { type DataTableSortState } from '../state/sortStates';
8
+ /**
9
+ * Compare two values to determine their order. If both values have the same
10
+ * type, the default sort algorithm will be used for those types. Otherwise, the
11
+ * values will be converted to strings for comparison.
12
+ */
13
+ export declare const compare: (a: any, b: any, locale?: string) => number;
14
+ interface Cell {
15
+ id: string;
16
+ value: any;
17
+ }
18
+ interface SortRowParams {
19
+ key: string;
20
+ sortDirection: DataTableSortState;
21
+ sortStates: Record<DataTableSortState, DataTableSortState>;
22
+ locale: string;
23
+ compare: typeof compare;
24
+ rowIds: string[];
25
+ }
26
+ interface SortRowsConfig {
27
+ rowIds: string[];
28
+ cellsById: Record<string, Cell>;
29
+ key: string;
30
+ sortDirection: DataTableSortState;
31
+ locale?: string;
32
+ sortRow?: (cellA: any, cellB: any, params: SortRowParams) => number;
33
+ }
34
+ /**
35
+ * Sorts table rows based on the provided column key and direction.
36
+ */
37
+ export declare const sortRows: ({ rowIds, cellsById, sortDirection, key, locale, sortRow, }: SortRowsConfig) => string[];
38
+ /**
39
+ * Sorts table rows based on the sort direction.
40
+ */
41
+ export declare const defaultSortRow: (cellA: any, cellB: any, { sortDirection, sortStates, locale, }: Pick<SortRowParams, "locale" | "sortDirection" | "sortStates">) => number;
42
+ export {};
@@ -13,76 +13,43 @@ var cells = require('./cells.js');
13
13
  var sortStates = require('../state/sortStates.js');
14
14
 
15
15
  /**
16
- * Compare two primitives to determine which comes first. Initially, this method
17
- * will try and figure out if both entries are the same type. If so, it will
18
- * apply the default sort algorithm for those types. Otherwise, it defaults to a
19
- * string conversion.
20
- *
21
- * @param {number|string} a
22
- * @param {number|string} b
23
- * @param {string} locale
24
- * @returns {number}
16
+ * Compare two values to determine their order. If both values have the same
17
+ * type, the default sort algorithm will be used for those types. Otherwise, the
18
+ * values will be converted to strings for comparison.
25
19
  */
26
20
  const compare = function (a, b) {
27
21
  let locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';
28
22
  // prevent multiple null values in one column (sorting breaks)
29
- a === null ? a = '' : null;
30
- b === null ? b = '' : null;
23
+ if (a === null) a = '';
24
+ if (b === null) b = '';
31
25
  if (typeof a === 'number' && typeof b === 'number') {
32
26
  return a - b;
33
27
  }
34
28
  if (typeof a === 'string' && typeof b === 'string') {
35
29
  return compareStrings(a, b, locale);
36
30
  }
37
-
38
- // if column has React elements, this should sort by the child string if there is one
39
- if (typeof a === 'object' && typeof b === 'object') {
40
- if (typeof a.props?.children === 'string' && typeof b.props?.children === 'string') {
41
- return compareStrings(a.props.children, b.props.children, locale);
42
- }
31
+ const aChild = a?.props?.children;
32
+ const bChild = b?.props?.children;
33
+ if (typeof aChild === 'string' && typeof bChild === 'string') {
34
+ return compareStrings(aChild, bChild, locale);
43
35
  }
44
- return compareStrings('' + a, '' + b, locale);
36
+ return compareStrings(String(a), String(b), locale);
45
37
  };
46
38
 
47
39
  /**
48
- * Use the built-in `localeCompare` function available on strings to compare two
49
- * strings.
40
+ * Compares two strings using `localeCompare`.
50
41
  *
51
- * @param {string} a
52
- * @param {string} b
53
- * @param {string} locale
54
- * @returns {number}
42
+ * Note: Uses numeric comparison if strings are numeric.
55
43
  */
56
44
  const compareStrings = function (a, b) {
57
45
  let locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';
58
- // Only set `numeric: true` if the string only contains numbers
59
- // https://stackoverflow.com/a/175787
60
- if (!isNaN(a) && !isNaN(parseFloat(a)) && !isNaN(b) && !isNaN(parseFloat(b))) {
61
- return a.localeCompare(b, locale, {
62
- numeric: true
63
- });
64
- }
65
- return a.localeCompare(b, locale);
46
+ const isNumeric = !isNaN(parseFloat(a)) && !isNaN(parseFloat(b));
47
+ return a.localeCompare(b, locale, {
48
+ numeric: isNumeric
49
+ });
66
50
  };
67
-
68
51
  /**
69
- * Default implementation of how we sort rows internally. The idea behind this
70
- * implementation is to use the given list of row ids to look up the cells in
71
- * the row by the given key. We then use the value of these cells and pipe them
72
- * into our local `compareStrings` method, including the locale where
73
- * appropriate.
74
- *
75
- * @param {object} config
76
- * @param {Array[string]} config.rowIds array of all the row ids in the table
77
- * @param {object} config.cellsById object containing a mapping of cell id to
78
- * cell
79
- * @param {string} config.key the header key that we use to lookup the cell
80
- * @param {string} [config.locale] optional locale used in the comparison
81
- * function
82
- * @param {string} config.sortDirection the sort direction used to determine the
83
- * order the comparison is called in
84
- * @param {Function} config.sortRow
85
- * @returns {Array[string]} array of sorted rowIds
52
+ * Sorts table rows based on the provided column key and direction.
86
53
  */
87
54
  const sortRows = _ref => {
88
55
  let {
@@ -96,16 +63,20 @@ const sortRows = _ref => {
96
63
  return rowIds.slice().sort((a, b) => {
97
64
  const cellA = cellsById[cells.getCellId(a, key)];
98
65
  const cellB = cellsById[cells.getCellId(b, key)];
99
- return sortRow(cellA && cellA.value, cellB && cellB.value, {
66
+ return sortRow(cellA?.value, cellB?.value, {
100
67
  key,
101
68
  sortDirection,
102
- locale,
103
69
  sortStates: sortStates.sortStates,
70
+ locale,
104
71
  compare,
105
72
  rowIds: [a, b]
106
73
  });
107
74
  });
108
75
  };
76
+
77
+ /**
78
+ * Sorts table rows based on the sort direction.
79
+ */
109
80
  const defaultSortRow = (cellA, cellB, _ref2) => {
110
81
  let {
111
82
  sortDirection,
@@ -119,6 +90,5 @@ const defaultSortRow = (cellA, cellB, _ref2) => {
119
90
  };
120
91
 
121
92
  exports.compare = compare;
122
- exports.compareStrings = compareStrings;
123
93
  exports.defaultSortRow = defaultSortRow;
124
94
  exports.sortRows = sortRows;
@@ -120,7 +120,7 @@ export interface DatePickerProps {
120
120
  * The value of the date value provided to flatpickr, could
121
121
  * be a date, a date number, a date string, an array of dates.
122
122
  */
123
- value?: string | number | (string | number | object)[] | object | undefined;
123
+ value?: DateOption | DateOption[];
124
124
  /**
125
125
  * Specify whether the control is currently in warning state (Fluid only)
126
126
  */
@@ -185,13 +185,14 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
185
185
  }
186
186
  }, []);
187
187
  const lastStartValue = React.useRef('');
188
+ const calendarRef = React.useRef(null);
188
189
  const [calendarCloseEvent, setCalendarCloseEvent] = React.useState(null);
189
190
 
190
191
  // fix datepicker deleting the selectedDate when the calendar closes
191
192
  const handleCalendarClose = React.useCallback((selectedDates, dateStr, instance) => {
192
193
  if (lastStartValue.current && selectedDates[0] && !startInputField.current.value) {
193
194
  startInputField.current.value = lastStartValue.current;
194
- calendarRef.current.setDate([startInputField.current.value, endInputField?.current?.value], true, calendarRef.current.config.dateFormat);
195
+ calendarRef.current?.setDate([startInputField.current.value, endInputField?.current?.value], true, calendarRef.current.config.dateFormat);
195
196
  }
196
197
  if (onClose) {
197
198
  onClose(selectedDates, dateStr, instance);
@@ -219,7 +220,6 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
219
220
  }
220
221
  }, [calendarCloseEvent, handleCalendarClose]);
221
222
  const endInputField = React.useRef(null);
222
- const calendarRef = React.useRef(null);
223
223
  const savedOnChange = useSavedCallback.useSavedCallback(onChange);
224
224
  const savedOnOpen = useSavedCallback.useSavedCallback(onOpen);
225
225
  const datePickerClasses = cx__default["default"](`${prefix}--date-picker`, {
@@ -336,7 +336,7 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
336
336
  const {
337
337
  current: end
338
338
  } = endInputField;
339
- const flatpickerconfig = {
339
+ const flatpickerConfig = {
340
340
  inline: inline ?? false,
341
341
  onClose: onCalendarClose,
342
342
  disableMobile: true,
@@ -382,7 +382,7 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
382
382
  },
383
383
  onValueUpdate: onHook
384
384
  };
385
- const calendar = flatpickr__default["default"](start, flatpickerconfig);
385
+ const calendar = flatpickr__default["default"](start, flatpickerConfig);
386
386
  calendarRef.current = calendar;
387
387
  function handleArrowDown(event) {
388
388
  if (match.match(event, keys.Escape)) {
@@ -395,10 +395,10 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
395
395
  const {
396
396
  calendarContainer,
397
397
  selectedDateElem: fpSelectedDateElem,
398
- todayDateElem: fptodayDateElem
398
+ todayDateElem: fpTodayDateElem
399
399
  } = calendar;
400
400
  const selectedDateElem = calendarContainer.querySelector('.selected') && fpSelectedDateElem;
401
- const todayDateElem = calendarContainer.querySelector('.today') && fptodayDateElem;
401
+ const todayDateElem = calendarContainer.querySelector('.today') && fpTodayDateElem;
402
402
  (selectedDateElem || todayDateElem || calendarContainer.querySelector('.flatpickr-day[tabindex]') || calendarContainer).focus();
403
403
  }
404
404
  }
@@ -473,7 +473,7 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
473
473
  }
474
474
  };
475
475
  // eslint-disable-next-line react-hooks/exhaustive-deps
476
- }, [savedOnChange, savedOnOpen, readOnly, closeOnSelect, hasInput]);
476
+ }, [savedOnChange, savedOnOpen, readOnly, closeOnSelect, hasInput, datePickerType]);
477
477
 
478
478
  // this hook allows consumers to access the flatpickr calendar
479
479
  // instance for cases where functions like open() or close()
@@ -484,44 +484,44 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
484
484
  }
485
485
  }));
486
486
  React.useEffect(() => {
487
- if (calendarRef?.current?.set) {
487
+ if (calendarRef.current?.set) {
488
488
  calendarRef.current.set({
489
489
  dateFormat
490
490
  });
491
491
  }
492
492
  }, [dateFormat]);
493
493
  React.useEffect(() => {
494
- if (calendarRef?.current?.set) {
494
+ if (calendarRef.current?.set) {
495
495
  calendarRef.current.set('minDate', minDate);
496
496
  }
497
497
  }, [minDate]);
498
498
  React.useEffect(() => {
499
- if (calendarRef?.current?.set) {
499
+ if (calendarRef.current?.set) {
500
500
  calendarRef.current.set('allowInput', allowInput);
501
501
  }
502
502
  }, [allowInput]);
503
503
  React.useEffect(() => {
504
- if (calendarRef?.current?.set) {
504
+ if (calendarRef.current?.set) {
505
505
  calendarRef.current.set('maxDate', maxDate);
506
506
  }
507
507
  }, [maxDate]);
508
508
  React.useEffect(() => {
509
- if (calendarRef?.current?.set && disable) {
509
+ if (calendarRef.current?.set && disable) {
510
510
  calendarRef.current.set('disable', disable);
511
511
  }
512
512
  }, [disable]);
513
513
  React.useEffect(() => {
514
- if (calendarRef?.current?.set && enable) {
514
+ if (calendarRef.current?.set && enable) {
515
515
  calendarRef.current.set('enable', enable);
516
516
  }
517
517
  }, [enable]);
518
518
  React.useEffect(() => {
519
- if (calendarRef?.current?.set && inline) {
519
+ if (calendarRef.current?.set && inline) {
520
520
  calendarRef.current.set('inline', inline);
521
521
  }
522
522
  }, [inline]);
523
523
  React.useEffect(() => {
524
- //when value prop is set to empty, this clears the faltpicker's calendar instance and text input
524
+ //when value prop is set to empty, this clears the flatpicker's calendar instance and text input
525
525
  if (value === '') {
526
526
  calendarRef.current?.clear();
527
527
  if (startInputField.current) {
@@ -540,9 +540,9 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
540
540
  }
541
541
  };
542
542
  const closeCalendar = event => {
543
- calendarRef.current.close();
543
+ calendarRef.current?.close();
544
544
  // Remove focus from endDate calendar input
545
- onCalendarClose(calendarRef.current.selectedDates, '', calendarRef.current, {
545
+ onCalendarClose(calendarRef.current?.selectedDates, '', calendarRef.current, {
546
546
  type: 'clickOutside'
547
547
  });
548
548
  };
@@ -552,7 +552,7 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
552
552
  };
553
553
  }, [calendarRef, startInputField, endInputField, onCalendarClose]);
554
554
  React.useEffect(() => {
555
- if (calendarRef?.current?.set) {
555
+ if (calendarRef.current?.set) {
556
556
  if (value !== undefined) {
557
557
  calendarRef.current.setDate(value);
558
558
  }
@@ -566,7 +566,7 @@ const DatePicker = /*#__PURE__*/React__default["default"].forwardRef(function Da
566
566
  React.useEffect(() => {
567
567
  if (!calendarRef.current || !startInputField.current) return;
568
568
  const handleKeyDown = event => {
569
- if (match.match(event, keys.Tab) && !event.shiftKey && document.activeElement === endInputField.current && calendarRef.current.isOpen) {
569
+ if (match.match(event, keys.Tab) && !event.shiftKey && document.activeElement === endInputField.current && calendarRef.current?.isOpen) {
570
570
  calendarRef.current.close();
571
571
  onCalendarClose(calendarRef.current.selectedDates, '', calendarRef.current, event);
572
572
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright IBM Corp. 2014, 2024
2
+ * Copyright IBM Corp. 2014, 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.
@@ -1,11 +1,11 @@
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
7
  import React from 'react';
8
- import { ListBoxSize } from '../ListBox';
8
+ import { type ListBoxSize } from '../ListBox';
9
9
  import { ReactAttr } from '../../types/common';
10
10
  export interface DropdownSkeletonProps extends ReactAttr<HTMLDivElement> {
11
11
  /**
@@ -54,7 +54,7 @@ DropdownSkeleton.propTypes = {
54
54
  /**
55
55
  * Specify the size of the ListBox.
56
56
  */
57
- size: ListBoxPropTypes.ListBoxSize
57
+ size: ListBoxPropTypes.ListBoxSizePropType
58
58
  };
59
59
 
60
60
  exports.DropdownSkeleton = DropdownSkeleton;
@@ -4,15 +4,15 @@
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, { ReactNode, Ref } from 'react';
8
8
  import { UseSelectProps } from 'downshift';
9
- import { type ListBoxMenuIconTranslationKey, ListBoxSize, ListBoxType } from '../ListBox';
9
+ import { type ListBoxMenuIconTranslationKey, type ListBoxSize, type ListBoxType } from '../ListBox';
10
10
  import { TranslateWithId, ReactAttr } from '../../types/common';
11
11
  type ExcludedAttributes = 'id' | 'onChange';
12
12
  export interface OnChangeData<ItemType> {
13
13
  selectedItem: ItemType | null;
14
14
  }
15
- export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>, ExcludedAttributes>, TranslateWithId<ListBoxMenuIconTranslationKey>, React.RefAttributes<HTMLDivElement> {
15
+ export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>, ExcludedAttributes>, TranslateWithId<ListBoxMenuIconTranslationKey> {
16
16
  /**
17
17
  * Specify a label to be read by screen readers on the container node
18
18
  * 'aria-label' of the ListBox component.
@@ -147,9 +147,10 @@ export interface DropdownProps<ItemType> extends Omit<ReactAttr<HTMLDivElement>,
147
147
  warnText?: ReactNode;
148
148
  }
149
149
  export type DropdownTranslationKey = ListBoxMenuIconTranslationKey;
150
- type DropdownComponentProps<ItemType> = React.PropsWithoutRef<React.PropsWithChildren<DropdownProps<ItemType>> & React.RefAttributes<HTMLButtonElement>>;
151
- export interface DropdownComponent {
152
- <ItemType>(props: DropdownComponentProps<ItemType>): React.ReactElement<any> | null;
150
+ interface DropdownComponent {
151
+ <ItemType>(props: DropdownProps<ItemType> & {
152
+ ref?: Ref<HTMLButtonElement>;
153
+ }): React.ReactElement<any> | null;
153
154
  }
154
155
  declare const _default: DropdownComponent;
155
156
  export default _default;
@@ -256,9 +256,9 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
256
256
 
257
257
  // needs to be Capitalized for react to render it correctly
258
258
  const ItemToElement = itemToElement;
259
- const toggleButtonProps = React.useMemo(() => getToggleButtonProps({
259
+ const toggleButtonProps = getToggleButtonProps({
260
260
  'aria-label': ariaLabel || deprecatedAriaLabel
261
- }), [getToggleButtonProps, ariaLabel, deprecatedAriaLabel, isOpen]);
261
+ });
262
262
  const helper = helperText && !isFluid ? /*#__PURE__*/React__default["default"].createElement("div", {
263
263
  id: helperId,
264
264
  className: helperClasses
@@ -330,7 +330,10 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
330
330
  }
331
331
  return /*#__PURE__*/React__default["default"].isValidElement(element) ? element : null;
332
332
  }, [slug, decorator]);
333
- const labelProps = ! /*#__PURE__*/React.isValidElement(titleText) ? getLabelProps() : null;
333
+ const allLabelProps = getLabelProps();
334
+ const labelProps = /*#__PURE__*/React.isValidElement(titleText) ? {
335
+ id: allLabelProps.id
336
+ } : allLabelProps;
334
337
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
335
338
  className: wrapperClasses
336
339
  }, other), titleText && /*#__PURE__*/React__default["default"].createElement("label", _rollupPluginBabelHelpers["extends"]({
@@ -377,9 +380,6 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
377
380
  item,
378
381
  index
379
382
  });
380
- if (item !== null && typeof item === 'object' && Object.prototype.hasOwnProperty.call(item, 'id')) {
381
- itemProps.id = item['id'];
382
- }
383
383
  const title = isObject && 'text' in item && itemToElement ? item.text : itemToString(item);
384
384
  return /*#__PURE__*/React__default["default"].createElement(index$1["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
385
385
  key: itemProps.id,
@@ -394,6 +394,10 @@ const Dropdown = /*#__PURE__*/React__default["default"].forwardRef((_ref, ref) =
394
394
  }));
395
395
  }))), !inline && !invalid && !warn && helper);
396
396
  });
397
+
398
+ // Workaround problems with forwardRef() and generics. In the long term, should stop using forwardRef().
399
+ // See https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref.
400
+
397
401
  Dropdown.displayName = 'Dropdown';
398
402
  Dropdown.propTypes = {
399
403
  /**
@@ -507,7 +511,7 @@ Dropdown.propTypes = {
507
511
  /**
508
512
  * Specify the size of the ListBox. Currently supports either `sm`, `md` or `lg` as an option.
509
513
  */
510
- size: ListBoxPropTypes.ListBoxSize,
514
+ size: ListBoxPropTypes.ListBoxSizePropType,
511
515
  /**
512
516
  * **Experimental**: Provide a `Slug` component to be rendered inside the `Dropdown` component
513
517
  */
@@ -524,7 +528,7 @@ Dropdown.propTypes = {
524
528
  /**
525
529
  * The dropdown type, `default` or `inline`
526
530
  */
527
- type: ListBoxPropTypes.ListBoxType,
531
+ type: ListBoxPropTypes.ListBoxTypePropType,
528
532
  /**
529
533
  * Specify whether the control is currently in warning state
530
534
  */
@@ -1,5 +1,5 @@
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.