@carbon/react 1.78.2 → 1.79.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 (249) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +835 -835
  2. package/es/components/Accordion/AccordionItem.js +2 -2
  3. package/es/components/Button/Button.d.ts +2 -3
  4. package/es/components/Button/Button.js +29 -19
  5. package/es/components/Button/ButtonBase.js +3 -1
  6. package/es/components/ChatButton/ChatButton.d.ts +2 -3
  7. package/es/components/ChatButton/ChatButton.js +1 -2
  8. package/es/components/ComboBox/ComboBox.js +34 -24
  9. package/es/components/ComposedModal/ComposedModal.js +65 -51
  10. package/es/components/ContainedList/ContainedListItem/ContainedListItem.d.ts +2 -2
  11. package/es/components/ContainedList/ContainedListItem/ContainedListItem.js +1 -1
  12. package/es/components/ContentSwitcher/ContentSwitcher.js +3 -3
  13. package/es/components/DataTable/TableBatchAction.d.ts +3 -3
  14. package/es/components/DataTable/TableBatchAction.js +1 -1
  15. package/es/components/DataTable/TableContainer.d.ts +1 -1
  16. package/es/components/DataTable/TableContainer.js +5 -4
  17. package/es/components/DataTable/TableExpandHeader.d.ts +6 -5
  18. package/es/components/DataTable/TableToolbarMenu.d.ts +2 -2
  19. package/es/components/DataTable/TableToolbarMenu.js +1 -1
  20. package/es/components/DatePicker/DatePicker.js +2 -2
  21. package/es/components/DatePicker/plugins/fixEventsPlugin.js +1 -1
  22. package/es/components/Dialog/index.d.ts +42 -4
  23. package/es/components/Dialog/index.js +177 -0
  24. package/es/components/ExpandableSearch/ExpandableSearch.js +2 -2
  25. package/es/components/FeatureFlags/index.d.ts +3 -1
  26. package/es/components/FeatureFlags/index.js +3 -0
  27. package/es/components/FileUploader/FileUploader.d.ts +1 -1
  28. package/es/components/FileUploader/FileUploader.js +2 -2
  29. package/es/components/FileUploader/FileUploaderButton.js +2 -2
  30. package/es/components/FileUploader/FileUploaderDropContainer.d.ts +1 -1
  31. package/es/components/FileUploader/FileUploaderDropContainer.js +6 -4
  32. package/es/components/FileUploader/FileUploaderItem.d.ts +1 -1
  33. package/es/components/FileUploader/FileUploaderItem.js +2 -2
  34. package/es/components/Grid/CSSGrid.js +18 -14
  35. package/es/components/Grid/Column.d.ts +2 -2
  36. package/es/components/Grid/Column.js +7 -8
  37. package/es/components/Grid/FlexGrid.js +7 -6
  38. package/es/components/Grid/GridTypes.d.ts +5 -3
  39. package/es/components/IconButton/index.d.ts +2 -2
  40. package/es/components/IconButton/index.js +4 -4
  41. package/es/components/Layer/index.d.ts +4 -6
  42. package/es/components/Layer/index.js +5 -6
  43. package/es/components/Link/Link.d.ts +2 -3
  44. package/es/components/Link/Link.js +1 -2
  45. package/es/components/ListBox/ListBoxMenuItem.d.ts +3 -3
  46. package/es/components/ListBox/ListBoxMenuItem.js +37 -15
  47. package/es/components/Menu/Menu.js +2 -2
  48. package/es/components/Menu/MenuItem.d.ts +2 -2
  49. package/es/components/Menu/MenuItem.js +3 -3
  50. package/es/components/Modal/Modal.js +121 -49
  51. package/es/components/ModalWrapper/ModalWrapper.js +1 -1
  52. package/es/components/MultiSelect/FilterableMultiSelect.js +3 -3
  53. package/es/components/MultiSelect/MultiSelect.js +2 -2
  54. package/es/components/MultiSelect/index.d.ts +1 -1
  55. package/es/components/MultiSelect/index.js +1 -8
  56. package/es/components/Notification/Notification.d.ts +5 -13
  57. package/es/components/Notification/Notification.js +3 -4
  58. package/es/components/OverflowMenu/OverflowMenu.d.ts +22 -201
  59. package/es/components/OverflowMenu/OverflowMenu.js +269 -338
  60. package/es/components/OverflowMenu/index.d.ts +5 -5
  61. package/es/components/OverflowMenu/index.js +2 -2
  62. package/es/components/OverflowMenu/next/index.d.ts +4 -4
  63. package/es/components/OverflowMenu/next/index.js +1 -1
  64. package/es/components/OverflowMenuItem/OverflowMenuItem.js +2 -2
  65. package/es/components/ProgressIndicator/ProgressIndicator.js +2 -2
  66. package/es/components/RadioTile/RadioTile.js +2 -2
  67. package/es/components/Search/Search.d.ts +2 -3
  68. package/es/components/Search/Search.js +4 -6
  69. package/es/components/Slider/Slider.d.ts +39 -44
  70. package/es/components/Slider/Slider.js +57 -59
  71. package/es/components/Tabs/Tabs.d.ts +3 -6
  72. package/es/components/Tabs/Tabs.js +16 -18
  73. package/es/components/Tag/DismissibleTag.d.ts +3 -5
  74. package/es/components/Tag/DismissibleTag.js +1 -2
  75. package/es/components/Tag/OperationalTag.d.ts +2 -3
  76. package/es/components/Tag/OperationalTag.js +1 -2
  77. package/es/components/Tag/SelectableTag.d.ts +3 -5
  78. package/es/components/Tag/SelectableTag.js +1 -2
  79. package/es/components/Tag/Tag.d.ts +2 -3
  80. package/es/components/Tag/Tag.js +1 -2
  81. package/es/components/Tile/Tile.d.ts +3 -5
  82. package/es/components/Tile/Tile.js +16 -10
  83. package/es/components/Toggletip/index.js +2 -2
  84. package/es/components/Tooltip/DefinitionTooltip.js +2 -2
  85. package/es/components/Tooltip/Tooltip.d.ts +1 -1
  86. package/es/components/Tooltip/Tooltip.js +2 -2
  87. package/es/components/TreeView/TreeNode.d.ts +3 -5
  88. package/es/components/TreeView/TreeNode.js +3 -4
  89. package/es/components/TreeView/TreeView.js +2 -2
  90. package/es/components/UIShell/HeaderContainer.js +2 -2
  91. package/es/components/UIShell/HeaderMenu.js +2 -2
  92. package/es/components/UIShell/HeaderPanel.js +2 -2
  93. package/es/components/UIShell/SideNav.d.ts +1 -1
  94. package/es/components/UIShell/SideNav.js +2 -2
  95. package/es/components/UIShell/SideNavHeader.d.ts +2 -3
  96. package/es/components/UIShell/SideNavHeader.js +1 -2
  97. package/es/components/UIShell/SideNavLink.d.ts +2 -2
  98. package/es/components/UIShell/SideNavLink.js +1 -1
  99. package/es/components/UIShell/SideNavMenu.d.ts +2 -2
  100. package/es/components/UIShell/SideNavMenu.js +3 -3
  101. package/es/components/UIShell/SwitcherItem.js +2 -2
  102. package/es/index.js +1 -1
  103. package/es/internal/FloatingMenu.d.ts +2 -2
  104. package/es/internal/FloatingMenu.js +8 -5
  105. package/es/internal/OptimizedResize.d.ts +18 -0
  106. package/es/internal/OptimizedResize.js +21 -24
  107. package/es/internal/createClassWrapper.d.ts +3 -3
  108. package/es/internal/createClassWrapper.js +4 -4
  109. package/es/internal/keyboard/index.d.ts +9 -0
  110. package/es/internal/keyboard/keys.d.ts +23 -0
  111. package/es/internal/keyboard/keys.js +2 -2
  112. package/es/internal/keyboard/match.d.ts +26 -0
  113. package/es/internal/keyboard/match.js +17 -41
  114. package/es/internal/keyboard/navigation.d.ts +37 -0
  115. package/es/internal/keyboard/navigation.js +15 -27
  116. package/es/internal/useMatchMedia.d.ts +8 -0
  117. package/es/internal/useMatchMedia.js +10 -20
  118. package/es/internal/useMergedRefs.js +3 -0
  119. package/es/internal/useNormalizedInputProps.d.ts +52 -0
  120. package/es/internal/useNormalizedInputProps.js +9 -36
  121. package/lib/components/Accordion/AccordionItem.js +2 -2
  122. package/lib/components/Button/Button.d.ts +2 -3
  123. package/lib/components/Button/Button.js +29 -19
  124. package/lib/components/Button/ButtonBase.js +3 -1
  125. package/lib/components/ChatButton/ChatButton.d.ts +2 -3
  126. package/lib/components/ChatButton/ChatButton.js +1 -2
  127. package/lib/components/ComboBox/ComboBox.js +34 -24
  128. package/lib/components/ComposedModal/ComposedModal.js +64 -50
  129. package/lib/components/ContainedList/ContainedListItem/ContainedListItem.d.ts +2 -2
  130. package/lib/components/ContainedList/ContainedListItem/ContainedListItem.js +1 -1
  131. package/lib/components/ContentSwitcher/ContentSwitcher.js +3 -3
  132. package/lib/components/DataTable/TableBatchAction.d.ts +3 -3
  133. package/lib/components/DataTable/TableBatchAction.js +1 -1
  134. package/lib/components/DataTable/TableContainer.d.ts +1 -1
  135. package/lib/components/DataTable/TableContainer.js +5 -4
  136. package/lib/components/DataTable/TableExpandHeader.d.ts +6 -5
  137. package/lib/components/DataTable/TableToolbarMenu.d.ts +2 -2
  138. package/lib/components/DataTable/TableToolbarMenu.js +1 -1
  139. package/lib/components/DatePicker/DatePicker.js +2 -2
  140. package/lib/components/DatePicker/plugins/fixEventsPlugin.js +1 -1
  141. package/lib/components/Dialog/index.d.ts +42 -4
  142. package/lib/components/Dialog/index.js +190 -0
  143. package/lib/components/ExpandableSearch/ExpandableSearch.js +2 -2
  144. package/lib/components/FeatureFlags/index.d.ts +3 -1
  145. package/lib/components/FeatureFlags/index.js +3 -0
  146. package/lib/components/FileUploader/FileUploader.d.ts +1 -1
  147. package/lib/components/FileUploader/FileUploader.js +2 -2
  148. package/lib/components/FileUploader/FileUploaderButton.js +2 -2
  149. package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +1 -1
  150. package/lib/components/FileUploader/FileUploaderDropContainer.js +6 -4
  151. package/lib/components/FileUploader/FileUploaderItem.d.ts +1 -1
  152. package/lib/components/FileUploader/FileUploaderItem.js +2 -2
  153. package/lib/components/Grid/CSSGrid.js +18 -14
  154. package/lib/components/Grid/Column.d.ts +2 -2
  155. package/lib/components/Grid/Column.js +7 -8
  156. package/lib/components/Grid/FlexGrid.js +7 -6
  157. package/lib/components/Grid/GridTypes.d.ts +5 -3
  158. package/lib/components/IconButton/index.d.ts +2 -2
  159. package/lib/components/IconButton/index.js +4 -4
  160. package/lib/components/Layer/index.d.ts +4 -6
  161. package/lib/components/Layer/index.js +5 -6
  162. package/lib/components/Link/Link.d.ts +2 -3
  163. package/lib/components/Link/Link.js +1 -2
  164. package/lib/components/ListBox/ListBoxMenuItem.d.ts +3 -3
  165. package/lib/components/ListBox/ListBoxMenuItem.js +36 -14
  166. package/lib/components/Menu/Menu.js +2 -2
  167. package/lib/components/Menu/MenuItem.d.ts +2 -2
  168. package/lib/components/Menu/MenuItem.js +3 -3
  169. package/lib/components/Modal/Modal.js +123 -51
  170. package/lib/components/ModalWrapper/ModalWrapper.js +1 -1
  171. package/lib/components/MultiSelect/FilterableMultiSelect.js +3 -3
  172. package/lib/components/MultiSelect/MultiSelect.js +2 -2
  173. package/lib/components/MultiSelect/index.d.ts +1 -1
  174. package/lib/components/MultiSelect/index.js +1 -8
  175. package/lib/components/Notification/Notification.d.ts +5 -13
  176. package/lib/components/Notification/Notification.js +3 -4
  177. package/lib/components/OverflowMenu/OverflowMenu.d.ts +22 -201
  178. package/lib/components/OverflowMenu/OverflowMenu.js +268 -336
  179. package/lib/components/OverflowMenu/index.d.ts +5 -5
  180. package/lib/components/OverflowMenu/index.js +2 -2
  181. package/lib/components/OverflowMenu/next/index.d.ts +4 -4
  182. package/lib/components/OverflowMenu/next/index.js +1 -1
  183. package/lib/components/OverflowMenuItem/OverflowMenuItem.js +2 -2
  184. package/lib/components/ProgressIndicator/ProgressIndicator.js +2 -2
  185. package/lib/components/RadioTile/RadioTile.js +2 -2
  186. package/lib/components/Search/Search.d.ts +2 -3
  187. package/lib/components/Search/Search.js +4 -6
  188. package/lib/components/Slider/Slider.d.ts +39 -44
  189. package/lib/components/Slider/Slider.js +57 -59
  190. package/lib/components/Tabs/Tabs.d.ts +3 -6
  191. package/lib/components/Tabs/Tabs.js +16 -18
  192. package/lib/components/Tag/DismissibleTag.d.ts +3 -5
  193. package/lib/components/Tag/DismissibleTag.js +1 -2
  194. package/lib/components/Tag/OperationalTag.d.ts +2 -3
  195. package/lib/components/Tag/OperationalTag.js +1 -2
  196. package/lib/components/Tag/SelectableTag.d.ts +3 -5
  197. package/lib/components/Tag/SelectableTag.js +1 -2
  198. package/lib/components/Tag/Tag.d.ts +2 -3
  199. package/lib/components/Tag/Tag.js +1 -2
  200. package/lib/components/Tile/Tile.d.ts +3 -5
  201. package/lib/components/Tile/Tile.js +16 -10
  202. package/lib/components/Toggletip/index.js +2 -2
  203. package/lib/components/Tooltip/DefinitionTooltip.js +2 -2
  204. package/lib/components/Tooltip/Tooltip.d.ts +1 -1
  205. package/lib/components/Tooltip/Tooltip.js +2 -2
  206. package/lib/components/TreeView/TreeNode.d.ts +3 -5
  207. package/lib/components/TreeView/TreeNode.js +3 -4
  208. package/lib/components/TreeView/TreeView.js +2 -2
  209. package/lib/components/UIShell/HeaderContainer.js +2 -2
  210. package/lib/components/UIShell/HeaderMenu.js +2 -2
  211. package/lib/components/UIShell/HeaderPanel.js +2 -2
  212. package/lib/components/UIShell/SideNav.d.ts +1 -1
  213. package/lib/components/UIShell/SideNav.js +2 -2
  214. package/lib/components/UIShell/SideNavHeader.d.ts +2 -3
  215. package/lib/components/UIShell/SideNavHeader.js +1 -2
  216. package/lib/components/UIShell/SideNavLink.d.ts +2 -2
  217. package/lib/components/UIShell/SideNavLink.js +1 -1
  218. package/lib/components/UIShell/SideNavMenu.d.ts +2 -2
  219. package/lib/components/UIShell/SideNavMenu.js +3 -3
  220. package/lib/components/UIShell/SwitcherItem.js +2 -2
  221. package/lib/index.js +2 -2
  222. package/lib/internal/FloatingMenu.d.ts +2 -2
  223. package/lib/internal/FloatingMenu.js +9 -6
  224. package/lib/internal/OptimizedResize.d.ts +18 -0
  225. package/lib/internal/OptimizedResize.js +21 -24
  226. package/lib/internal/createClassWrapper.d.ts +3 -3
  227. package/lib/internal/createClassWrapper.js +4 -4
  228. package/lib/internal/keyboard/index.d.ts +9 -0
  229. package/lib/internal/keyboard/keys.d.ts +23 -0
  230. package/lib/internal/keyboard/keys.js +2 -2
  231. package/lib/internal/keyboard/match.d.ts +26 -0
  232. package/lib/internal/keyboard/match.js +17 -41
  233. package/lib/internal/keyboard/navigation.d.ts +37 -0
  234. package/lib/internal/keyboard/navigation.js +15 -27
  235. package/lib/internal/useMatchMedia.d.ts +8 -0
  236. package/lib/internal/useMatchMedia.js +10 -20
  237. package/lib/internal/useMergedRefs.js +3 -0
  238. package/lib/internal/useNormalizedInputProps.d.ts +52 -0
  239. package/lib/internal/useNormalizedInputProps.js +9 -36
  240. package/package.json +6 -6
  241. package/scss/components/dialog/_dialog.scss +9 -0
  242. package/scss/components/dialog/_index.scss +9 -0
  243. package/telemetry.yml +1 -0
  244. package/es/components/Modal/next/index.d.ts +0 -171
  245. package/es/internal/focus/index.js +0 -15
  246. package/es/internal/useEffectOnce.js +0 -30
  247. package/lib/components/Modal/next/index.d.ts +0 -171
  248. package/lib/internal/focus/index.js +0 -19
  249. package/lib/internal/useEffectOnce.js +0 -34
