@carbon/react 1.24.0 → 1.26.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 (197) hide show
  1. package/es/components/Button/Button.js +2 -2
  2. package/es/components/CodeSnippet/CodeSnippet.js +13 -115
  3. package/es/components/ComboBox/ComboBox.d.ts +6 -0
  4. package/es/components/ComboBox/ComboBox.js +19 -172
  5. package/es/components/ComboButton/index.js +164 -0
  6. package/es/components/ComposedModal/ComposedModal.js +1 -2
  7. package/es/components/DataTable/Table.d.ts +74 -0
  8. package/es/components/DataTable/Table.js +4 -2
  9. package/es/components/DataTable/TableCell.d.ts +10 -0
  10. package/es/components/DataTable/TableContext.d.ts +13 -0
  11. package/es/components/DataTable/TableContext.js +2 -2
  12. package/es/components/DataTable/TableExpandRow.d.ts +67 -0
  13. package/es/components/DataTable/TableExpandedRow.d.ts +32 -0
  14. package/es/components/DataTable/TableHead.d.ts +10 -0
  15. package/es/components/DataTable/TableHeader.d.ts +64 -0
  16. package/es/components/DataTable/TableHeader.js +23 -28
  17. package/es/components/DataTable/TableRow.d.ts +32 -0
  18. package/es/components/DataTable/TableSelectAll.js +1 -1
  19. package/es/components/DataTable/TableSelectRow.js +1 -3
  20. package/es/components/DataTable/TableToolbar.d.ts +19 -0
  21. package/es/components/DataTable/TableToolbar.js +1 -1
  22. package/es/components/DataTable/TableToolbarAction.d.ts +21 -0
  23. package/es/components/DataTable/TableToolbarContent.d.ts +19 -0
  24. package/es/components/DataTable/TableToolbarMenu.d.ts +24 -0
  25. package/es/components/DataTable/TableToolbarMenu.js +3 -3
  26. package/es/components/DataTable/TableToolbarSearch.js +1 -0
  27. package/es/components/DataTable/tools/sorting.js +2 -1
  28. package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +107 -0
  29. package/es/components/Dropdown/Dropdown.d.ts +6 -0
  30. package/es/components/Dropdown/Dropdown.js +8 -145
  31. package/es/components/ExpandableSearch/ExpandableSearch.js +1 -0
  32. package/es/components/FileUploader/FileUploader.js +1 -1
  33. package/es/components/FileUploader/FileUploaderButton.js +2 -0
  34. package/es/components/FileUploader/FileUploaderDropContainer.js +30 -18
  35. package/es/components/FileUploader/FileUploaderItem.js +2 -1
  36. package/es/components/FileUploader/Filename.js +8 -2
  37. package/es/components/FluidTextArea/FluidTextArea.js +12 -1
  38. package/es/components/IconButton/index.js +1 -0
  39. package/es/components/InlineCheckbox/InlineCheckbox.js +7 -53
  40. package/es/components/ListBox/ListBoxSelection.js +4 -23
  41. package/es/components/ListBox/next/ListBoxSelection.js +2 -23
  42. package/es/components/Menu/Menu.js +50 -29
  43. package/es/components/Menu/MenuItem.js +1 -0
  44. package/es/components/MenuButton/index.js +127 -0
  45. package/es/components/Modal/Modal.js +4 -3
  46. package/es/components/MultiSelect/FilterableMultiSelect.js +46 -144
  47. package/es/components/MultiSelect/MultiSelect.d.ts +1 -1
  48. package/es/components/MultiSelect/MultiSelect.js +48 -28
  49. package/es/components/Notification/Notification.js +27 -264
  50. package/es/components/NumberInput/NumberInput.js +9 -1
  51. package/es/components/OverflowMenu/OverflowMenu.js +13 -139
  52. package/es/components/OverflowMenuItem/OverflowMenuItem.d.ts +58 -0
  53. package/es/components/OverflowMenuItem/OverflowMenuItem.js +12 -7
  54. package/es/components/OverflowMenuV2/index.js +15 -51
  55. package/es/components/Popover/index.d.ts +5 -1
  56. package/es/components/Popover/index.js +37 -9
  57. package/es/components/RadioButton/RadioButton.Skeleton.d.ts +25 -0
  58. package/es/components/RadioButton/RadioButton.Skeleton.js +3 -3
  59. package/es/components/RadioButton/RadioButton.d.ts +64 -0
  60. package/es/components/RadioButton/RadioButton.js +19 -17
  61. package/es/components/RadioButtonGroup/RadioButtonGroup.d.ts +80 -0
  62. package/es/components/RadioButtonGroup/RadioButtonGroup.js +88 -26
  63. package/es/components/RadioTile/RadioTile.js +6 -6
  64. package/es/components/Search/Search.Skeleton.d.ts +36 -0
  65. package/es/components/Search/Search.js +3 -2
  66. package/es/components/Search/index.js +1 -0
  67. package/es/components/Select/Select.d.ts +89 -0
  68. package/es/components/SelectItem/SelectItem.d.ts +62 -0
  69. package/es/components/SelectItem/SelectItem.js +2 -4
  70. package/es/components/SelectItemGroup/SelectItemGroup.d.ts +52 -0
  71. package/es/components/SkeletonText/SkeletonText.js +1 -1
  72. package/es/components/StructuredList/StructuredList.js +11 -39
  73. package/es/components/Tabs/Tabs.js +29 -6
  74. package/es/components/TextArea/TextArea.Skeleton.d.ts +33 -0
  75. package/es/components/TextArea/TextArea.Skeleton.js +5 -5
  76. package/es/components/TextArea/TextArea.d.ts +9 -2
  77. package/es/components/TextArea/TextArea.js +31 -8
  78. package/es/components/TextArea/index.js +1 -0
  79. package/es/components/TextInput/TextInput.Skeleton.d.ts +33 -0
  80. package/es/components/TextInput/index.js +1 -0
  81. package/es/components/Tile/Tile.js +15 -8
  82. package/es/components/Toggle/Toggle.js +8 -19
  83. package/es/components/Tooltip/DefinitionTooltip.d.ts +52 -0
  84. package/es/components/Tooltip/DefinitionTooltip.js +2 -2
  85. package/es/components/Tooltip/Tooltip.d.ts +117 -0
  86. package/es/components/Tooltip/Tooltip.js +6 -4
  87. package/es/components/Tooltip/index.d.ts +9 -0
  88. package/es/components/UIShell/HeaderMenu.js +13 -4
  89. package/es/components/UIShell/HeaderMenuItem.js +17 -4
  90. package/es/index.d.ts +2 -0
  91. package/es/index.js +5 -3
  92. package/es/internal/ClickListener.js +1 -2
  93. package/es/internal/keyboard/match.js +1 -1
  94. package/es/internal/useAttachedMenu.js +85 -0
  95. package/es/internal/useDelayedState.d.ts +19 -0
  96. package/es/internal/useDelayedState.js +7 -3
  97. package/es/internal/useId.js +1 -1
  98. package/es/tools/wrapComponent.js +9 -0
  99. package/lib/components/Button/Button.js +2 -2
  100. package/lib/components/CodeSnippet/CodeSnippet.js +13 -115
  101. package/lib/components/ComboBox/ComboBox.d.ts +6 -0
  102. package/lib/components/ComboBox/ComboBox.js +18 -171
  103. package/lib/components/ComboButton/index.js +174 -0
  104. package/lib/components/ComposedModal/ComposedModal.js +1 -2
  105. package/lib/components/DataTable/Table.d.ts +74 -0
  106. package/lib/components/DataTable/Table.js +4 -2
  107. package/lib/components/DataTable/TableCell.d.ts +10 -0
  108. package/lib/components/DataTable/TableContext.d.ts +13 -0
  109. package/lib/components/DataTable/TableContext.js +2 -2
  110. package/lib/components/DataTable/TableExpandRow.d.ts +67 -0
  111. package/lib/components/DataTable/TableExpandedRow.d.ts +32 -0
  112. package/lib/components/DataTable/TableHead.d.ts +10 -0
  113. package/lib/components/DataTable/TableHeader.d.ts +64 -0
  114. package/lib/components/DataTable/TableHeader.js +23 -28
  115. package/lib/components/DataTable/TableRow.d.ts +32 -0
  116. package/lib/components/DataTable/TableSelectAll.js +1 -1
  117. package/lib/components/DataTable/TableSelectRow.js +1 -3
  118. package/lib/components/DataTable/TableToolbar.d.ts +19 -0
  119. package/lib/components/DataTable/TableToolbar.js +1 -1
  120. package/lib/components/DataTable/TableToolbarAction.d.ts +21 -0
  121. package/lib/components/DataTable/TableToolbarContent.d.ts +19 -0
  122. package/lib/components/DataTable/TableToolbarMenu.d.ts +24 -0
  123. package/lib/components/DataTable/TableToolbarMenu.js +3 -3
  124. package/lib/components/DataTable/TableToolbarSearch.js +1 -0
  125. package/lib/components/DataTable/tools/sorting.js +2 -1
  126. package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +107 -0
  127. package/lib/components/Dropdown/Dropdown.d.ts +6 -0
  128. package/lib/components/Dropdown/Dropdown.js +7 -144
  129. package/lib/components/ExpandableSearch/ExpandableSearch.js +1 -0
  130. package/lib/components/FileUploader/FileUploader.js +1 -1
  131. package/lib/components/FileUploader/FileUploaderButton.js +2 -0
  132. package/lib/components/FileUploader/FileUploaderDropContainer.js +30 -18
  133. package/lib/components/FileUploader/FileUploaderItem.js +2 -1
  134. package/lib/components/FileUploader/Filename.js +8 -2
  135. package/lib/components/FluidTextArea/FluidTextArea.js +12 -1
  136. package/lib/components/IconButton/index.js +1 -0
  137. package/lib/components/InlineCheckbox/InlineCheckbox.js +7 -53
  138. package/lib/components/ListBox/ListBoxSelection.js +4 -23
  139. package/lib/components/ListBox/next/ListBoxSelection.js +2 -23
  140. package/lib/components/Menu/Menu.js +50 -29
  141. package/lib/components/Menu/MenuItem.js +1 -0
  142. package/lib/components/MenuButton/index.js +137 -0
  143. package/lib/components/Modal/Modal.js +4 -3
  144. package/lib/components/MultiSelect/FilterableMultiSelect.js +43 -141
  145. package/lib/components/MultiSelect/MultiSelect.d.ts +1 -1
  146. package/lib/components/MultiSelect/MultiSelect.js +47 -27
  147. package/lib/components/Notification/Notification.js +27 -264
  148. package/lib/components/NumberInput/NumberInput.js +9 -1
  149. package/lib/components/OverflowMenu/OverflowMenu.js +13 -139
  150. package/lib/components/OverflowMenuItem/OverflowMenuItem.d.ts +58 -0
  151. package/lib/components/OverflowMenuItem/OverflowMenuItem.js +12 -7
  152. package/lib/components/OverflowMenuV2/index.js +13 -49
  153. package/lib/components/Popover/index.d.ts +5 -1
  154. package/lib/components/Popover/index.js +37 -9
  155. package/lib/components/RadioButton/RadioButton.Skeleton.d.ts +25 -0
  156. package/lib/components/RadioButton/RadioButton.Skeleton.js +3 -3
  157. package/lib/components/RadioButton/RadioButton.d.ts +64 -0
  158. package/lib/components/RadioButton/RadioButton.js +18 -16
  159. package/lib/components/RadioButtonGroup/RadioButtonGroup.d.ts +80 -0
  160. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +86 -24
  161. package/lib/components/RadioTile/RadioTile.js +6 -6
  162. package/lib/components/Search/Search.Skeleton.d.ts +36 -0
  163. package/lib/components/Search/Search.js +3 -2
  164. package/lib/components/Search/index.js +2 -0
  165. package/lib/components/Select/Select.d.ts +89 -0
  166. package/lib/components/SelectItem/SelectItem.d.ts +62 -0
  167. package/lib/components/SelectItem/SelectItem.js +1 -3
  168. package/lib/components/SelectItemGroup/SelectItemGroup.d.ts +52 -0
  169. package/lib/components/SkeletonText/SkeletonText.js +1 -1
  170. package/lib/components/StructuredList/StructuredList.js +11 -39
  171. package/lib/components/Tabs/Tabs.js +29 -6
  172. package/lib/components/TextArea/TextArea.Skeleton.d.ts +33 -0
  173. package/lib/components/TextArea/TextArea.Skeleton.js +5 -5
  174. package/lib/components/TextArea/TextArea.d.ts +9 -2
  175. package/lib/components/TextArea/TextArea.js +30 -7
  176. package/lib/components/TextArea/index.js +2 -0
  177. package/lib/components/TextInput/TextInput.Skeleton.d.ts +33 -0
  178. package/lib/components/TextInput/index.js +2 -0
  179. package/lib/components/Tile/Tile.js +15 -8
  180. package/lib/components/Toggle/Toggle.js +8 -19
  181. package/lib/components/Tooltip/DefinitionTooltip.d.ts +52 -0
  182. package/lib/components/Tooltip/DefinitionTooltip.js +2 -2
  183. package/lib/components/Tooltip/Tooltip.d.ts +117 -0
  184. package/lib/components/Tooltip/Tooltip.js +6 -4
  185. package/lib/components/Tooltip/index.d.ts +9 -0
  186. package/lib/components/UIShell/HeaderMenu.js +13 -4
  187. package/lib/components/UIShell/HeaderMenuItem.js +17 -4
  188. package/lib/index.d.ts +2 -0
  189. package/lib/index.js +50 -46
  190. package/lib/internal/ClickListener.js +1 -2
  191. package/lib/internal/keyboard/match.js +1 -1
  192. package/lib/internal/useAttachedMenu.js +89 -0
  193. package/lib/internal/useDelayedState.d.ts +19 -0
  194. package/lib/internal/useDelayedState.js +7 -3
  195. package/lib/internal/useId.js +1 -1
  196. package/lib/tools/wrapComponent.js +9 -0
  197. package/package.json +3 -3
