@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
@@ -10,38 +10,38 @@
10
10
  Object.defineProperty(exports, '__esModule', { value: true });
11
11
 
12
12
  var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
13
- var FloatingMenu = require('../../internal/FloatingMenu.js');
14
13
  var React = require('react');
15
- var ClickListener = require('../../internal/ClickListener.js');
16
- var index = require('../IconButton/index.js');
17
14
  var iconsReact = require('@carbon/icons-react');
18
- var usePrefix = require('../../internal/usePrefix.js');
19
- var PropTypes = require('prop-types');
20
15
  var cx = require('classnames');
21
- var deprecate = require('../../prop-types/deprecate.js');
22
16
  var invariant = require('invariant');
23
- var mergeRefs = require('../../tools/mergeRefs.js');
17
+ var PropTypes = require('prop-types');
18
+ var ClickListener = require('../../internal/ClickListener.js');
19
+ var FloatingMenu = require('../../internal/FloatingMenu.js');
20
+ var keys = require('../../internal/keyboard/keys.js');
21
+ var match = require('../../internal/keyboard/match.js');
24
22
  var noopFn = require('../../internal/noopFn.js');
23
+ var usePrefix = require('../../internal/usePrefix.js');
24
+ var deprecate = require('../../prop-types/deprecate.js');
25
+ var mergeRefs = require('../../tools/mergeRefs.js');
25
26
  var setupGetInstanceId = require('../../tools/setupGetInstanceId.js');
26
- var match = require('../../internal/keyboard/match.js');
27
- var keys = require('../../internal/keyboard/keys.js');
27
+ var index = require('../IconButton/index.js');
28
28
 
29
29
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
30
30
 
31
31
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
32
- var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
33
32
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
34
33
  var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
34
+ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
35
35
 
36
36
  const getInstanceId = setupGetInstanceId["default"]();