@@ -8,44 +8,42 @@
8
8
  import window from 'window-or-global';
9
9
 
10
10
  // mdn resize function
11
- const OptimizedResize = function optimizedResize() {
11
+
12
+ /**
13
+ * A callback function to be executed on `resize`.
14
+ */
15
+
16
+ const OptimizedResize = (() => {
12
17
  const callbacks = [];
13
18
  let running = false;
14
-
15
- // run the actual callbacks
16
- function runCallbacks() {
19
+ const runCallbacks = () => {
17
20
  callbacks.forEach(callback => {
18
21
  callback();
19
22
  });
20
23
  running = false;
21
- }
22
-
23
- // fired on resize event
24
- function resize() {
24
+ };
25
+ const handleResize = () => {
25
26
  if (!running) {
26
27
  running = true;
27
28
  window.requestAnimationFrame(runCallbacks);
28
29
  }
29
- }
30
-
31
- // adds callback to loop
32
- function addCallback(callback) {
33
- if (callback) {
34
- const index = callbacks.indexOf(callback);
35
- if (index < 0) {
36
- callbacks.push(callback);
37
- }
30
+ };
31
+ const addCallback = callback => {
32
+ const index = callbacks.indexOf(callback);
33
+ if (index < 0) {
34
+ callbacks.push(callback);
38
35
  }
39
- }
36
+ };
40
37
  return {
41
- // public method to add additional callback
38
+ /** Adds a callback function to be executed on window `resize`. */
42
39
  add: callback => {
43
40
  if (!callbacks.length) {
44
- window.addEventListener('resize', resize);
41
+ window.addEventListener('resize', handleResize);
45
42
  }
46
43
  addCallback(callback);
47
44
  return {
48
- release() {
45
+ /** Removes the callback. */
46
+ remove: () => {
49
47
  const index = callbacks.indexOf(callback);
50
48
  if (index >= 0) {
51
49
  callbacks.splice(index, 1);
@@ -54,7 +52,6 @@ const OptimizedResize = function optimizedResize() {
54
52
  };
55
53
  }
56
54
  };
57
- }();
58
- var OptimizedResize$1 = OptimizedResize;
55
+ })();
59
56
 
60
- export { OptimizedResize$1 as default };
57
+ export { OptimizedResize };
@@ -1,12 +1,12 @@
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 { ComponentClass, FunctionComponent } from 'react';
7
+ import { type ComponentClass, type ForwardRefExoticComponent, type FunctionComponent, type PropsWithChildren } from 'react';
8
8
  /**
9
9
  * Wrap a class component with a functional component. This prevents an end-user
10
10
  * from being able to pass `ref` and access the underlying class instance.
11
11
  */
12
- export declare function createClassWrapper<Props>(Component: ComponentClass<Props>): FunctionComponent<Props>;
12
+ export declare const createClassWrapper: <Props extends PropsWithChildren>(Component: ComponentClass<Props> | ForwardRefExoticComponent<Props>) => FunctionComponent<Props>;
@@ -11,13 +11,13 @@ import React__default from 'react';
11
11
  * Wrap a class component with a functional component. This prevents an end-user
12
12
  * from being able to pass `ref` and access the underlying class instance.
13
13
  */
14
- function createClassWrapper(Component) {
15
- function ClassWrapper(props) {
14
+ const createClassWrapper = Component => {
15
+ const ClassWrapper = props => {
16
16
  return /*#__PURE__*/React__default.createElement(Component, props);
17
- }
17
+ };
18
18
  const name = Component.displayName || Component.name;
19
19
  ClassWrapper.displayName = `ClassWrapper(${name})`;
20
20
  return ClassWrapper;
21
- }
21
+ };
22
22
 
23
23
  export { createClassWrapper };
@@ -0,0 +1,9 @@
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
+ export * as keys from './keys';
8
+ export * from './match';
9
+ export * from './navigation';
@@ -0,0 +1,23 @@
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 { KeyboardEvent } from 'react';
8
+ export type Key = Pick<KeyboardEvent, 'which' | 'keyCode' | 'code'> & {
9
+ key?: string | string[];
10
+ };
11
+ export declare const Tab: Key;
12
+ export declare const Enter: Key;
13
+ export declare const Escape: Key;
14
+ export declare const Space: Key;
15
+ export declare const PageUp: Key;
16
+ export declare const PageDown: Key;
17
+ export declare const End: Key;
18
+ export declare const Home: Key;
19
+ export declare const ArrowLeft: Key;
20
+ export declare const ArrowUp: Key;
21
+ export declare const ArrowRight: Key;
22
+ export declare const ArrowDown: Key;
23
+ export declare const Delete: Key;
@@ -69,8 +69,8 @@ const ArrowDown = {
69
69
  };
70
70
  const Delete = {
71
71
  key: 'Delete',
72
- which: 8 ,
73
- keyCode: 8 ,
72
+ which: 8,
73
+ keyCode: 8,
74
74
  code: 'ArrowDecimal'
75
75
  };
76
76
 
@@ -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
+ import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
8
+ import type { Key } from './keys';
9
+ /**
10
+ * Check to see if at least one key code matches the key code of the
11
+ * given event.
12
+ *
13
+ * @param event - The event to test.
14
+ * @param keysToMatch - An array of key definitions to match against.
15
+ * @returns `true` if one of the keys matches.
16
+ */
17
+ export declare const matches: (event: ReactKeyboardEvent | KeyboardEvent, keysToMatch: Key[]) => boolean;
18
+ /**
19
+ * Check to see if the given key matches the corresponding keyboard event. Also
20
+ * supports passing in the value directly if you can't use the given event.
21
+ *
22
+ * @param eventOrCode - A `KeyboardEvent`, a number, or a string value.
23
+ * @param keyObj - An object with key properties to match against.
24
+ * @returns `true` if the event or code matches the key definition.
25
+ */
26
+ export declare const match: (eventOrCode: ReactKeyboardEvent | KeyboardEvent | number | string, { key, which, keyCode, code }: Key) => boolean;
@@ -5,65 +5,38 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- /**
9
- * @typedef Key
10
- * @property key {Array<string>|string}
11
- * @property which {number}
12
- * @property keyCode {number}
13
- */
14
-
15
8
  /**
16
9
  * Check to see if at least one key code matches the key code of the
17
10
  * given event.
18
11
  *
19
- * @example
20
- * import * as keys from '../keys';
21
- * import { matches } from '../match';
22
- *
23
- * function handleOnKeyDown(event) {
24
- * if (matches(event, [keys.Enter, keys.Space]) {
25
- * // ...
26
- * }
27
- * }
28
- *
29
- * @param {Event|React.SyntheticEvent} event
30
- * @param {Array<Key>} keysToMatch
31
- * @returns {boolean}
12
+ * @param event - The event to test.
13
+ * @param keysToMatch - An array of key definitions to match against.
14
+ * @returns `true` if one of the keys matches.
32
15
  */
33
- function matches(event, keysToMatch) {
16
+ const matches = (event, keysToMatch) => {
34
17
  for (let i = 0; i < keysToMatch.length; i++) {
35
18
  if (match(event, keysToMatch[i])) {
36
19
  return true;
37
20
  }
38
21
  }
39
22
  return false;
40
- }
23
+ };
41
24
 
42
25
  /**
43
26
  * Check to see if the given key matches the corresponding keyboard event. Also
44
- * supports passing in the value directly if you can't used the given event.
45
- *
46
- * @example
47
- * import * as keys from '../keys';
48
- * import { matches } from '../match';
49
- *
50
- * function handleOnKeyDown(event) {
51
- * if (match(event, keys.Enter) {
52
- * // ...
53
- * }
54
- * }
27
+ * supports passing in the value directly if you can't use the given event.
55
28
  *
56
- * @param {React.SyntheticEvent|Event|number|string} eventOrCode
57
- * @param {Key} key
58
- * @returns {boolean}
29
+ * @param eventOrCode - A `KeyboardEvent`, a number, or a string value.
30
+ * @param keyObj - An object with key properties to match against.
31
+ * @returns `true` if the event or code matches the key definition.
59
32
  */
60
- function match(eventOrCode) {
33
+ const match = (eventOrCode, _ref) => {
61
34
  let {
62
35
  key,
63
36
  which,
64
37
  keyCode,
65
38
  code
66
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
39
+ } = _ref;
67
40
  if (typeof eventOrCode === 'string') {
68
41
  return eventOrCode === key;
69
42
  }
@@ -71,9 +44,12 @@ function match(eventOrCode) {
71
44
  return eventOrCode === which || eventOrCode === keyCode;
72
45
  }
73
46
  if (eventOrCode.key && Array.isArray(key)) {
74
- return key.indexOf(eventOrCode.key) !== -1;
47
+ return key.includes(eventOrCode.key);
75
48
  }
76
- return eventOrCode.key === key || eventOrCode.which === which || eventOrCode.keyCode === keyCode || eventOrCode.code === code;
77
- }
49
+ return eventOrCode.key === key ||
50
+ // TODO: When can these checks for deprecated properties be deleted?
51
+ // Presumably, the `Key` type should also be pruned of these properties.
52
+ eventOrCode.which === which || eventOrCode.keyCode === keyCode || eventOrCode.code === code;
53
+ };
78
54
 
79
55
  export { match, matches };
@@ -0,0 +1,37 @@
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 { KeyboardEvent } from 'react';
8
+ /**
9
+ * A "ring buffer" function that takes an array and, depending on an ArrowRight
10
+ * or ArrowLeft key input, loops from last index to first or first index to last.
11
+ *
12
+ * @param key - the left or right arrow key (KeyboardEvent, number, or string)
13
+ * @param index - the current index in the array
14
+ * @param arrayLength - the total length of the array
15
+ *
16
+ * @example
17
+ * getNextIndex(keyCodes.RIGHT, 0, 4)
18
+ */
19
+ export declare const getNextIndex: (key: KeyboardEvent | number | string, index: number, arrayLength: number) => number | undefined;
20
+ /**
21
+ * A flag `node.compareDocumentPosition(target)` returns that indicates
22
+ * `target` is located earlier than `node` in the document or `target` contains `node`.
23
+ */
24
+ export declare const DOCUMENT_POSITION_BROAD_PRECEDING: number;
25
+ /**
26
+ * A flag `node.compareDocumentPosition(target)` returns that indicates
27
+ * `target` is located later than `node` in the document or `node` contains `target`.
28
+ */
29
+ export declare const DOCUMENT_POSITION_BROAD_FOLLOWING: number;
30
+ /**
31
+ * CSS selector that selects major nodes that are sequentially focusable.
32
+ */
33
+ export declare const selectorTabbable = "\n a[href], area[href], input:not([disabled]):not([tabindex='-1']),\n button:not([disabled]):not([tabindex='-1']),select:not([disabled]):not([tabindex='-1']),\n textarea:not([disabled]):not([tabindex='-1']),\n iframe, object, embed, *[tabindex]:not([tabindex='-1']):not([disabled]), *[contenteditable=true]\n";
34
+ /**
35
+ * CSS selector that selects major nodes that are click focusable.
36
+ */
37
+ export declare const selectorFocusable = "\n a[href], area[href], input:not([disabled]),\n button:not([disabled]),select:not([disabled]),\n textarea:not([disabled]),\n iframe, object, embed, *[tabindex]:not([disabled]), *[contenteditable=true]\n";
@@ -9,21 +9,16 @@ import { ArrowRight, ArrowLeft } from './keys.js';
9
9
  import { match } from './match.js';
10
10
 
11
11
  /**
12
- * Various utilities to help with a11y work
13
- */
14
-
15
- /**
16
- * A "ring buffer" function that takes an array and depending on an ArrowRight
17
- * or ArrowLeft key input loops from last index to first or first index to last.
12
+ * A "ring buffer" function that takes an array and, depending on an ArrowRight
13
+ * or ArrowLeft key input, loops from last index to first or first index to last.
18
14
  *
19
- * @param {string} key - the left or right arrow keys
20
- * @param {number} index - the current index in a given array
21
- * @param {number} arrayLength - the total length of the array
15
+ * @param key - the left or right arrow key (KeyboardEvent, number, or string)
16
+ * @param index - the current index in the array
17
+ * @param arrayLength - the total length of the array
22
18
  *
23
19
  * @example
24
- * getNextIndex(keyCodes.RIGHT, 0, 4)
20
+ * getNextIndex(keyCodes.RIGHT, 0, 4)
25
21
  */
26
-
27
22
  const getNextIndex = (key, index, arrayLength) => {
28
23
  if (match(key, ArrowRight)) {
29
24
  return (index + 1) % arrayLength;
@@ -31,30 +26,23 @@ const getNextIndex = (key, index, arrayLength) => {
31
26
  if (match(key, ArrowLeft)) {
32
27
  return (index + arrayLength - 1) % arrayLength;
33
28
  }
29
+ return;
34
30
  };
35
31
 
36
32
  /**
37
- * A flag `node.compareDocumentPosition(target)` returns,
38
- * that indicates `target` is located earlier than `node` in the document or `target` contains `node`.
33
+ * A flag `node.compareDocumentPosition(target)` returns that indicates
34
+ * `target` is located earlier than `node` in the document or `target` contains `node`.
39
35
  */
40
- const DOCUMENT_POSITION_BROAD_PRECEDING =
41
- // Checks `typeof Node` for `react-docgen`
42
- typeof Node !== 'undefined' &&
43
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
44
- Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_CONTAINS;
36
+ const DOCUMENT_POSITION_BROAD_PRECEDING = typeof Node !== 'undefined' ? Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_CONTAINS : 0;
45
37
 
46
38
  /**
47
- * A flag `node.compareDocumentPosition(target)` returns,
48
- * that indicates `target` is located later than `node` in the document or `node` contains `target`.
39
+ * A flag `node.compareDocumentPosition(target)` returns that indicates
40
+ * `target` is located later than `node` in the document or `node` contains `target`.
49
41
  */
50
- const DOCUMENT_POSITION_BROAD_FOLLOWING =
51
- // Checks `typeof Node` for `react-docgen`
52
- typeof Node !== 'undefined' &&
53
- // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
54
- Node.DOCUMENT_POSITION_FOLLOWING | Node.DOCUMENT_POSITION_CONTAINED_BY;
42
+ const DOCUMENT_POSITION_BROAD_FOLLOWING = typeof Node !== 'undefined' ? Node.DOCUMENT_POSITION_FOLLOWING | Node.DOCUMENT_POSITION_CONTAINED_BY : 0;
55
43
 
56
44
  /**
57
- * CSS selector that selects major nodes that are sequential-focusable.
45
+ * CSS selector that selects major nodes that are sequentially focusable.
58
46
  */
59
47
  const selectorTabbable = `
60
48
  a[href], area[href], input:not([disabled]):not([tabindex='-1']),
@@ -64,7 +52,7 @@ const selectorTabbable = `
64
52
  `;
65
53
 
66
54
  /**
67
- * CSS selector that selects major nodes that are click focusable
55
+ * CSS selector that selects major nodes that are click focusable.
68
56
  */
69
57
  const selectorFocusable = `
70
58
  a[href], area[href], input:not([disabled]),
@@ -0,0 +1,8 @@
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
+ /** Listens to changes in a media query and returns whether it matches. */
8
+ export declare const useMatchMedia: (mediaQuery: string) => boolean;
@@ -8,37 +8,27 @@
8
8
  import { useState, useEffect } from 'react';
9
9
  import { canUseDOM } from './environment.js';
10
10
 
11
- function useMatchMedia(mediaQueryString) {
11
+ /** Listens to changes in a media query and returns whether it matches. */
12
+ const useMatchMedia = mediaQuery => {
12
13
  const [matches, setMatches] = useState(() => {
13
14
  if (canUseDOM) {
14
- const mediaQueryList = window.matchMedia(mediaQueryString);
15
+ const mediaQueryList = window.matchMedia(mediaQuery);
15
16
  return mediaQueryList.matches;
16
17
  }
17
18
  return false;
18
19
  });
19
20
  useEffect(() => {
20
- function listener(event) {
21
+ const listener = event => {
21
22
  setMatches(event.matches);
22
- }
23
- const mediaQueryList = window.matchMedia(mediaQueryString);
24
- // Support fallback to `addListener` for broader browser support
25
- if (mediaQueryList.addEventListener) {
26
- mediaQueryList.addEventListener('change', listener);
27
- } else {
28
- mediaQueryList.addListener(listener);
29
- }
30
-
31
- // Make sure the media query list is in sync with the matches state
23
+ };
24
+ const mediaQueryList = window.matchMedia(mediaQuery);
25
+ mediaQueryList.addEventListener('change', listener);
32
26
  setMatches(mediaQueryList.matches);
33
27
  return () => {
34
- if (mediaQueryList.addEventListener) {
35
- mediaQueryList.removeEventListener('change', listener);
36
- } else {
37
- mediaQueryList.removeListener(listener);
38
- }
28
+ mediaQueryList.removeEventListener('change', listener);
39
29
  };
40
- }, [mediaQueryString]);
30
+ }, [mediaQuery]);
41
31
  return matches;
42
- }
32
+ };
43
33
 
44
34
  export { useMatchMedia };
@@ -7,6 +7,9 @@
7
7
 
8
8
  import { useCallback } from 'react';
9
9
 
10
+ // TODO: Investigate updating this hook based on the following code from
11
+ // https://github.com/carbon-design-system/carbon/pull/18611:
12
+ // https://github.com/adamalston/carbon/blob/dd403b6b10de3d8a6ccd8d2e21174c908c1e890a/packages/react/src/components/ListBox/ListBoxMenuItem.tsx#L23-L46
10
13
  /**
11
14
  * Combine multiple refs into a single ref. This use useful when you have two
12
15
  * refs from both `React.forwardRef` and `useRef` that you would like to add to
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright IBM Corp. 2021, 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 ReactNode } from 'react';
8
+ interface InputProps {
9
+ /** The ID for the input. */
10
+ id: string;
11
+ /** Whether the input is read-only. */
12
+ readOnly?: boolean;
13
+ /** Whether the input is disabled. */
14
+ disabled: boolean;
15
+ /** Whether the input is an invalid state. */
16
+ invalid: boolean;
17
+ /** The message displayed when the input is invalid. */
18
+ invalidText?: ReactNode;
19
+ /** Whether the input is in a warning state. */
20
+ warn: boolean;
21
+ /** The message displayed when the input is in a warning state. */
22
+ warnText?: ReactNode;
23
+ }
24
+ interface NormalizedInputProps {
25
+ /** Disabled state. */
26
+ disabled: boolean;
27
+ /** Invalid state. */
28
+ invalid: boolean;
29
+ /** The generated ID for the error message. */
30
+ invalidId: string;
31
+ /** The generated ID for the helper text. */
32
+ helperId: string;
33
+ /** Warning state. */
34
+ warn: boolean;
35
+ /** The generated ID for the warning message. */
36
+ warnId: string;
37
+ /** A React node containing the validation message. */
38
+ validation: ReactNode | null;
39
+ /** A React component representing the accompanying icon. */
40
+ icon: ComponentType | null;
41
+ }
42
+ /**
43
+ * Returns an object containing normalized properties for an input component.
44
+ *
45
+ * This hook ensures that only one of `invalid` or `warn` is active (with
46
+ * `invalid` taking precedence) and that `readOnly` overrides the `disabled`,
47
+ * `invalid`, and `warn` states. It generates unique IDs for error, warning, and
48
+ * helper messages, and conditionally provides the appropriate validation
49
+ * message and accompanying icon.
50
+ */
51
+ export declare const useNormalizedInputProps: ({ id, readOnly, disabled, invalid, invalidText, warn, warnText, }: InputProps) => NormalizedInputProps;
52
+ export {};
@@ -7,47 +7,20 @@
7
7
 
8
8
  import React__default from 'react';
9
9
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
10
- import { usePrefix } from './usePrefix.js';
11
10
  import '../components/Text/index.js';
11
+ import { usePrefix } from './usePrefix.js';
12
12
  import { Text } from '../components/Text/Text.js';
13
13
 
14
14
  /**
15
- * @typedef {object} InputProps
16
- * @property {string} id - The input's id
17
- * @property {boolean | undefined} readOnly - Whether the input should be readonly
18
- * @property {boolean} disabled - Whether the input should be disabled
19
- * @property {boolean} invalid - Whether the input should be marked as invalid
20
- * @property {React.ReactNode | undefined} invalidText - The validation message displayed in case the input is considered invalid
21
- * @property {boolean} warn - Whether the input should be in warning state
22
- * @property {React.ReactNode | undefined} warnText - The validation message displayed in case the input is in warning state
23
- */
24
-
25
- /**
26
- * @typedef {object} NormalizedInputProps
27
- * @property {boolean} disabled - Whether the input is disabled
28
- * @property {boolean} invalid - Whether the input is invalid (takes precedence over warn)
29
- * @property {string} invalidId - The invalid message's id
30
- * @property {string} helperId - id used for helper text
31
- * @property {boolean} warn - Whether the input is in warning state
32
- * @property {string} warnId - The warning message's id
33
- * @property {React.ReactNode | null} validation – React node rendering the appropriate validation message (if any)
34
- * @property {React.ReactNode | null} icon – React node rendering the appropriate accompanying icon (if any)
35
- */
36
-
37
- /**
38
- * Returns an object containing non-colliding props and additional, generated ones.
39
- * This hook ensures that only either "invalid" or "warn" is true but never both at
40
- * the same time. Regardless whether "invalid" or "warn", the appropriate validation
41
- * message is passed as "validation". If the input should be accompanied by an icon
42
- * (to visually represent a readonly, invalid or warning state), the appropriate icon
43
- * is passed as "icon".
44
- * It also ensure that neither "invalid", nor "warn", nor "disabled" are enabled when
45
- * "readonly" is passed as "readonly" takes precedence over these variants.
15
+ * Returns an object containing normalized properties for an input component.
46
16
  *
47
- * @param {InputProps} props - The props passed to the component
48
- * @returns {NormalizedInputProps}
17
+ * This hook ensures that only one of `invalid` or `warn` is active (with
18
+ * `invalid` taking precedence) and that `readOnly` overrides the `disabled`,
19
+ * `invalid`, and `warn` states. It generates unique IDs for error, warning, and
20
+ * helper messages, and conditionally provides the appropriate validation
21
+ * message and accompanying icon.
49
22
  */
50
- function useNormalizedInputProps(_ref) {
23
+ const useNormalizedInputProps = _ref => {
51
24
  let {
52
25
  id,
53
26
  readOnly,
@@ -84,6 +57,6 @@ function useNormalizedInputProps(_ref) {
84
57
  }, warnText);
85
58
  }
86
59
  return normalizedProps;
87
- }
60
+ };
88
61
 
89
62
  export { useNormalizedInputProps };
@@ -15,13 +15,13 @@ var cx = require('classnames');
15
15
  var PropTypes = require('prop-types');
16
16
  var React = require('react');
17
17
  require('../Text/index.js');
18
+ var keys = require('../../internal/keyboard/keys.js');
19
+ var match = require('../../internal/keyboard/match.js');
18
20
  var useId = require('../../internal/useId.js');
19
21
  var deprecate = require('../../prop-types/deprecate.js');
20
22
  var usePrefix = require('../../internal/usePrefix.js');
21
23
  var AccordionProvider = require('./AccordionProvider.js');
22
- var match = require('../../internal/keyboard/match.js');
23
24
  var Text = require('../Text/Text.js');
24
- var keys = require('../../internal/keyboard/keys.js');
25
25
 
26
26
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
27
27
 
@@ -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.
@@ -50,8 +50,7 @@ export interface ButtonBaseProps extends React.ButtonHTMLAttributes<HTMLButtonEl
50
50
  */
51
51
  rel?: React.AnchorHTMLAttributes<HTMLAnchorElement>['rel'];
52
52
  /**
53
- * Optional prop to allow overriding the icon rendering.
54
- * Can be a React component class
53
+ * A component used to render an icon.
55
54
  */
56
55
  renderIcon?: React.ElementType;
57
56
  /**