@@ -16,7 +16,7 @@ import { MenuContext, menuReducer } from './MenuContext.js';
16
16
  import { match } from '../../internal/keyboard/match.js';
17
17
  import { Escape, ArrowLeft, ArrowUp, ArrowDown } from '../../internal/keyboard/keys.js';
18
18
 
19
- var _excluded = ["children", "className", "label", "onClose", "open", "size", "target", "x", "y"];
19
+ var _excluded = ["children", "className", "label", "onClose", "onOpen", "open", "size", "target", "x", "y"];
20
20
  var spacing = 8; // distance to keep to window edges, in px
21
21
 
22
22
  var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef) {
@@ -26,6 +26,7 @@ var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef
26
26
  className = _ref.className,
27
27
  label = _ref.label,
28
28
  onClose = _ref.onClose,
29
+ onOpen = _ref.onOpen,
29
30
  open = _ref.open,
30
31
  _ref$size = _ref.size,
31
32
  size = _ref$size === void 0 ? 'sm' : _ref$size,
@@ -67,7 +68,7 @@ var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef
67
68
  setPosition = _useState2[1];
68
69
 
69
70
  var focusableItems = childContext.state.items.filter(function (item) {
70
- return !item.disabled;
71
+ return !item.disabled && item.ref.current;
71
72
  });
72
73
 
73
74
  function returnFocus() {
@@ -79,8 +80,15 @@ var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef
79
80
  function handleOpen() {
80
81
  if (menu.current) {
81
82
  focusReturn.current = document.activeElement;
82
- setPosition(calculatePosition());
83
+ var pos = calculatePosition();
84
+ menu.current.style.left = "".concat(pos[0], "px");
85
+ menu.current.style.top = "".concat(pos[1], "px");
86
+ setPosition(pos);
83
87
  menu.current.focus();
88
+
89
+ if (onOpen) {
90
+ onOpen();
91
+ }
84
92
  }
85
93
  }
86
94
 
@@ -103,39 +111,46 @@ var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef
103
111
  }
104
112
 
105
113
  function handleKeyDown(e) {
106
- e.stopPropagation();
107
- var currentItem = focusableItems.findIndex(function (item) {
108
- return item.ref.current.contains(document.activeElement);
109
- });
110
- var indexToFocus = currentItem; // if the user presses escape or this is a submenu
114
+ e.stopPropagation(); // if the user presses escape or this is a submenu
111
115
  // and the user presses ArrowLeft, close it
112
116
 
113
117
  if ((match(e, Escape) || !isRoot && match(e, ArrowLeft)) && onClose) {
114
118
  handleClose(e);
115
119
  } else {
116
- // if currentItem is -1, the menu itself is focused.
117
- // in this case, the arrow keys define the first item
118
- // to be focused.
120
+ focusItem(e);
121
+ }
122
+ }
123
+
124
+ function focusItem(e) {
125
+ var currentItem = focusableItems.findIndex(function (item) {
126
+ return item.ref.current.contains(document.activeElement);
127
+ });
128
+ var indexToFocus = currentItem; // if currentItem is -1, no menu item is focused yet.
129
+ // in this case, the first item should receive focus.
130
+
131
+ if (currentItem === -1) {
132
+ indexToFocus = 0;
133
+ } else if (e) {
119
134
  if (match(e, ArrowUp)) {
120
- indexToFocus = currentItem === -1 ? focusableItems.length - 1 : indexToFocus - 1;
135
+ indexToFocus = indexToFocus - 1;
121
136
  }
122
137
 
123
138
  if (match(e, ArrowDown)) {
124
- indexToFocus = currentItem === -1 ? 0 : indexToFocus + 1;
139
+ indexToFocus = indexToFocus + 1;
125
140
  }
141
+ }
126
142
 
127
- if (indexToFocus < 0) {
128
- indexToFocus = 0;
129
- }
143
+ if (indexToFocus < 0) {
144
+ indexToFocus = focusableItems.length - 1;
145
+ }
130
146
 
131
- if (indexToFocus >= focusableItems.length) {
132
- indexToFocus = focusableItems.length - 1;
133
- }
147
+ if (indexToFocus >= focusableItems.length) {
148
+ indexToFocus = 0;
149
+ }
134
150
 
135
- if (indexToFocus !== currentItem) {
136
- var nodeToFocus = focusableItems[indexToFocus];
137
- nodeToFocus.ref.current.focus();
138
- }
151
+ if (indexToFocus !== currentItem) {
152
+ var nodeToFocus = focusableItems[indexToFocus];
153
+ nodeToFocus.ref.current.focus();
139
154
  }
140
155
  }
141
156
 
@@ -197,6 +212,12 @@ var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef
197
212
  return [-1, -1];
198
213
  }