37
- const on = function (element) {
37
+ const on = function (target) {
38
38
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
39
39
  args[_key - 1] = arguments[_key];
40
40
  }
41
- element.addEventListener(...args);
41
+ target.addEventListener(...args);
42
42
  return {
43
43
  release() {
44
- element.removeEventListener(...args);
44
+ target.removeEventListener(...args);
45
45
  return null;
46
46
  }
47
47
  };
@@ -49,7 +49,6 @@ const on = function (element) {
49
49
 
50
50
  /**
51
51
  * The CSS property names of the arrow keyed by the floating menu direction.
52
- * @type {[key: string]: string}
53
52
  */
54
53
  const triggerButtonPositionProps = {
55
54
  [FloatingMenu.DIRECTION_TOP]: 'bottom',
@@ -57,13 +56,22 @@ const triggerButtonPositionProps = {
57
56
  };
58
57
 
59
58
  /**
60
- * Determines how the position of arrow should affect the floating menu position.
61
- * @type {[key: string]: number}
59
+ * Determines how the position of the arrow should affect the floating menu
60
+ * position.
62
61
  */
63
62
  const triggerButtonPositionFactors = {
64
63
  [FloatingMenu.DIRECTION_TOP]: -2,
65
64
  [FloatingMenu.DIRECTION_BOTTOM]: -1
66
65
  };
66
+
67
+ /**
68
+ * Calculates the offset for the floating menu.
69
+ *
70
+ * @param menuBody - The menu body with the menu arrow.
71
+ * @param direction - The floating menu direction.
72
+ * @returns The adjustment of the floating menu position, upon the position of
73
+ * the menu arrow.
74
+ */
67
75
  const getMenuOffset = (menuBody, direction, trigger, flip) => {
68
76
  const triggerButtonPositionProp = triggerButtonPositionProps[direction];
69
77
  const triggerButtonPositionFactor = triggerButtonPositionFactors[direction];
@@ -92,324 +100,254 @@ const getMenuOffset = (menuBody, direction, trigger, flip) => {
92
100
  };
93
101
  }
94
102
  };
95
- class OverflowMenu extends React__default["default"].Component {
96
- constructor() {
97
- super(...arguments);
98
- _rollupPluginBabelHelpers.defineProperty(this, "state", {
99
- open: false,
100
- // Set a default value for 'open'
101
- hasMountedTrigger: false,
102
- // Set a default value for 'hasMountedTrigger'
103
- click: false // Set a default value for 'click'
104
- });
105
- _rollupPluginBabelHelpers.defineProperty(this, "instanceId", getInstanceId());
106
- /**
107
- * The handle of `onfocusin` or `focus` event handler.
108
- * @private
109
- */
110
- _rollupPluginBabelHelpers.defineProperty(this, "_hFocusIn", null);
111
- /**
112
- * The timeout handle for handling `blur` event.
113
- * @private
114
- */
115
- _rollupPluginBabelHelpers.defineProperty(this, "_hBlurTimeout", void 0);
116
- /**
117
- * The element ref of the tooltip's trigger button.
118
- * @type {React.RefObject<HTMLElement>}
119
- * @private
120
- */
121
- _rollupPluginBabelHelpers.defineProperty(this, "_triggerRef", /*#__PURE__*/React__default["default"].createRef());
122
- _rollupPluginBabelHelpers.defineProperty(this, "handleClick", evt => {
123
- const {
124
- onClick = noopFn.noopFn
125
- } = this.props;
126
- this.setState({
127
- click: true
128
- });
129
- if (!this._menuBody || !this._menuBody.contains(evt.target)) {
130
- this.setState({
131
- open: !this.state.open
132
- });
133
- onClick(evt);
134
- }
135
- });
136
- _rollupPluginBabelHelpers.defineProperty(this, "closeMenuAndFocus", () => {
137
- const wasClicked = this.state.click;
138
- const wasOpen = this.state.open;
139
- this.closeMenu(() => {
140
- if (wasOpen && !wasClicked) {
141
- this.focusMenuEl();
142
- }
143
- });
144
- });
145
- _rollupPluginBabelHelpers.defineProperty(this, "closeMenuOnEscape", () => {
146
- const wasOpen = this.state.open;
147
- this.closeMenu(() => {
148
- if (wasOpen) {
149
- this.focusMenuEl();
150
- }
151
- });
152
- });
153
- _rollupPluginBabelHelpers.defineProperty(this, "handleKeyPress", evt => {
154
- if (this.state.open && match.matches(evt, [keys.ArrowUp, keys.ArrowRight, keys.ArrowDown, keys.ArrowLeft])) {
155
- evt.preventDefault();
156
- }
103
+ const OverflowMenu = /*#__PURE__*/React.forwardRef((_ref, ref) => {
104
+ let {
105
+ ['aria-label']: ariaLabel = null,
106
+ ariaLabel: deprecatedAriaLabel,
107
+ children,
108
+ className,
109
+ direction = FloatingMenu.DIRECTION_BOTTOM,
110
+ flipped = false,
111
+ focusTrap = true,
112
+ iconClass,
113
+ iconDescription = 'Options',
114
+ id,
115
+ light,
116
+ menuOffset = getMenuOffset,
117
+ menuOffsetFlip = getMenuOffset,
118
+ menuOptionsClass,
119
+ onClick = noopFn.noopFn,
120
+ onClose = noopFn.noopFn,
121
+ onOpen = noopFn.noopFn,
122
+ open: openProp,
123
+ renderIcon: IconElement = iconsReact.OverflowMenuVertical,
124
+ selectorPrimaryFocus = '[data-floating-menu-primary-focus]',
125
+ size = 'md',
126
+ ...other
127
+ } = _ref;
128
+ const prefix = React.useContext(usePrefix.PrefixContext);
129
+ const [open, setOpen] = React.useState(openProp ?? false);
130
+ const [click, setClick] = React.useState(false);
131
+ const [hasMountedTrigger, setHasMountedTrigger] = React.useState(false);
132
+ /** The handle of `onfocusin` or `focus` event handler. */
133
+ const hFocusIn = React.useRef(null);
134
+ const instanceId = React.useRef(getInstanceId());
135
+ const menuBodyRef = React.useRef(null);
136
+ const menuItemRefs = React.useRef({});
137
+ const prevOpenProp = React.useRef(openProp);
138
+ const prevOpenState = React.useRef(open);
139
+ /** The element ref of the tooltip's trigger button. */
140
+ const triggerRef = React.useRef(null);
157
141
 
158
- // Close the overflow menu on escape
159
- if (match.matches(evt, [keys.Escape])) {
160
- this.closeMenuOnEscape();
142
+ // Sync open prop changes.
143
+ React.useEffect(() => {
144
+ if (prevOpenProp.current !== openProp) {
145
+ setOpen(!!openProp);
146
+ prevOpenProp.current = openProp;
147
+ }
148
+ }, [openProp]);
149
+
150
+ // Mark trigger as mounted.
151
+ React.useEffect(() => {
152
+ if (triggerRef.current) {
153
+ setHasMountedTrigger(true);
154
+ }
155
+ }, []);
161
156
 
162
- // Stop the esc keypress from bubbling out and closing something it shouldn't
163
- evt.stopPropagation();
157
+ // Call `onClose` when menu closes.
158
+ React.useEffect(() => {
159
+ if (!open && prevOpenState.current) {
160
+ onClose();
161
+ }
162
+ prevOpenState.current = open;
163
+ }, [open, onClose]);
164
+ const focusMenuEl = React.useCallback(() => {
165
+ if (triggerRef.current) {
166
+ triggerRef.current.focus();
167
+ }
168
+ }, []);
169
+ const closeMenu = React.useCallback(onCloseMenu => {
170
+ setOpen(false);
171
+ // Optional callback to be executed after the state as been set to close
172
+ if (onCloseMenu) {
173
+ onCloseMenu();
174
+ }
175
+ onClose();
176
+ }, [onClose]);
177
+ const closeMenuAndFocus = React.useCallback(() => {
178
+ const wasClicked = click;
179
+ const wasOpen = open;
180
+ closeMenu(() => {
181
+ if (wasOpen && !wasClicked) {
182
+ focusMenuEl();
164
183
  }
165
184
  });
166
- _rollupPluginBabelHelpers.defineProperty(this, "handleClickOutside", evt => {
167
- if (this.state.open && (!this._menuBody || !this._menuBody.contains(evt.target))) {
168
- this.closeMenu();
185
+ }, [click, open, closeMenu, focusMenuEl]);
186
+ const closeMenuOnEscape = React.useCallback(() => {
187
+ const wasOpen = open;
188
+ closeMenu(() => {
189
+ if (wasOpen) {
190
+ focusMenuEl();
169
191
  }
170
192
  });
171
- _rollupPluginBabelHelpers.defineProperty(this, "closeMenu", onCloseMenu => {
172
- const {
173
- onClose = noopFn.noopFn
174
- } = this.props;
175
- this.setState({
176
- open: false
177
- }, () => {
178
- // Optional callback to be executed after the state as been set to close
179
- if (onCloseMenu) {
180
- onCloseMenu();
181
- }
182
- onClose();
183
- });
184
- });
185
- _rollupPluginBabelHelpers.defineProperty(this, "focusMenuEl", () => {
186
- const {
187
- current: triggerEl
188
- } = this._triggerRef;
189
- if (triggerEl) {
190
- triggerEl.focus();
191
- }
192
- });
193
- /**
194
- * Focuses the next enabled overflow menu item given the currently focused
195
- * item index and direction to move
196
- * @param {object} params
197
- * @param {number} params.currentIndex - the index of the currently focused
198
- * overflow menu item in the list of overflow menu items
199
- * @param {number} params.direction - number denoting the direction to move
200
- * focus (1 for forwards, -1 for backwards)
201
- */
202
- _rollupPluginBabelHelpers.defineProperty(this, "handleOverflowMenuItemFocus", _ref => {
203
- let {
204
- currentIndex,
205
- direction
206
- } = _ref;
207
- const enabledIndices = React__default["default"].Children.toArray(this.props.children).reduce((acc, curr, i) => {
208
- if (/*#__PURE__*/React__default["default"].isValidElement(curr) && !curr.props.disabled) {
209
- acc.push(i);
210
- }
211
- return acc;
212
- }, []);
213
- const nextValidIndex = (() => {
214
- const nextIndex = enabledIndices.indexOf(currentIndex) + direction;
215
- switch (nextIndex) {
216
- case -1:
217
- return enabledIndices.length - 1;
218
- case enabledIndices.length:
219
- return 0;
220
- default:
221
- return nextIndex;
222
- }
223
- })();
224
- const overflowMenuItem = this[`overflowMenuItem${enabledIndices[nextValidIndex]}`];
225
- overflowMenuItem?.focus();
226
- });
227
- /**
228
- * Handles the floating menu being unmounted or non-floating menu being
229
- * mounted or unmounted.
230
- * @param {Element} menuBody The DOM element of the menu body.
231
- * @private
232
- */
233
- _rollupPluginBabelHelpers.defineProperty(this, "_menuBody", null);
234
- _rollupPluginBabelHelpers.defineProperty(this, "_bindMenuBody", menuBody => {
235
- if (!menuBody) {
236
- this._menuBody = menuBody;
193
+ }, [open, closeMenu, focusMenuEl]);
194
+ const handleClick = evt => {
195
+ setClick(true);
196
+ if (!menuBodyRef.current || !menuBodyRef.current.contains(evt.target)) {
197
+ setOpen(prev => !prev);
198
+ onClick(evt);
199
+ }
200
+ };
201
+ const handleKeyPress = evt => {
202
+ if (open && match.matches(evt, [keys.ArrowUp, keys.ArrowRight, keys.ArrowDown, keys.ArrowLeft])) {
203
+ evt.preventDefault();
204
+ }
205
+
206
+ // Close the overflow menu on escape
207
+ if (match.matches(evt, [keys.Escape])) {
208
+ closeMenuOnEscape();
209
+
210
+ // Stop the esc keypress from bubbling out and closing something it shouldn't
211
+ evt.stopPropagation();
212
+ }
213
+ };
214
+ const handleClickOutside = evt => {
215
+ if (open && (!menuBodyRef.current || !menuBodyRef.current.contains(evt.target))) {
216
+ closeMenu();
217
+ }
218
+ };
219
+
220
+ /**
221
+ * Focuses the next enabled overflow menu item given the currently focused
222
+ * item index and direction to move.
223
+ */
224
+ const handleOverflowMenuItemFocus = _ref2 => {
225
+ let {
226
+ currentIndex,
227
+ direction
228
+ } = _ref2;
229
+ const enabledIndices = React.Children.toArray(children).reduce((acc, curr, i) => {
230
+ if (/*#__PURE__*/React.isValidElement(curr) && !curr.props.disabled) {
231
+ acc.push(i);
237
232
  }
238
- if (!menuBody && this._hFocusIn) {
239
- this._hFocusIn = this._hFocusIn.release();
233
+ return acc;
234
+ }, []);
235
+ const nextValidIndex = (() => {
236
+ const nextIndex = enabledIndices.indexOf(currentIndex) + direction;
237
+ switch (nextIndex) {
238
+ case -1:
239
+ return enabledIndices.length - 1;
240
+ case enabledIndices.length:
241
+ return 0;
242
+ default:
243
+ return nextIndex;
240
244
  }
241
- });
242
- /**
243
- * Handles the floating menu being placed.
244
- * @param {Element} menuBody The DOM element of the menu body.
245
- * @private
246
- */
247
- _rollupPluginBabelHelpers.defineProperty(this, "_handlePlace", menuBody => {
248
- const {
249
- onOpen = noopFn.noopFn
250
- } = this.props;
251
- if (menuBody) {
252
- this._menuBody = menuBody;
253
- const hasFocusin = 'onfocusin' in window;
254
- const focusinEventName = hasFocusin ? 'focusin' : 'focus';
255
- this._hFocusIn = on(menuBody.ownerDocument, focusinEventName, event => {
256
- const target = ClickListener["default"].getEventTarget(event);
257
- const {
258
- current: triggerEl
259
- } = this._triggerRef;
260
- if (typeof target.matches === 'function') {
261
- if (!menuBody.contains(target) && triggerEl && !target.matches(`.${this.context}--overflow-menu:first-child,.${this.context}--overflow-menu-options:first-child`)) {
262
- this.closeMenuAndFocus();
263
- }
264
- }
265
- }, !hasFocusin);
266
- onOpen();
245
+ })();
246
+ const overflowMenuItem = menuItemRefs.current[enabledIndices[nextValidIndex]];
247
+ overflowMenuItem?.focus();
248
+ };
249
+ const bindMenuBody = menuBody => {
250
+ if (!menuBody) {
251
+ menuBodyRef.current = menuBody;
252
+ }
253
+ if (!menuBody && hFocusIn.current) {
254
+ hFocusIn.current = hFocusIn.current.release();
255
+ }
256
+ };
257
+ const handlePlace = menuBody => {
258
+ if (!menuBody) return;
259
+ menuBodyRef.current = menuBody;
260
+ const hasFocusin = 'onfocusin' in window;
261
+ const focusinEventName = hasFocusin ? 'focusin' : 'focus';
262
+ hFocusIn.current = on(menuBody.ownerDocument, focusinEventName, event => {
263
+ const target = event.target;
264
+ const triggerEl = triggerRef.current;
265
+ if (typeof target.matches === 'function') {
266
+ if (!menuBody.contains(target) && triggerEl && !target.matches(`.${prefix}--overflow-menu:first-child, .${prefix}--overflow-menu-options:first-child`)) {
267
+ closeMenuAndFocus();
268
+ }
267
269
  }
268
- });
269
- /**
270
- * @returns {Element} The DOM element where the floating menu is placed in.
271
- */
272
- _rollupPluginBabelHelpers.defineProperty(this, "_getTarget", () => {
273
- const {
274
- current: triggerEl
275
- } = this._triggerRef;
276
- return triggerEl instanceof Element && triggerEl.closest('[data-floating-menu-container]') || document.body;
277
- });
278
- }
279
- componentDidUpdate(_, prevState) {
280
- const {
281
- onClose = noopFn.noopFn
282
- } = this.props;
283
- if (!this.state.open && prevState.open) {
284
- onClose();
270
+ }, !hasFocusin);
271
+ onOpen();
272
+ };
273
+ const getTarget = () => {
274
+ const triggerEl = triggerRef.current;
275
+ if (triggerEl instanceof Element) {
276
+ return triggerEl.closest('[data-floating-menu-container]') || document.body;
285
277
  }
286
- }
287
- componentDidMount() {
288
- // ensure that if open=true on first render, we wait
289
- // to render the floating menu until the trigger ref is not null
290
- if (this._triggerRef.current) {
291
- this.setState({
292
- hasMountedTrigger: true
278
+ return document.body;
279
+ };
280
+ const menuBodyId = `overflow-menu-${instanceId.current}__menu-body`;
281
+ const overflowMenuClasses = cx__default["default"](className, `${prefix}--overflow-menu`, {
282
+ [`${prefix}--overflow-menu--open`]: open,
283
+ [`${prefix}--overflow-menu--light`]: light,
284
+ [`${prefix}--overflow-menu--${size}`]: size
285
+ });
286
+ const overflowMenuOptionsClasses = cx__default["default"](menuOptionsClass, `${prefix}--overflow-menu-options`, {
287
+ [`${prefix}--overflow-menu--flip`]: flipped,
288
+ [`${prefix}--overflow-menu-options--open`]: open,
289
+ [`${prefix}--overflow-menu-options--light`]: light,
290
+ [`${prefix}--overflow-menu-options--${size}`]: size
291
+ });
292
+ const overflowMenuIconClasses = cx__default["default"](`${prefix}--overflow-menu__icon`, iconClass);
293
+ const childrenWithProps = React.Children.toArray(children).map((child, index) => {
294
+ if (/*#__PURE__*/React.isValidElement(child)) {
295
+ const childElement = child;
296
+ return /*#__PURE__*/React.cloneElement(childElement, {
297
+ closeMenu: childElement.props.closeMenu || closeMenuAndFocus,
298
+ handleOverflowMenuItemFocus,
299
+ ref: el => {
300
+ menuItemRefs.current[index] = el;
301
+ },
302
+ index
293
303
  });
294
304
  }
295
- }
296
- static getDerivedStateFromProps(_ref2, state) {
297
- let {
298
- open
299
- } = _ref2;
300
- const {
301
- prevOpen
302
- } = state;
303
- return prevOpen === open ? null : {
304
- open,
305
- prevOpen: open
306
- };
307
- }
308
- componentWillUnmount() {
309
- if (typeof this._hBlurTimeout === 'number') {
310
- clearTimeout(this._hBlurTimeout);
311
- this._hBlurTimeout = undefined;
312
- }
313
- }
314
- render() {
315
- const prefix = this.context;
316
- const {
317
- id,
318
- ['aria-label']: ariaLabel = null,
319
- ariaLabel: deprecatedAriaLabel,
320
- children,
321
- iconDescription = 'Options',
322
- direction = FloatingMenu.DIRECTION_BOTTOM,
323
- flipped = false,
324
- focusTrap = true,
325
- menuOffset = getMenuOffset,
326
- menuOffsetFlip = getMenuOffset,
327
- iconClass,
328
- onClick = noopFn.noopFn,
329
- // eslint-disable-line
330
- onOpen = noopFn.noopFn,
331
- // eslint-disable-line
332
- selectorPrimaryFocus = '[data-floating-menu-primary-focus]',
333
- // eslint-disable-line
334
- renderIcon: IconElement = iconsReact.OverflowMenuVertical,
335
- // eslint-disable-next-line react/prop-types
336
- innerRef: ref,
337
- menuOptionsClass,
338
- light,
339
- size = 'md',
340
- ...other
341
- } = this.props;
342
- const {
343
- open = false
344
- } = this.state;
345
- const overflowMenuClasses = cx__default["default"](this.props.className, `${prefix}--overflow-menu`, {
346
- [`${prefix}--overflow-menu--open`]: open,
347
- [`${prefix}--overflow-menu--light`]: light,
348
- [`${prefix}--overflow-menu--${size}`]: size
349
- });
350
- const overflowMenuOptionsClasses = cx__default["default"](menuOptionsClass, `${prefix}--overflow-menu-options`, {
351
- [`${prefix}--overflow-menu--flip`]: this.props.flipped,
352
- [`${prefix}--overflow-menu-options--open`]: open,
353
- [`${prefix}--overflow-menu-options--light`]: light,
354
- [`${prefix}--overflow-menu-options--${size}`]: size
355
- });
356
- const overflowMenuIconClasses = cx__default["default"](`${prefix}--overflow-menu__icon`, iconClass);
357
- const childrenWithProps = React__default["default"].Children.toArray(children).map((child, index) => /*#__PURE__*/React__default["default"].isValidElement(child) ? /*#__PURE__*/React__default["default"].cloneElement(child, {
358
- // @ts-expect-error: PropTypes are not expressive enough to cover this case
359
- closeMenu: child.props.closeMenu || this.closeMenuAndFocus,
360
- handleOverflowMenuItemFocus: this.handleOverflowMenuItemFocus,
361
- ref: e => {
362
- this[`overflowMenuItem${index}`] = e;
363
- },
364
- index
365
- }) : null);
366
- const menuBodyId = `overflow-menu-${this.instanceId}__menu-body`;
367
- const menuBody = /*#__PURE__*/React__default["default"].createElement("ul", {
368
- className: overflowMenuOptionsClasses,
369
- tabIndex: -1,
370
- role: "menu",
371
- "aria-label": ariaLabel || deprecatedAriaLabel,
372
- onKeyDown: this.handleKeyPress,
373
- id: menuBodyId
374
- }, childrenWithProps);
375
- const wrappedMenuBody = /*#__PURE__*/React__default["default"].createElement(FloatingMenu.FloatingMenu, {
376
- focusTrap: focusTrap,
377
- triggerRef: this._triggerRef,
378
- menuDirection: direction,
379
- menuOffset: flipped ? menuOffsetFlip : menuOffset,
380
- menuRef: this._bindMenuBody,
381
- flipped: this.props.flipped,
382
- target: this._getTarget,
383
- onPlace: this._handlePlace,
384
- selectorPrimaryFocus: this.props.selectorPrimaryFocus
385
- }, /*#__PURE__*/React__default["default"].cloneElement(menuBody, {
386
- 'data-floating-menu-direction': direction
387
- }));
388
- const iconProps = {
389
- className: overflowMenuIconClasses,
390
- 'aria-label': iconDescription
391
- };
392
- return /*#__PURE__*/React__default["default"].createElement(ClickListener["default"], {
393
- onClickOutside: this.handleClickOutside
394
- }, /*#__PURE__*/React__default["default"].createElement("span", {
395
- className: `${prefix}--overflow-menu__wrapper`,
396
- "aria-owns": open ? menuBodyId : undefined
397
- }, /*#__PURE__*/React__default["default"].createElement(index.IconButton, _rollupPluginBabelHelpers["extends"]({}, other, {
398
- type: "button",
399
- "aria-haspopup": true,
400
- "aria-expanded": open,
401
- "aria-controls": open ? menuBodyId : undefined,
402
- className: overflowMenuClasses,
403
- onClick: this.handleClick,
404
- id: id,
405
- ref: mergeRefs["default"](this._triggerRef, ref),
406
- size: size,
407
- label: iconDescription,
408
- kind: "ghost"
409
- }), /*#__PURE__*/React__default["default"].createElement(IconElement, iconProps)), open && this.state.hasMountedTrigger && wrappedMenuBody));
410
- }
411
- }
412
- _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
305
+ return null;
306
+ });
307
+ const menuBody = /*#__PURE__*/React__default["default"].createElement("ul", {
308
+ className: overflowMenuOptionsClasses,
309
+ tabIndex: -1,
310
+ role: "menu",
311
+ "aria-label": ariaLabel || deprecatedAriaLabel,
312
+ onKeyDown: handleKeyPress,
313
+ id: menuBodyId
314
+ }, childrenWithProps);
315
+ const wrappedMenuBody = /*#__PURE__*/React__default["default"].createElement(FloatingMenu.FloatingMenu, {
316
+ focusTrap: focusTrap,
317
+ triggerRef: triggerRef,
318
+ menuDirection: direction,
319
+ menuOffset: flipped ? menuOffsetFlip : menuOffset,
320
+ menuRef: bindMenuBody,
321
+ flipped: flipped,
322
+ target: getTarget,
323
+ onPlace: handlePlace,
324
+ selectorPrimaryFocus: selectorPrimaryFocus
325
+ }, /*#__PURE__*/React.cloneElement(menuBody, {
326
+ 'data-floating-menu-direction': direction
327
+ }));
328
+ return /*#__PURE__*/React__default["default"].createElement(ClickListener["default"], {
329
+ onClickOutside: handleClickOutside
330
+ }, /*#__PURE__*/React__default["default"].createElement("span", {
331
+ className: `${prefix}--overflow-menu__wrapper`,
332
+ "aria-owns": open ? menuBodyId : undefined
333
+ }, /*#__PURE__*/React__default["default"].createElement(index.IconButton, _rollupPluginBabelHelpers["extends"]({}, other, {
334
+ type: "button",
335
+ "aria-haspopup": true,
336
+ "aria-expanded": open,
337
+ "aria-controls": open ? menuBodyId : undefined,
338
+ className: overflowMenuClasses,
339
+ onClick: handleClick,
340
+ id: id,
341
+ ref: mergeRefs["default"](triggerRef, ref),
342
+ size: size,
343
+ label: iconDescription,
344
+ kind: "ghost"
345
+ }), /*#__PURE__*/React__default["default"].createElement(IconElement, {
346
+ className: overflowMenuIconClasses,
347
+ "aria-label": iconDescription
348
+ })), open && hasMountedTrigger && wrappedMenuBody));
349
+ });
350
+ OverflowMenu.propTypes = {
413
351
  /**
414
352
  * Specify a label to be read by screen readers on the container node
415
353
  */
@@ -460,15 +398,15 @@ _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
460
398
  * The adjustment in position applied to the floating menu.
461
399
  */
462
400
  menuOffset: PropTypes__default["default"].oneOfType([PropTypes__default["default"].shape({
463
- top: PropTypes__default["default"].number,
464
- left: PropTypes__default["default"].number
401
+ top: PropTypes__default["default"].number.isRequired,
402
+ left: PropTypes__default["default"].number.isRequired
465
403
  }), PropTypes__default["default"].func]),
466
404
  /**
467
405
  * The adjustment in position applied to the floating menu.
468
406
  */
469
407
  menuOffsetFlip: PropTypes__default["default"].oneOfType([PropTypes__default["default"].shape({
470
- top: PropTypes__default["default"].number,
471
- left: PropTypes__default["default"].number
408
+ top: PropTypes__default["default"].number.isRequired,
409
+ left: PropTypes__default["default"].number.isRequired
472
410
  }), PropTypes__default["default"].func]),
473
411
  /**
474
412
  * The class to apply to the menu options
@@ -499,8 +437,9 @@ _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
499
437
  */
500
438
  open: PropTypes__default["default"].bool,
501
439
  /**
502
- * Function called to override icon rendering.
440
+ * A component used to render an icon.
503
441
  */
442
+ // @ts-expect-error: PropTypes are not expressive enough to cover this case
504
443
  renderIcon: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object]),
505
444
  /**
506
445
  * Specify a CSS selector that matches the DOM element that should
@@ -511,15 +450,8 @@ _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "propTypes", {
511
450
  * Specify the size of the OverflowMenu. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
512
451
  */
513
452
  size: PropTypes__default["default"].oneOf(['sm', 'md', 'lg'])
514
- });
515
- _rollupPluginBabelHelpers.defineProperty(OverflowMenu, "contextType", usePrefix.PrefixContext);
516
- (() => {
517
- const forwardRef = (props, ref) => /*#__PURE__*/React__default["default"].createElement(OverflowMenu, _rollupPluginBabelHelpers["extends"]({}, props, {
518
- innerRef: ref
519
- }));
520
- forwardRef.displayName = 'OverflowMenu';
521
- return /*#__PURE__*/React__default["default"].forwardRef(forwardRef);
522
- })();
453
+ };
523
454
 
524
455
  exports.OverflowMenu = OverflowMenu;
456
+ exports["default"] = OverflowMenu;
525
457
  exports.getMenuOffset = getMenuOffset;