@carbon/react 1.32.0 → 1.33.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 (74) hide show
  1. package/README.md +22 -7
  2. package/es/components/ComboBox/ComboBox.js +43 -10
  3. package/es/components/ContentSwitcher/ContentSwitcher.js +5 -5
  4. package/es/components/DataTable/DataTable.js +110 -130
  5. package/es/components/DataTable/Table.js +1 -1
  6. package/es/components/DatePicker/DatePicker.d.ts +14 -13
  7. package/es/components/DatePicker/DatePicker.js +3 -0
  8. package/es/components/DatePickerInput/DatePickerInput.d.ts +2 -2
  9. package/es/components/Dropdown/Dropdown.js +31 -6
  10. package/es/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
  11. package/es/components/FileUploader/FileUploader.d.ts +175 -0
  12. package/es/components/FileUploader/FileUploader.js +3 -3
  13. package/es/components/FileUploader/FileUploaderButton.d.ts +140 -0
  14. package/es/components/FileUploader/FileUploaderButton.js +11 -7
  15. package/es/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
  16. package/es/components/FileUploader/FileUploaderDropContainer.js +3 -3
  17. package/es/components/FileUploader/FileUploaderItem.d.ts +110 -0
  18. package/es/components/FileUploader/Filename.d.ts +71 -0
  19. package/es/components/FileUploader/Filename.js +6 -4
  20. package/es/components/InlineCheckbox/InlineCheckbox.js +3 -1
  21. package/es/components/Loading/Loading.d.ts +65 -0
  22. package/es/components/Notification/Notification.d.ts +4 -4
  23. package/es/components/Notification/Notification.js +3 -3
  24. package/es/components/OverflowMenu/OverflowMenu.js +36 -41
  25. package/es/components/Slider/Slider.js +59 -68
  26. package/es/components/Toggle/Toggle.d.ts +129 -0
  27. package/es/components/Toggle/Toggle.js +2 -2
  28. package/es/components/Toggle/index.d.ts +11 -0
  29. package/es/components/UIShell/HeaderMenu.js +29 -36
  30. package/es/components/UIShell/HeaderName.d.ts +39 -0
  31. package/es/components/UIShell/HeaderName.js +2 -7
  32. package/es/components/UIShell/HeaderPanel.js +1 -1
  33. package/es/components/UIShell/Link.js +2 -1
  34. package/es/index.js +1 -1
  35. package/es/internal/FloatingMenu.js +47 -51
  36. package/es/internal/useControllableState.js +1 -1
  37. package/es/internal/useId.js +10 -1
  38. package/lib/components/ComboBox/ComboBox.js +43 -10
  39. package/lib/components/ContentSwitcher/ContentSwitcher.js +5 -5
  40. package/lib/components/DataTable/DataTable.js +110 -130
  41. package/lib/components/DataTable/Table.js +1 -1
  42. package/lib/components/DatePicker/DatePicker.d.ts +14 -13
  43. package/lib/components/DatePicker/DatePicker.js +3 -0
  44. package/lib/components/DatePickerInput/DatePickerInput.d.ts +2 -2
  45. package/lib/components/Dropdown/Dropdown.js +30 -5
  46. package/lib/components/FileUploader/FileUploader.Skeleton.d.ts +29 -0
  47. package/lib/components/FileUploader/FileUploader.d.ts +175 -0
  48. package/lib/components/FileUploader/FileUploader.js +3 -3
  49. package/lib/components/FileUploader/FileUploaderButton.d.ts +140 -0
  50. package/lib/components/FileUploader/FileUploaderButton.js +11 -7
  51. package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +139 -0
  52. package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -3
  53. package/lib/components/FileUploader/FileUploaderItem.d.ts +110 -0
  54. package/lib/components/FileUploader/Filename.d.ts +71 -0
  55. package/lib/components/FileUploader/Filename.js +6 -4
  56. package/lib/components/InlineCheckbox/InlineCheckbox.js +3 -1
  57. package/lib/components/Loading/Loading.d.ts +65 -0
  58. package/lib/components/Notification/Notification.d.ts +4 -4
  59. package/lib/components/Notification/Notification.js +3 -3
  60. package/lib/components/OverflowMenu/OverflowMenu.js +36 -41
  61. package/lib/components/Slider/Slider.js +59 -68
  62. package/lib/components/Toggle/Toggle.d.ts +129 -0
  63. package/lib/components/Toggle/Toggle.js +2 -2
  64. package/lib/components/Toggle/index.d.ts +11 -0
  65. package/lib/components/UIShell/HeaderMenu.js +29 -36
  66. package/lib/components/UIShell/HeaderName.d.ts +39 -0
  67. package/lib/components/UIShell/HeaderName.js +2 -7
  68. package/lib/components/UIShell/HeaderPanel.js +1 -1
  69. package/lib/components/UIShell/Link.js +2 -1
  70. package/lib/index.js +2 -2
  71. package/lib/internal/FloatingMenu.js +47 -51
  72. package/lib/internal/useControllableState.js +1 -1
  73. package/lib/internal/useId.js +9 -0
  74. package/package.json +22 -19
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Copyright IBM Corp. 2021, 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
+ import React, { KeyboardEventHandler, MouseEventHandler } from 'react';
8
+ import PropTypes from 'prop-types';
9
+ type ExcludedAttributes = 'aria-labelledby' | 'aria-checked' | 'type' | 'role' | 'id' | 'size' | 'onClick';
10
+ export interface ToggleProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, ExcludedAttributes> {
11
+ /**
12
+ * Specify another element's id to be used as the label for this toggle
13
+ */
14
+ 'aria-labelledby'?: string;
15
+ /**
16
+ * Provide an id that unique represents the underlying `<button>`
17
+ */
18
+ id: string;
19
+ /**
20
+ * Specify the label for the "off" position
21
+ */
22
+ labelA?: string | undefined;
23
+ /**
24
+ * Specify the label for the "on" position
25
+ */
26
+ labelB?: string | undefined;
27
+ /**
28
+ * Provide the text that will be read by a screen reader when visiting this
29
+ * control. This should be provided unless 'aria-labelledby' is set instead
30
+ * or you use an external <label> element with its "for" attribute set to the
31
+ * toggle's id.
32
+ */
33
+ labelText?: string | undefined;
34
+ /**
35
+ * If true, the side labels (props.labelA and props.labelB) will be replaced by
36
+ * props.labelText (if passed), so that the toggle doesn't render a top label.
37
+ */
38
+ hideLabel?: boolean;
39
+ /**
40
+ * Provide an event listener that is called when the control is toggled
41
+ */
42
+ onClick: MouseEventHandler<HTMLDivElement> | KeyboardEventHandler<HTMLDivElement> | undefined;
43
+ /**
44
+ * Provide an event listener that is called when the control is toggled
45
+ */
46
+ onToggle?(checked: boolean): void;
47
+ /**
48
+ * Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
49
+ */
50
+ size?: 'sm' | 'md' | undefined;
51
+ /**
52
+ * Whether the toggle should be read-only
53
+ */
54
+ readOnly?: boolean | undefined;
55
+ /**
56
+ * Specify whether the toggle should be on by default
57
+ */
58
+ defaultToggled?: boolean | undefined;
59
+ /**
60
+ * Specify whether the control is toggled
61
+ */
62
+ toggled?: boolean | undefined;
63
+ }
64
+ export declare function Toggle({ 'aria-labelledby': ariaLabelledby, className, defaultToggled, disabled, hideLabel, id, labelA, labelB, labelText, onClick, onToggle, readOnly, size, toggled, ...other }: ToggleProps): JSX.Element;
65
+ export declare namespace Toggle {
66
+ var propTypes: {
67
+ /**
68
+ * Specify another element's id to be used as the label for this toggle
69
+ */
70
+ 'aria-labelledby': PropTypes.Requireable<string>;
71
+ /**
72
+ * Specify a custom className to apply to the form-item node
73
+ */
74
+ className: PropTypes.Requireable<string>;
75
+ /**
76
+ * Specify whether the toggle should be on by default
77
+ */
78
+ defaultToggled: PropTypes.Requireable<boolean>;
79
+ /**
80
+ * Whether this control should be disabled
81
+ */
82
+ disabled: PropTypes.Requireable<boolean>;
83
+ /**
84
+ * If true, the side labels (props.labelA and props.labelB) will be replaced by
85
+ * props.labelText (if passed), so that the toggle doesn't render a top label.
86
+ */
87
+ hideLabel: PropTypes.Requireable<boolean>;
88
+ /**
89
+ * Provide an id that unique represents the underlying `<button>`
90
+ */
91
+ id: PropTypes.Validator<string>;
92
+ /**
93
+ * Specify the label for the "off" position
94
+ */
95
+ labelA: PropTypes.Requireable<PropTypes.ReactNodeLike>;
96
+ /**
97
+ * Specify the label for the "on" position
98
+ */
99
+ labelB: PropTypes.Requireable<PropTypes.ReactNodeLike>;
100
+ /**
101
+ * Provide the text that will be read by a screen reader when visiting this
102
+ * control. This should be provided unless 'aria-labelledby' is set instead
103
+ * or you use an external <label> element with its "for" attribute set to the
104
+ * toggle's id.
105
+ */
106
+ labelText: PropTypes.Requireable<string>;
107
+ /**
108
+ * Provide an event listener that is called when the control is clicked
109
+ */
110
+ onClick: PropTypes.Requireable<(...args: any[]) => any>;
111
+ /**
112
+ * Provide an event listener that is called when the control is toggled
113
+ */
114
+ onToggle: PropTypes.Requireable<(...args: any[]) => any>;
115
+ /**
116
+ * Whether the toggle should be read-only
117
+ */
118
+ readOnly: PropTypes.Requireable<boolean>;
119
+ /**
120
+ * Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
121
+ */
122
+ size: PropTypes.Requireable<string>;
123
+ /**
124
+ * Specify whether the control is toggled
125
+ */
126
+ toggled: PropTypes.Requireable<boolean>;
127
+ };
128
+ }
129
+ export default Toggle;
@@ -78,7 +78,7 @@ function Toggle(_ref) {
78
78
  handleClick(e);
79
79
  buttonElement.current.focus();
80
80
  }