199
214
 
215
+ useEffect(function () {
216
+ if (open && focusableItems.length > 0) {
217
+ focusItem();
218
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
219
+
220
+ }, [open, focusableItems]);
200
221
  useEffect(function () {
201
222
  if (open) {
202
223
  handleOpen();
@@ -217,12 +238,7 @@ var Menu = /*#__PURE__*/React__default.forwardRef(function Menu(_ref, forwardRef
217
238
  "aria-label": label,
218
239
  tabIndex: -1,
219
240
  onKeyDown: handleKeyDown,
220
- onBlur: handleBlur // eslint-disable-next-line react/forbid-dom-props
221
- ,
222
- style: {
223
- left: "".concat(position[0], "px"),
224
- top: "".concat(position[1], "px")
225
- }
241
+ onBlur: handleBlur
226
242
  }), children));
227
243
  return isRoot ? open && /*#__PURE__*/createPortal(rendered, target) || null : rendered;
228
244
  });
@@ -247,6 +263,11 @@ Menu.propTypes = {
247
263
  */
248
264
  onClose: PropTypes.func,
249
265
 
266
+ /**
267
+ * Provide an optional function to be called when the Menu is opened.
268
+ */
269
+ onOpen: PropTypes.func,
270
+
250
271
  /**
251
272
  * Whether the Menu is open or not.
252
273
  */
@@ -126,6 +126,7 @@ var MenuItem = /*#__PURE__*/React__default.forwardRef(function MenuItem(_ref, fo
126
126
  function handleKeyDown(e) {
127
127
  if (hasChildren && match(e, ArrowRight)) {
128
128
  openSubmenu();
129
+ e.stopPropagation();
129
130
  }
130
131
 
131
132
  if (match(e, Enter) || match(e, Space)) {
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default, { useRef, useState } from 'react';
10
+ import PropTypes from 'prop-types';
11
+ import cx from 'classnames';
12
+ import { ChevronDown } from '@carbon/icons-react';
13
+ import Button from '../Button/Button.js';
14
+ import { Menu } from '../Menu/Menu.js';
15
+ import { useAttachedMenu } from '../../internal/useAttachedMenu.js';
16
+ import { useId } from '../../internal/useId.js';
17
+ import { useMergedRefs } from '../../internal/useMergedRefs.js';
18
+ import { usePrefix } from '../../internal/usePrefix.js';
19
+
20
+ var _excluded = ["children", "className", "disabled", "kind", "label", "size"];
21
+ var spacing = 4; // top and bottom spacing between the button and the menu. in px
22
+
23
+ var validButtonKinds = ['primary', 'tertiary', 'ghost'];
24
+ var defaultButtonKind = 'primary';
25
+ var MenuButton = /*#__PURE__*/React__default.forwardRef(function MenuButton(_ref, forwardRef) {
26
+ var children = _ref.children,
27
+ className = _ref.className,
28
+ disabled = _ref.disabled,
29
+ _ref$kind = _ref.kind,
30
+ kind = _ref$kind === void 0 ? defaultButtonKind : _ref$kind,
31
+ label = _ref.label,
32
+ _ref$size = _ref.size,
33
+ size = _ref$size === void 0 ? 'lg' : _ref$size,
34
+ rest = _objectWithoutProperties(_ref, _excluded);
35
+
36
+ var id = useId('MenuButton');
37
+ var prefix = usePrefix();
38
+ var triggerRef = useRef(null);
39
+ var menuRef = useRef(null);
40
+ var ref = useMergedRefs([forwardRef, triggerRef]);
41
+
42
+ var _useState = useState(0),
43
+ _useState2 = _slicedToArray(_useState, 2),
44
+ width = _useState2[0],
45
+ setWidth = _useState2[1];
46
+
47
+ var _useAttachedMenu = useAttachedMenu(triggerRef),
48
+ open = _useAttachedMenu.open,
49
+ x = _useAttachedMenu.x,
50
+ y = _useAttachedMenu.y,
51
+ hookOnClick = _useAttachedMenu.handleClick,
52
+ handleMousedown = _useAttachedMenu.handleMousedown,
53
+ handleClose = _useAttachedMenu.handleClose;
54
+
55
+ function handleClick() {
56
+ if (triggerRef.current) {
57
+ var _triggerRef$current$g = triggerRef.current.getBoundingClientRect(),
58
+ w = _triggerRef$current$g.width;
59
+
60
+ setWidth(w);
61
+ hookOnClick();
62
+ }
63
+ }
64
+
65
+ function handleOpen() {
66
+ menuRef.current.style.width = "".concat(width, "px");
67
+ }
68
+
69
+ var triggerClasses = cx("".concat(prefix, "--menu-button__trigger"), _defineProperty({}, "".concat(prefix, "--menu-button__trigger--open"), open), className);
70
+ var buttonKind = validButtonKinds.includes(kind) ? kind : defaultButtonKind;
71
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Button, _extends({}, rest, {
72
+ ref: ref,
73
+ className: triggerClasses,
74
+ size: size,
75
+ kind: buttonKind,
76
+ renderIcon: ChevronDown,
77
+ disabled: disabled,
78
+ "aria-haspopup": true,
79
+ "aria-expanded": open,
80
+ onClick: handleClick,
81
+ onMouseDown: handleMousedown,
82
+ "aria-owns": open ? id : null
83
+ }), label), /*#__PURE__*/React__default.createElement(Menu, {
84
+ ref: menuRef,
85
+ id: id,
86
+ label: label,
87
+ size: size,
88
+ open: open,
89
+ onClose: handleClose,
90
+ onOpen: handleOpen,
91
+ x: x,
92
+ y: [y[0] - spacing, y[1] + spacing]
93
+ }, children));
94
+ });
95
+ MenuButton.propTypes = {
96
+ /**
97
+ * A collection of MenuItems to be rendered as actions for this MenuButton.
98
+ */
99
+ children: PropTypes.node.isRequired,
100
+
101
+ /**
102
+ * Additional CSS class names.
103
+ */
104
+ className: PropTypes.string,
105
+
106
+ /**
107
+ * Specify whether the MenuButton should be disabled, or not.
108
+ */
109
+ disabled: PropTypes.bool,
110
+
111
+ /**
112
+ * Specify the type of button to be used as the base for the trigger button.
113
+ */
114
+ kind: PropTypes.oneOf(validButtonKinds),
115
+
116
+ /**
117
+ * Provide the label to be renderd on the trigger button.
118
+ */
119
+ label: PropTypes.string.isRequired,
120
+
121
+ /**
122
+ * Specify the size of the button and menu.
123
+ */
124
+ size: PropTypes.oneOf(['sm', 'md', 'lg'])
125
+ };
126
+
127
+ export { MenuButton };
@@ -20,12 +20,13 @@ import { usePrefix } from '../../internal/usePrefix.js';
20
20
 
21
21
  var _Modal$propTypes;
22
22
 
23
- var _excluded = ["children", "className", "modalHeading", "modalLabel", "modalAriaLabel", "passiveModal", "secondaryButtonText", "primaryButtonText", "open", "onRequestClose", "onRequestSubmit", "onSecondarySubmit", "primaryButtonDisabled", "danger", "alert", "secondaryButtons", "selectorPrimaryFocus", "selectorsFloatingMenus", "shouldSubmitOnEnter", "size", "hasScrollingContent", "closeButtonLabel", "preventCloseOnClickOutside", "isFullWidth"];
23
+ var _excluded = ["aria-label", "children", "className", "modalHeading", "modalLabel", "modalAriaLabel", "passiveModal", "secondaryButtonText", "primaryButtonText", "open", "onRequestClose", "onRequestSubmit", "onSecondarySubmit", "primaryButtonDisabled", "danger", "alert", "secondaryButtons", "selectorPrimaryFocus", "selectorsFloatingMenus", "shouldSubmitOnEnter", "size", "hasScrollingContent", "closeButtonLabel", "preventCloseOnClickOutside", "isFullWidth"];
24
24
  var getInstanceId = setupGetInstanceId();
25
25
  var Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
26
26
  var _classNames, _classNames2;
27
27
 
28
- var children = _ref.children,
28
+ var ariaLabelProp = _ref['aria-label'],
29
+ children = _ref.children,
29
30
  className = _ref.className,
30
31
  modalHeading = _ref.modalHeading,
31
32
  modalLabel = _ref.modalLabel,
@@ -122,7 +123,7 @@ var Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
122
123
  tabIndex: "-1",
123
124
  className: "".concat(modalCloseButtonClass, "__icon")
124
125
  }));
125
- var ariaLabel = modalLabel || rest['aria-label'] || modalAriaLabel || modalHeading;
126
+ var ariaLabel = modalLabel || ariaLabelProp || modalAriaLabel || modalHeading;
126
127
  var getAriaLabelledBy = modalLabel ? modalLabelId : modalHeadingId;
127
128
  var hasScrollingContentProps = hasScrollingContent ? {
128
129
  tabIndex: 0,
@@ -5,13 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
8
+ import { slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends, objectSpread2 as _objectSpread2$1 } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
10
10
  import cx from 'classnames';
11
11
  import Downshift from 'downshift';
12
12
  import isEqual from 'lodash.isequal';
13
13
  import PropTypes from 'prop-types';
14
- import React__default, { useContext, useState, useRef } from 'react';
14
+ import React__default, { useContext, useState, useRef, useEffect } from 'react';
15
15
  import { defaultFilterItems } from '../ComboBox/tools/filter.js';
16
16
  import { sortingPropTypes } from './MultiSelectPropTypes.js';
17
17
  import ListBox from '../ListBox/index.js';
@@ -29,12 +29,14 @@ import { match } from '../../internal/keyboard/match.js';
29
29
  import ListBoxSelection from '../ListBox/next/ListBoxSelection.js';
30
30
  import ListBoxTrigger from '../ListBox/next/ListBoxTrigger.js';
31
31
  import { ListBoxSize } from '../ListBox/ListBoxPropTypes.js';
32
- import { Space, Tab } from '../../internal/keyboard/keys.js';
32
+ import { Space, Enter, Delete, Escape, Tab } from '../../internal/keyboard/keys.js';
33
33
 
34
+ var _objectSpread2, _FilterableMultiSelec;
34
35
  var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function FilterableMultiSelect(_ref, ref) {
35
36
  var _cx, _cx2, _cx3, _cx4;
36
37
 
37
- var ariaLabel = _ref.ariaLabel,
38
+ var ariaLabel = _ref['aria-label'],
39
+ deprecatedAriaLabel = _ref.ariaLabel,
38
40
  containerClassName = _ref.className,
39
41
  compareItems = _ref.compareItems,
40
42
  direction = _ref.direction,
@@ -90,7 +92,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
90
92
  inputValue = _useState8[0],
91
93
  setInputValue = _useState8[1];
92
94
 
93
- var _useState9 = useState([]),
95
+ var _useState9 = useState(initialSelectedItems !== null && initialSelectedItems !== void 0 ? initialSelectedItems : []),
94
96
  _useState10 = _slicedToArray(_useState9, 2),
95
97
  topItems = _useState10[0],
96
98
  setTopItems = _useState10[1];
@@ -105,6 +107,11 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
105
107
  highlightedIndex = _useState14[0],
106
108
  setHighlightedIndex = _useState14[1];
107
109
 
110
+ var _useState15 = useState(initialSelectedItems !== null && initialSelectedItems !== void 0 ? initialSelectedItems : []),
111
+ _useState16 = _slicedToArray(_useState15, 2),
112
+ currentSelectedItems = _useState16[0],
113
+ setCurrentSelectedItems = _useState16[1];
114
+
108
115
  var textInput = useRef();
109
116
  var filterableMultiSelectInstanceId = useId();
110
117
  var enabled = useFeatureFlag('enable-v11-release');
@@ -117,7 +124,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
117
124
 
118
125
  var inline = type === 'inline';
119
126
  var showWarning = !invalid && warn;
120
- var wrapperClasses = cx("".concat(prefix, "--multi-select__wrapper"), "".concat(prefix, "--list-box__wrapper"), [enabled ? containerClassName : null], (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--multi-select__wrapper--inline"), inline), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--inline"), inline), _defineProperty(_cx, "".concat(prefix, "--multi-select__wrapper--inline--invalid"), inline && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--inline--invalid"), inline && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box--up"), direction === 'top'), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--fluid--invalid"), isFluid && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--fluid--focus"), isFluid && isFocused), _cx));
127
+ var wrapperClasses = cx("".concat(prefix, "--multi-select__wrapper"), "".concat(prefix, "--multi-select--filterable__wrapper"), "".concat(prefix, "--list-box__wrapper"), [enabled ? containerClassName : null], (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--multi-select__wrapper--inline"), inline), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--inline"), inline), _defineProperty(_cx, "".concat(prefix, "--multi-select__wrapper--inline--invalid"), inline && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--inline--invalid"), inline && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box--up"), direction === 'top'), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--fluid--invalid"), isFluid && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--fluid--focus"), isFluid && isFocused), _cx));
121
128
  var helperId = !helperText ? undefined : "filterablemultiselect-helper-text-".concat(filterableMultiSelectInstanceId);