81
- } : null
81
+ } : undefined
82
82
  }, /*#__PURE__*/React__default.createElement("button", _extends({}, other, {
83
83
  ref: buttonElement,
84
84
  id: id,
@@ -90,7 +90,7 @@ function Toggle(_ref) {
90
90
  disabled: disabled,
91
91
  onClick: handleClick
92
92
  })), /*#__PURE__*/React__default.createElement(LabelComponent, {
93
- htmlFor: ariaLabelledby ? null : id,
93
+ htmlFor: ariaLabelledby ? undefined : id,
94
94
  className: `${prefix}--toggle__label`
95
95
  }, labelText && /*#__PURE__*/React__default.createElement("span", {
96
96
  className: labelTextClasses
@@ -0,0 +1,11 @@
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
+ import { default as Toggle, ToggleProps } from './Toggle';
8
+ export * from './Toggle.Skeleton';
9
+ export default Toggle;
10
+ export { Toggle };
11
+ export type { ToggleProps };
@@ -26,6 +26,9 @@ class HeaderMenu extends React__default.Component {
26
26
  constructor(props) {
27
27
  super(props);
28
28
  _defineProperty(this, "_subMenus", /*#__PURE__*/React__default.createRef());
29
+ /**
30
+ * Toggle the expanded state of the menu on click.
31
+ */
29
32
  _defineProperty(this, "handleOnClick", e => {
30
33
  const {
31
34
  current: subMenusNode
@@ -37,6 +40,9 @@ class HeaderMenu extends React__default.Component {
37
40
  expanded: !prevState.expanded
38
41
  }));
39
42
  });
43
+ /**
44
+ * Keyboard event handler for the entire menu.
45
+ */
40
46
  _defineProperty(this, "handleOnKeyDown", event => {
41
47
  // Handle enter or space key for toggling the expanded state of the menu.
42
48
  if (matches(event, [Enter, Space])) {
@@ -48,6 +54,11 @@ class HeaderMenu extends React__default.Component {
48
54
  return;
49
55
  }
50
56
  });
57
+ /**
58
+ * Handle our blur event from our underlying menuitems. Will mostly be used
59
+ * for toggling the expansion status of our menu in response to a user
60
+ * clicking off of the menu or menubar.
61
+ */
51
62
  _defineProperty(this, "handleOnBlur", event => {
52
63
  // Rough guess for a blur event that is triggered outside of our menu or
53
64
  // menubar context
@@ -60,12 +71,24 @@ class HeaderMenu extends React__default.Component {
60
71
  selectedIndex: null
61
72
  });
62
73
  });
74
+ /**
75
+ * ref handler for our menu button. If we are supplied a `focusRef` prop, we also
76
+ * forward along the node.
77
+ *
78
+ * This is useful when this component is a child in a
79
+ * menu or menubar as it will allow the parent to explicitly focus the menu
80
+ * button node when that child should receive focus.
81
+ */
63
82
  _defineProperty(this, "handleMenuButtonRef", node => {
64
83
  if (this.props.focusRef) {
65
84
  this.props.focusRef(node);
66
85
  }
67
86
  this.menuButtonRef = node;
68
87
  });
88
+ /**
89
+ * Handles individual menuitem refs. We assign them to a class instance
90
+ * property so that we can properly manage focus of our children.
91
+ */
69
92
  _defineProperty(this, "handleItemRef", index => node => {
70
93
  this.items[index] = node;
71
94
  });
@@ -84,6 +107,12 @@ class HeaderMenu extends React__default.Component {
84
107
  return;
85
108
  }
86
109
  });
110
+ /**
111
+ * We capture the `ref` for each child inside of `this.items` to properly
112
+ * manage focus. In addition to this focus management, all items receive a
113
+ * `tabIndex: -1` so the user won't hit a large number of items in their tab
114
+ * sequence when they might not want to go through all the items.
115
+ */
87
116
  _defineProperty(this, "_renderMenuItem", (item, index) => {
88
117
  if ( /*#__PURE__*/React__default.isValidElement(item)) {
89
118
  return /*#__PURE__*/React__default.cloneElement(item, {
@@ -100,35 +129,6 @@ class HeaderMenu extends React__default.Component {
100
129
  };
101
130
  this.items = [];
102
131
  }
103
-
104
- /**
105
- * Toggle the expanded state of the menu on click.
106
- */
107
-
108
- /**
109
- * Keyboard event handler for the entire menu.
110
- */
111
-
112
- /**
113
- * Handle our blur event from our underlying menuitems. Will mostly be used
114
- * for toggling the expansion status of our menu in response to a user
115
- * clicking off of the menu or menubar.
116
- */
117
-
118
- /**
119
- * ref handler for our menu button. If we are supplied a `focusRef` prop, we also
120
- * forward along the node.
121
- *
122
- * This is useful when this component is a child in a
123
- * menu or menubar as it will allow the parent to explicitly focus the menu
124
- * button node when that child should receive focus.
125
- */
126
-
127
- /**
128
- * Handles individual menuitem refs. We assign them to a class instance
129
- * property so that we can properly manage focus of our children.
130
- */
131
-
132
132
  render() {
133
133
  const prefix = this.context;
134
134
  const {
@@ -191,13 +191,6 @@ class HeaderMenu extends React__default.Component {
191
191
  className: `${prefix}--header__menu`
192
192
  }), React__default.Children.map(children, this._renderMenuItem)));
193
193
  }
194
-
195
- /**
196
- * We capture the `ref` for each child inside of `this.items` to properly
197
- * manage focus. In addition to this focus management, all items receive a
198
- * `tabIndex: -1` so the user won't hit a large number of items in their tab
199
- * sequence when they might not want to go through all the items.
200
- */
201
194
  }
202
195
  _defineProperty(HeaderMenu, "propTypes", {
203
196
  /**
@@ -0,0 +1,39 @@
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
+ import { type ElementType } from 'react';
8
+ import PropTypes from 'prop-types';
9
+ import { type LinkProps } from './Link';
10
+ type HeaderNameProps<E extends ElementType> = LinkProps<E> & {
11
+ prefix?: string | undefined;
12
+ };
13
+ declare function HeaderName<E extends ElementType = 'a'>({ children, className: customClassName, prefix, ...rest }: HeaderNameProps<E>): JSX.Element;
14
+ declare namespace HeaderName {
15
+ var propTypes: {
16
+ /**
17
+ * Pass in children that are either a string or can be read as a string by
18
+ * screen readers
19
+ */
20
+ children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
21
+ /**
22
+ * Optionally provide a custom class to apply to the underlying `<li>` node
23
+ */
24
+ className: PropTypes.Requireable<string>;
25
+ /**
26
+ * Provide an href for the name to link to
27
+ */
28
+ href: PropTypes.Requireable<string>;
29
+ /**
30
+ * Optionally specify a prefix to your header name. Useful for companies, for
31
+ * example: IBM [Product Name] versus solely [Product Name]
32
+ */
33
+ prefix: PropTypes.Requireable<string>;
34
+ as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
35
+ element: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
36
+ isSideNavExpanded: PropTypes.Requireable<boolean>;
37
+ };
38
+ }
39
+ export default HeaderName;
@@ -16,15 +16,13 @@ function HeaderName(_ref) {
16
16
  let {
17
17
  children,
18
18
  className: customClassName,
19
- prefix,
20
- href,
19
+ prefix = 'IBM',
21
20
  ...rest
22
21
  } = _ref;
23
22
  const selectorPrefix = usePrefix();
24
23
  const className = cx(`${selectorPrefix}--header__name`, customClassName);
25
24
  return /*#__PURE__*/React__default.createElement(Link, _extends({}, rest, {
26
- className: className,
27
- href: href
25
+ className: className
28
26
  }), prefix && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("span", {
29
27
  className: `${selectorPrefix}--header__name--prefix`
30
28
  }, prefix), "\xA0"), children);
@@ -54,8 +52,5 @@ HeaderName.propTypes = {
54
52
  */
55
53
  prefix: PropTypes.string
56
54
  };
57
- HeaderName.defaultProps = {
58
- prefix: 'IBM'
59
- };
60
55
 
61
56
  export { HeaderName as default };
@@ -60,7 +60,7 @@ const HeaderPanel = /*#__PURE__*/React__default.forwardRef(function HeaderPanel(
60
60
  useWindowEvent('click', () => {
61
61
  const focusedElement = document.activeElement;
62
62
  setLastClickedElement(focusedElement);
63
- if (children.type.__docgenInfo.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelRef?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
63
+ if (children.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelRef?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
64
64
  setExpandedState(false);
65
65
  onHeaderPanelFocus();
66
66
  }
@@ -55,5 +55,6 @@ const LinkPropTypes = {
55
55
  };
56
56
  Link.displayName = 'Link';
57
57
  Link.propTypes = LinkPropTypes;
58
+ var Link$1 = Link;
58
59
 
59
- export { LinkPropTypes, Link as default };
60
+ export { LinkPropTypes, Link$1 as default };
package/es/index.js CHANGED
@@ -59,6 +59,7 @@ export { default as TextAreaSkeleton } from './components/TextArea/TextArea.Skel
59
59
  import './components/TextInput/index.js';
60
60
  export { ClickableTile, ExpandableTile, SelectableTile, Tile, TileAboveTheFoldContent, TileBelowTheFoldContent } from './components/Tile/Tile.js';
61
61
  export { default as TileGroup } from './components/TileGroup/index.js';
62
+ export { Toggle } from './components/Toggle/Toggle.js';
62
63
  export { default as ToggleSkeleton } from './components/Toggle/Toggle.Skeleton.js';
63
64
  export { default as ToggleSmallSkeleton } from './components/ToggleSmall/ToggleSmall.Skeleton.js';
64
65
  export { Toggletip, ToggletipActions, ToggletipButton, ToggletipContent, ToggletipLabel } from './components/Toggletip/index.js';
@@ -110,7 +111,6 @@ export { default as NumberInputSkeleton } from './components/NumberInput/NumberI
110
111
  export { default as ProgressIndicatorSkeleton } from './components/ProgressIndicator/ProgressIndicator.Skeleton.js';
111
112
  export { default as TextInputSkeleton } from './components/TextInput/TextInput.Skeleton.js';
112
113
  export { default as TextInput } from './components/TextInput/TextInput.js';
113
- export { Toggle } from './components/Toggle/Toggle.js';
114
114
  export { default as TreeNode } from './components/TreeView/TreeNode.js';
115
115
  export { default as TreeView } from './components/TreeView/TreeView.js';
116
116
  export { default as HeaderContainer } from './components/UIShell/HeaderContainer.js';
@@ -142,6 +142,7 @@ class FloatingMenu extends React__default.Component {
142
142
  var _this;
143
143
  super(...arguments);
144
144
  _this = this;
145
+ // `true` if the menu body is mounted and calculation of the position is in progress.
145
146
  _defineProperty(this, "_placeInProgress", false);
146
147
  _defineProperty(this, "state", {
147
148
  /**
@@ -150,10 +151,36 @@ class FloatingMenu extends React__default.Component {
150
151
  */
151
152
  floatingPosition: undefined
152
153
  });
154
+ /**
155
+ * The cached reference to the menu container.
156
+ * Only used if React portal API is not available.
157
+ * @type {Element}
158
+ * @private
159
+ */
153
160
  _defineProperty(this, "_menuContainer", null);
161
+ /**
162
+ * The cached reference to the menu body.
163
+ * The reference is set via callback ref instead of object ref,
164
+ * in order to hook the event when the element ref gets available,
165
+ * which can be at a different timing from `cDM()`, presumably with SSR scenario.
166
+ * @type {Element}
167
+ * @private
168
+ */
154
169
  _defineProperty(this, "_menuBody", null);
170
+ /**
171
+ * Focus sentinel refs for focus trap behavior
172
+ */
155
173
  _defineProperty(this, "startSentinel", /*#__PURE__*/React__default.createRef());
156
174
  _defineProperty(this, "endSentinel", /*#__PURE__*/React__default.createRef());
175
+ /**
176
+ * Calculates the position in the viewport of floating menu,
177
+ * once this component is mounted or updated upon change in the following props:
178
+ *
179
+ * * `menuOffset` (The adjustment that should be applied to the calculated floating menu's position)
180
+ * * `menuDirection` (Where the floating menu menu should be placed relative to the trigger button)
181
+ *
182
+ * @private
183
+ */
157
184
  _defineProperty(this, "_updateMenuSize", function () {
158
185
  let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
159
186
  let isAdjustment = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -227,6 +254,11 @@ class FloatingMenu extends React__default.Component {
227
254
  }
228
255
  }
229
256
  });
257
+ /**
258
+ * Set focus on floating menu content after menu placement.
259
+ * @param {Element} menuBody The DOM element of the menu body.
260
+ * @private
261
+ */
230
262
  _defineProperty(this, "_focusMenuContent", menuBody => {
231
263
  const primaryFocusNode = menuBody.querySelector(this.props.selectorPrimaryFocus || null);
232
264
  const tabbableNode = menuBody.querySelector(selectorTabbable);
@@ -243,6 +275,10 @@ class FloatingMenu extends React__default.Component {
243
275
  process.env.NODE_ENV !== "production" ? warning(focusableNode === null, 'Floating Menus must have at least a programmatically focusable child. ' + 'This can be accomplished by adding tabIndex="-1" to the content element.') : void 0;
244
276
  }
245
277
  });
278
+ /**
279
+ * A callback for called when menu body is mounted or unmounted.
280
+ * @param {Element} menuBody The menu body being mounted. `null` if the menu body is being unmounted.
281
+ */
246
282
  _defineProperty(this, "_menuRef", menuBody => {
247
283
  const {
248
284
  menuRef
@@ -253,6 +289,10 @@ class FloatingMenu extends React__default.Component {
253
289
  this._updateMenuSize();
254
290
  }
255
291
  });
292
+ /**
293
+ * @returns The child nodes, with styles containing the floating menu position.
294
+ * @private
295
+ */
256
296
  _defineProperty(this, "_getChildrenWithProps", () => {
257
297
  const {
258
298
  styles,
@@ -281,6 +321,12 @@ class FloatingMenu extends React__default.Component {
281
321
  }
282
322
  });
283
323
  });
324
+ /**
325
+ * Blur handler for when focus wrap behavior is enabled
326
+ * @param {Event} event
327
+ * @param {Element} event.target previously focused node
328
+ * @param {Element} event.relatedTarget current focused node
329
+ */
284
330
  _defineProperty(this, "handleBlur", _ref2 => {
285
331
  let {
286
332
  target: oldActiveNode,
@@ -302,33 +348,7 @@ class FloatingMenu extends React__default.Component {
302
348
  });
303
349
  }
304
350
  });
305
- } // `true` if the menu body is mounted and calculation of the position is in progress.
306
- /**
307
- * The cached reference to the menu container.
308
- * Only used if React portal API is not available.
309
- * @type {Element}
310
- * @private
311
- */
312
- /**
313
- * The cached reference to the menu body.
314
- * The reference is set via callback ref instead of object ref,
315
- * in order to hook the event when the element ref gets available,
316
- * which can be at a different timing from `cDM()`, presumably with SSR scenario.
317
- * @type {Element}
318
- * @private
319
- */
320
- /**
321
- * Focus sentinel refs for focus trap behavior
322
- */
323
- /**
324
- * Calculates the position in the viewport of floating menu,
325
- * once this component is mounted or updated upon change in the following props:
326
- *
327
- * * `menuOffset` (The adjustment that should be applied to the calculated floating menu's position)
328
- * * `menuDirection` (Where the floating menu menu should be placed relative to the trigger button)
329
- *
330
- * @private
331
- */
351
+ }
332
352
  componentWillUnmount() {
333
353
  this.hResize.release();
334
354
  }
@@ -337,12 +357,6 @@ class FloatingMenu extends React__default.Component {
337
357
  this._updateMenuSize();
338
358
  });
339
359
  }
340
- /**
341
- * Set focus on floating menu content after menu placement.
342
- * @param {Element} menuBody The DOM element of the menu body.
343
- * @private
344
- */
345
-
346
360
  componentDidUpdate(prevProps) {
347
361
  this._updateMenuSize(prevProps);
348
362
  const {
@@ -358,24 +372,6 @@ class FloatingMenu extends React__default.Component {
358
372
  }
359
373
  }
360
374
  }
361
-
362
- /**
363
- * A callback for called when menu body is mounted or unmounted.
364
- * @param {Element} menuBody The menu body being mounted. `null` if the menu body is being unmounted.
365
- */
366
-
367
- /**
368
- * @returns The child nodes, with styles containing the floating menu position.
369
- * @private
370
- */
371
-
372
- /**
373
- * Blur handler for when focus wrap behavior is enabled
374
- * @param {Event} event
375
- * @param {Element} event.target previously focused node
376
- * @param {Element} event.relatedTarget current focused node
377
- */
378
-
379
375
  render() {
380
376
  const {
381
377
  context: prefix
@@ -22,7 +22,7 @@ import { warning } from './warning.js';
22
22
  * @param {string} [config.name] - the name of the custom component
23
23
  * @param {any} config.defaultValue - the default value used for the state. This will be
24
24
  * the fallback value used if `value` is not defined.
25
- * @param {Function} config.onChange - an optional function that is called when
25
+ * @param {Function|undefined} config.onChange - an optional function that is called when
26
26
  * the value of the state changes. This is useful for communicating to parents of
27
27
  * controlled components that the value is requesting to be changed.
28
28
  * @param {any} config.value - a controlled value. Omitting this means that the state is
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { useLayoutEffect, useEffect, useState } from 'react';
8
+ import { useLayoutEffect, useEffect, useState, useId as useId$1 } from 'react';
9
9
  import setupGetInstanceId from '../tools/setupGetInstanceId.js';
10
10
  import { canUseDOM } from './environment.js';
11
11
  import { useIdPrefix } from './useIdPrefix.js';
@@ -39,6 +39,15 @@ function useId() {
39
39
  serverHandoffCompleted = true;
40
40
  }
41
41
  }, []);
42
+ if (useId$1) {
43
+ const id = nativeReactUseId(_prefix, prefix);
44
+ return id;
45
+ }
46
+ return id;
47
+ }
48
+ function nativeReactUseId(_prefix, prefix) {
49
+ const getId = useId$1();
50
+ const id = `${_prefix ? `${_prefix}-` : ``}${prefix}-${getId}`;
42
51
  return id;
43
52
  }
44
53
 
@@ -37,6 +37,14 @@ var Downshift__default = /*#__PURE__*/_interopDefaultLegacy(Downshift);
37
37
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
38
38
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
39
39
 
40
+ const {
41
+ keyDownArrowDown,
42
+ keyDownArrowUp,
43
+ keyDownEscape,
44
+ clickButton,
45
+ blurButton,
46
+ changeInput
47
+ } = Downshift__default["default"].stateChangeTypes;
40
48
  const defaultItemToString = item => {
41
49
  if (typeof item === 'string') {
42
50
  return item;
@@ -126,6 +134,7 @@ const ComboBox = /*#__PURE__*/React__default["default"].forwardRef((props, ref)
126
134
  const [isFocused, setIsFocused] = React.useState(false);
127
135
  const [prevSelectedItem, setPrevSelectedItem] = React.useState();
128
136
  const [doneInitialSelectedItem, setDoneInitialSelectedItem] = React.useState(false);
137
+ const [highlightedIndex, setHighlightedIndex] = React.useState();
129
138
  const savedOnInputChange = React.useRef(onInputChange);
130
139
  if (!doneInitialSelectedItem || prevSelectedItem !== selectedItem) {
131
140
  setDoneInitialSelectedItem(true);
@@ -165,19 +174,43 @@ const ComboBox = /*#__PURE__*/React__default["default"].forwardRef((props, ref)
165
174
  textInput.current.focus();
166
175
  }
167
176
  };
168
- const handleOnStateChange = (newState, _ref3) => {
169
- let {
170
- setHighlightedIndex
171
- } = _ref3;
172
- if (Object.prototype.hasOwnProperty.call(newState, 'inputValue')) {
177
+ const getHighlightedIndex = changes => {
178
+ if (Object.prototype.hasOwnProperty.call(changes, 'inputValue')) {
173
179
  const {
174
180
  inputValue
175
- } = newState;
181
+ } = changes;
176
182
  const filteredItems = filterItems(items, itemToString, inputValue);
177
- setHighlightedIndex(findHighlightedIndex({
183
+ const indexToHighlight = findHighlightedIndex({
178
184
  ...props,
179
185
  items: filteredItems
180
- }, inputValue));
186
+ }, inputValue);
187
+ setHighlightedIndex(indexToHighlight);
188
+ return indexToHighlight;
189
+ }
190
+ return highlightedIndex;
191
+ };
192
+ const handleOnStateChange = (changes, _ref3) => {
193
+ let {
194
+ setHighlightedIndex: updateHighlightedIndex
195
+ } = _ref3;
196
+ const {
197
+ type
198
+ } = changes;
199
+ switch (type) {
200
+ case keyDownArrowDown:
201
+ case keyDownArrowUp:
202
+ setHighlightedIndex(changes.highlightedIndex);
203
+ break;
204
+ case blurButton:
205
+ case keyDownEscape:
206
+ setHighlightedIndex(changes.highlightedIndex);
207
+ break;
208
+ case clickButton:
209
+ setHighlightedIndex(changes.highlightedIndex);
210
+ break;
211
+ case changeInput:
212
+ updateHighlightedIndex(getHighlightedIndex(changes));
213
+ break;
181
214
  }
182
215
  };
183
216
  const handleToggleClick = isOpen => event => {
@@ -239,7 +272,6 @@ const ComboBox = /*#__PURE__*/React__default["default"].forwardRef((props, ref)
239
272
  isOpen,
240
273
  inputValue,
241
274
  selectedItem,
242
- highlightedIndex,
243
275
  clearSelection,
244
276
  toggleMenu
245
277
  } = _ref4;
@@ -337,6 +369,7 @@ const ComboBox = /*#__PURE__*/React__default["default"].forwardRef((props, ref)
337
369
  "aria-expanded": rootProps['aria-expanded'],
338
370
  "aria-haspopup": "listbox",
339
371
  "aria-controls": inputProps['aria-controls'],
372
+ "aria-owns": getMenuProps().id,
340
373
  title: textInput?.current?.value
341
374
  }, inputProps, rest, readOnlyEventHandlers, {
342
375
  readOnly: readOnly,
@@ -368,7 +401,7 @@ const ComboBox = /*#__PURE__*/React__default["default"].forwardRef((props, ref)
368
401
  return /*#__PURE__*/React__default["default"].createElement(index["default"].MenuItem, _rollupPluginBabelHelpers["extends"]({
369
402
  key: itemProps.id,
370
403
  isActive: selectedItem === item,
371
- isHighlighted: highlightedIndex === index$1 || selectedItem?.id && selectedItem?.id === item.id || false,
404
+ isHighlighted: highlightedIndex === index$1,
372
405
  title: itemToElement ? item.text : itemToString ? itemToString(item) : undefined
373
406
  }, itemProps), itemToElement ?
374
407
  /*#__PURE__*/