122
129
  var labelId = "".concat(id, "-label");
123
130
  var titleClasses = cx((_cx2 = {}, _defineProperty(_cx2, "".concat(prefix, "--label"), true), _defineProperty(_cx2, "".concat(prefix, "--label--disabled"), disabled), _defineProperty(_cx2, "".concat(prefix, "--visually-hidden"), hideLabel), _cx2));
@@ -129,8 +136,15 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
129
136
  }, helperText) : null;
130
137
  var menuId = "".concat(id, "__menu");
131
138
  var inputId = "".concat(id, "-input");
139
+ useEffect(function () {
140
+ if (!isOpen) {
141
+ setTopItems(currentSelectedItems);
142
+ }
143
+ }, [currentSelectedItems, isOpen, setTopItems]);
132
144
 
133
145
  function handleOnChange(changes) {
146
+ setCurrentSelectedItems(changes.selectedItems);
147
+
134
148
  if (onChange) {
135
149
  onChange(changes);
136
150
  }
@@ -149,11 +163,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
149
163
  handleOnMenuChange(false);
150
164
  }
151
165
 
152
- function handleOnStateChange(changes, downshift) {
153
- if (changes.isOpen && !isOpen) {
154
- setTopItems(downshift.selectedItem);
155
- }
156
-
166
+ function handleOnStateChange(changes) {
157
167
  var type = changes.type;
158
168
  var stateChangeTypes = Downshift.stateChangeTypes;
159
169
 
@@ -246,7 +256,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
246
256
  isOpen = _ref4.isOpen,
247
257
  inputValue = _ref4.inputValue,
248
258
  selectedItem = _ref4.selectedItem;
249
- var className = cx("".concat(prefix, "--multi-select"), "".concat(prefix, "--combo-box"), "".concat(prefix, "--multi-select--filterable"), [enabled ? null : containerClassName], (_cx5 = {}, _defineProperty(_cx5, "".concat(prefix, "--multi-select--invalid"), invalid), _defineProperty(_cx5, "".concat(prefix, "--multi-select--open"), isOpen), _defineProperty(_cx5, "".concat(prefix, "--multi-select--inline"), inline), _defineProperty(_cx5, "".concat(prefix, "--multi-select--selected"), selectedItem.length > 0), _defineProperty(_cx5, "".concat(prefix, "--multi-select--filterable--input-focused"), inputFocused), _cx5));
259
+ var className = cx("".concat(prefix, "--multi-select"), "".concat(prefix, "--combo-box"), "".concat(prefix, "--multi-select--filterable"), [enabled ? null : containerClassName], (_cx5 = {}, _defineProperty(_cx5, "".concat(prefix, "--multi-select--invalid"), invalid), _defineProperty(_cx5, "".concat(prefix, "--multi-select--invalid--focused"), invalid && inputFocused), _defineProperty(_cx5, "".concat(prefix, "--multi-select--open"), isOpen), _defineProperty(_cx5, "".concat(prefix, "--multi-select--inline"), inline), _defineProperty(_cx5, "".concat(prefix, "--multi-select--selected"), selectedItem.length > 0), _defineProperty(_cx5, "".concat(prefix, "--multi-select--filterable--input-focused"), inputFocused), _cx5));
250
260
  var rootProps = getRootProps({}, {
251
261
  suppressRefError: true
252
262
  });
@@ -291,6 +301,26 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
291
301
  event.stopPropagation();
292
302
  }
293
303
 
304
+ if (match(event, Enter)) {
305
+ handleOnMenuChange(true);
306
+ }
307
+
308
+ if (!disabled) {
309
+ if (match(event, Delete) || match(event, Escape)) {
310
+ if (isOpen) {
311
+ handleOnMenuChange(true);
312
+ clearInputValue();
313
+ event.stopPropagation();
314
+ } else if (!isOpen) {
315
+ clearInputValue();
316
+
317
+ _clearSelection();
318
+
319
+ event.stopPropagation();
320
+ }
321
+ }
322
+ }
323
+
294
324
  if (match(event, Tab)) {
295
325
  handleOnMenuChange(false);
296
326
  }
@@ -300,6 +330,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
300
330
  },
301
331
  onBlur: function onBlur() {
302
332
  setInputFocused(false);
333
+ setInputValue('');
303
334
  }
304
335
  });
305
336
  var menuProps = getMenuProps({
@@ -321,6 +352,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
321
352
  }, titleText ? /*#__PURE__*/React__default.createElement("label", _extends({
322
353
  className: titleClasses
323
354
  }, labelProps), titleText) : null, /*#__PURE__*/React__default.createElement(ListBox, {
355
+ "aria-label": deprecatedAriaLabel || ariaLabel,
324
356
  onFocus: isFluid ? handleFocus : null,
325
357
  onBlur: isFluid ? handleFocus : null,
326
358
  className: className,
@@ -411,125 +443,7 @@ var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Filt
411
443
  }
412
444
  });
413
445
  });
414
- FilterableMultiSelect.propTypes = _objectSpread2(_objectSpread2({
415
- /**
416
- * 'aria-label' of the ListBox component.
417
- */
418
- ariaLabel: PropTypes.string,
419
-
420
- /**
421
- * Specify the direction of the multiselect dropdown. Can be either top or bottom.
422
- */
423
- direction: PropTypes.oneOf(['top', 'bottom']),
424
-
425
- /**
426
- * Disable the control
427
- */
428
- disabled: PropTypes.bool,
429
-
430
- /**
431
- * Additional props passed to Downshift
432
- */
433
- downshiftProps: PropTypes.shape(Downshift.propTypes),
434
-
435
- /**
436
- * Specify whether the title text should be hidden or not
437
- */
438
- hideLabel: PropTypes.bool,
439
-
440
- /**
441
- * Specify a custom `id`
442
- */
443
- id: PropTypes.string.isRequired,
444
-
445
- /**
446
- * Allow users to pass in arbitrary items from their collection that are
447
- * pre-selected
448
- */
449
- initialSelectedItems: PropTypes.array,
450
-
451
- /**
452
- * Is the current selection invalid?
453
- */
454
- invalid: PropTypes.bool,
455
-
456
- /**
457
- * If invalid, what is the error?
458
- */
459
- invalidText: PropTypes.node,
460
-
461
- /**
462
- * Function to render items as custom components instead of strings.
463
- * Defaults to null and is overridden by a getter
464
- */
465
- itemToElement: PropTypes.func,
466
-
467
- /**
468
- * Helper function passed to downshift that allows the library to render a
469
- * given item to a string label. By default, it extracts the `label` field
470
- * from a given item to serve as the item label in the list.
471
- */
472
- itemToString: PropTypes.func,
473
-
474
- /**
475
- * We try to stay as generic as possible here to allow individuals to pass
476
- * in a collection of whatever kind of data structure they prefer
477
- */
478
- items: PropTypes.array.isRequired,
479
-
480
- /**
481
- * `true` to use the light version.
482
- */
483
- light: deprecate(PropTypes.bool, 'The `light` prop for `FilterableMultiSelect` has ' + 'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.'),
484
-
485
- /**
486
- * Specify the locale of the control. Used for the default `compareItems`
487
- * used for sorting the list of items in the control.
488
- */
489
- locale: PropTypes.string,
490
-
491
- /**
492
- * `onChange` is a utility for this controlled component to communicate to a
493
- * consuming component what kind of internal state changes are occurring.
494
- */
495
- onChange: PropTypes.func,
496
-
497
- /**
498
- * `onInputValueChange` is a utility for this controlled component to communicate to
499
- * the currently typed input.
500
- */
501
- onInputValueChange: PropTypes.func,
502
-
503
- /**
504
- * `onMenuChange` is a utility for this controlled component to communicate to a
505
- * consuming component that the menu was opened(`true`)/closed(`false`).
506
- */
507
- onMenuChange: PropTypes.func,
508
-
509
- /**
510
- * Initialize the component with an open(`true`)/closed(`false`) menu.
511
- */
512
- open: PropTypes.bool,
513
-
514
- /**
515
- * Generic `placeholder` that will be used as the textual representation of
516
- * what this field is for
517
- */
518
- placeholder: PropTypes.string,
519
-
520
- /**
521
- * Specify feedback (mode) of the selection.
522
- * `top`: selected item jumps to top
523
- * `fixed`: selected item stays at it's position
524
- * `top-after-reopen`: selected item jump to top after reopen dropdown
525
- */
526
- selectionFeedback: PropTypes.oneOf(['top', 'fixed', 'top-after-reopen']),
527
-
528
- /**
529
- * Specify the size of the ListBox. Currently supports either `sm`, `md` or `lg` as an option.
530
- */
531
- size: ListBoxSize
532
- }, sortingPropTypes), {}, {
446
+ FilterableMultiSelect.propTypes = _objectSpread2$1(_objectSpread2$1((_objectSpread2 = {}, _defineProperty(_objectSpread2, 'aria-label', PropTypes.string), _defineProperty(_objectSpread2, "ariaLabel", deprecate(PropTypes.string, 'This prop syntax has been deprecated. Please use the new `aria-label`.')), _defineProperty(_objectSpread2, "direction", PropTypes.oneOf(['top', 'bottom'])), _defineProperty(_objectSpread2, "disabled", PropTypes.bool), _defineProperty(_objectSpread2, "downshiftProps", PropTypes.shape(Downshift.propTypes)), _defineProperty(_objectSpread2, "hideLabel", PropTypes.bool), _defineProperty(_objectSpread2, "id", PropTypes.string.isRequired), _defineProperty(_objectSpread2, "initialSelectedItems", PropTypes.array), _defineProperty(_objectSpread2, "invalid", PropTypes.bool), _defineProperty(_objectSpread2, "invalidText", PropTypes.node), _defineProperty(_objectSpread2, "itemToElement", PropTypes.func), _defineProperty(_objectSpread2, "itemToString", PropTypes.func), _defineProperty(_objectSpread2, "items", PropTypes.array.isRequired), _defineProperty(_objectSpread2, "light", deprecate(PropTypes.bool, 'The `light` prop for `FilterableMultiSelect` has ' + 'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.')), _defineProperty(_objectSpread2, "locale", PropTypes.string), _defineProperty(_objectSpread2, "onChange", PropTypes.func), _defineProperty(_objectSpread2, "onInputValueChange", PropTypes.func), _defineProperty(_objectSpread2, "onMenuChange", PropTypes.func), _defineProperty(_objectSpread2, "open", PropTypes.bool), _defineProperty(_objectSpread2, "placeholder", PropTypes.string), _defineProperty(_objectSpread2, "selectionFeedback", PropTypes.oneOf(['top', 'fixed', 'top-after-reopen'])), _defineProperty(_objectSpread2, "size", ListBoxSize), _objectSpread2), sortingPropTypes), {}, {
533
447
  /**
534
448
  * Callback function for translating ListBoxMenuIcon SVG title
535
449
  */
@@ -550,19 +464,7 @@ FilterableMultiSelect.propTypes = _objectSpread2(_objectSpread2({
550
464
  */
551
465
  warnText: PropTypes.node
552
466
  });
553
- FilterableMultiSelect.defaultProps = {
554
- ariaLabel: 'Choose an item',
555
- compareItems: defaultCompareItems,
556
- direction: 'bottom',
557
- disabled: false,
558
- filterItems: defaultFilterItems,
559
- initialSelectedItems: [],
560
- itemToString: defaultItemToString,
561
- locale: 'en',
562
- sortItems: defaultSortItems,
563
- open: false,
564
- selectionFeedback: 'top-after-reopen'
565
- };
467
+ FilterableMultiSelect.defaultProps = (_FilterableMultiSelec = {}, _defineProperty(_FilterableMultiSelec, 'aria-label', 'Choose an item'), _defineProperty(_FilterableMultiSelec, "compareItems", defaultCompareItems), _defineProperty(_FilterableMultiSelec, "direction", 'bottom'), _defineProperty(_FilterableMultiSelec, "disabled", false), _defineProperty(_FilterableMultiSelec, "filterItems", defaultFilterItems), _defineProperty(_FilterableMultiSelec, "initialSelectedItems", []), _defineProperty(_FilterableMultiSelec, "itemToString", defaultItemToString), _defineProperty(_FilterableMultiSelec, "locale", 'en'), _defineProperty(_FilterableMultiSelec, "sortItems", defaultSortItems), _defineProperty(_FilterableMultiSelec, "open", false), _defineProperty(_FilterableMultiSelec, "selectionFeedback", 'top-after-reopen'), _FilterableMultiSelec);
566
468
  var FilterableMultiSelect$1 = FilterableMultiSelect;
567
469
 
568
470
  export { FilterableMultiSelect$1 as default };
@@ -114,7 +114,7 @@ export interface MultiSelectProps<ItemType> extends MultiSelectSortingProps<Item
114
114
  onChange?(data: OnChangeData<ItemType>): void;
115
115
  /**
116
116
  * `onMenuChange` is a utility for this controlled component to communicate to a
117
- * consuming component that the menu was opend(`true`)/closed(`false`).
117
+ * consuming component that the menu was open(`true`)/closed(`false`).
118
118
  */
119
119
  onMenuChange?(open: boolean): void;
120
120
  /**