@carbon/react 1.62.1 → 1.63.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 (54) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +822 -822
  2. package/es/components/Checkbox/Checkbox.js +2 -3
  3. package/es/components/CheckboxGroup/CheckboxGroup.js +2 -3
  4. package/es/components/ComboBox/ComboBox.js +4 -3
  5. package/es/components/DataTable/DataTable.js +1 -1
  6. package/es/components/DataTable/TableSelectRow.js +3 -2
  7. package/es/components/DataTable/TableToolbarSearch.js +3 -4
  8. package/es/components/DatePickerInput/DatePickerInput.js +2 -3
  9. package/es/components/Dropdown/Dropdown.js +3 -6
  10. package/es/components/FluidSearch/FluidSearch.Skeleton.js +40 -0
  11. package/es/components/FluidSearch/FluidSearch.js +96 -0
  12. package/es/components/Modal/Modal.js +2 -3
  13. package/es/components/MultiSelect/FilterableMultiSelect.js +10 -7
  14. package/es/components/MultiSelect/MultiSelect.js +10 -10
  15. package/es/components/Pagination/experimental/PageSelector.js +2 -3
  16. package/es/components/RadioButtonGroup/RadioButtonGroup.js +2 -5
  17. package/es/components/Select/Select.js +3 -6
  18. package/es/components/Tag/DismissibleTag.js +2 -3
  19. package/es/components/Tag/OperationalTag.js +2 -3
  20. package/es/components/Tag/SelectableTag.js +2 -3
  21. package/es/components/Tag/Tag.js +3 -5
  22. package/es/components/TextArea/TextArea.js +32 -6
  23. package/es/components/TextInput/ControlledPasswordInput.js +3 -6
  24. package/es/components/TextInput/TextInput.js +29 -2
  25. package/es/index.d.ts +1 -0
  26. package/es/index.js +2 -0
  27. package/es/internal/useAnnouncer.js +8 -3
  28. package/lib/components/Checkbox/Checkbox.js +2 -3
  29. package/lib/components/CheckboxGroup/CheckboxGroup.js +2 -3
  30. package/lib/components/ComboBox/ComboBox.js +4 -3
  31. package/lib/components/DataTable/DataTable.js +1 -1
  32. package/lib/components/DataTable/TableSelectRow.js +2 -1
  33. package/lib/components/DataTable/TableToolbarSearch.js +2 -3
  34. package/lib/components/DatePickerInput/DatePickerInput.js +2 -3
  35. package/lib/components/Dropdown/Dropdown.js +2 -5
  36. package/lib/components/FluidSearch/FluidSearch.Skeleton.js +50 -0
  37. package/lib/components/FluidSearch/FluidSearch.js +106 -0
  38. package/lib/components/Modal/Modal.js +2 -3
  39. package/lib/components/MultiSelect/FilterableMultiSelect.js +9 -6
  40. package/lib/components/MultiSelect/MultiSelect.js +9 -9
  41. package/lib/components/Pagination/experimental/PageSelector.js +2 -3
  42. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +2 -5
  43. package/lib/components/Select/Select.js +2 -5
  44. package/lib/components/Tag/DismissibleTag.js +2 -3
  45. package/lib/components/Tag/OperationalTag.js +2 -3
  46. package/lib/components/Tag/SelectableTag.js +2 -3
  47. package/lib/components/Tag/Tag.js +3 -5
  48. package/lib/components/TextArea/TextArea.js +32 -6
  49. package/lib/components/TextInput/ControlledPasswordInput.js +2 -5
  50. package/lib/components/TextInput/TextInput.js +28 -1
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.js +4 -0
  53. package/lib/internal/useAnnouncer.js +8 -3
  54. package/package.json +18 -17
@@ -12,11 +12,10 @@ import cx from 'classnames';
12
12
  import '../Text/index.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
15
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
15
+ import { useId } from '../../internal/useId.js';
16
16
  import { noopFn } from '../../internal/noopFn.js';
17
17
  import { Text } from '../Text/Text.js';
18
18
 
19
- const getInstanceId = setupGetInstanceId();
20
19
  const Checkbox = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
21
20
  let {
22
21
  className,
@@ -39,7 +38,7 @@ const Checkbox = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
39
38
  const prefix = usePrefix();
40
39
  const showWarning = !readOnly && !invalid && warn;
41
40
  const showHelper = !invalid && !warn;
42
- const checkboxGroupInstanceId = getInstanceId();
41
+ const checkboxGroupInstanceId = useId();
43
42
  const helperId = !helperText ? undefined : `checkbox-helper-text-${checkboxGroupInstanceId}`;
44
43
  const helper = helperText ? /*#__PURE__*/React__default.createElement("div", {
45
44
  id: helperId,
@@ -11,9 +11,8 @@ import React__default from 'react';
11
11
  import cx from 'classnames';
12
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
13
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
14
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
14
+ import { useId } from '../../internal/useId.js';
15
15
 
16
- const getInstanceId = setupGetInstanceId();
17
16
  const CheckboxGroup = _ref => {
18
17
  let {
19
18
  children,
@@ -33,7 +32,7 @@ const CheckboxGroup = _ref => {
33
32
  const prefix = usePrefix();
34
33
  const showWarning = !readOnly && !invalid && warn;
35
34
  const showHelper = !invalid && !warn;
36
- const checkboxGroupInstanceId = getInstanceId();
35
+ const checkboxGroupInstanceId = useId();
37
36
  const helperId = !helperText ? undefined : `checkbox-group-helper-text-${checkboxGroupInstanceId}`;
38
37
  const helper = helperText ? /*#__PURE__*/React__default.createElement("div", {
39
38
  id: helperId,
@@ -13,7 +13,7 @@ import React__default, { forwardRef, useEffect, useContext, useRef, useState, us
13
13
  import '../Text/index.js';
14
14
  import { WarningFilled, WarningAltFilled, Checkmark } from '@carbon/icons-react';
15
15
  import ListBox from '../ListBox/index.js';
16
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
16
+ import { useId } from '../../internal/useId.js';
17
17
  import mergeRefs from '../../tools/mergeRefs.js';
18
18
  import deprecate from '../../prop-types/deprecate.js';
19
19
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -82,7 +82,6 @@ const findHighlightedIndex = (_ref2, inputValue) => {
82
82
  }
83
83
  return -1;
84
84
  };
85
- const getInstanceId = setupGetInstanceId();
86
85
  const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
87
86
  const {
88
87
  ['aria-label']: ariaLabel = 'Choose an item',
@@ -144,7 +143,7 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
144
143
  isFluid
145
144
  } = useContext(FormContext);
146
145
  const textInput = useRef(null);
147
- const comboBoxInstanceId = getInstanceId();
146
+ const comboBoxInstanceId = useId();
148
147
  const [inputValue, setInputValue] = useState(getInputValue({
149
148
  initialSelectedItem,
150
149
  inputValue: '',
@@ -383,6 +382,8 @@ const ComboBox = /*#__PURE__*/forwardRef((props, ref) => {
383
382
  // when both the message is supplied *and* when the component is in
384
383
  // the matching state (invalid, warn, etc).
385
384
  const ariaDescribedBy = invalid && invalidText && invalidTextId || warn && warnText && warnTextId || helperText && !isFluid && helperTextId || undefined;
385
+
386
+ // Memoize the value of getMenuProps to avoid an infinite loop
386
387
  const menuProps = useMemo(() => getMenuProps({
387
388
  'aria-label': deprecatedAriaLabel || ariaLabel,
388
389
  ref: autoAlign ? refs.setFloating : null
@@ -8,7 +8,7 @@
8
8
  import { defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
10
  import React__default from 'react';
11
- import isEqual from 'lodash.isequal';
11
+ import isEqual from 'react-fast-compare';
12
12
  import getDerivedStateFromProps from './state/getDerivedStateFromProps.js';
13
13
  import { getNextSortState } from './state/sorting.js';
14
14
  import { getCellId } from './tools/cells.js';
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default from 'react';
10
+ import React__default, { useId } from 'react';
11
11
  import cx from 'classnames';
12
12
  import InlineCheckbox from '../InlineCheckbox/InlineCheckbox.js';
13
13
  import RadioButton from '../RadioButton/RadioButton.js';
@@ -28,9 +28,10 @@ const TableSelectRow = _ref => {
28
28
  className
29
29
  } = _ref;
30
30
  const prefix = usePrefix();
31
+ const uniqueNameId = useId();
31
32
  const selectionInputProps = {
32
33
  id,
33
- name,
34
+ name: name ? name : uniqueNameId,
34
35
  onClick: onSelect,
35
36
  onChange,
36
37
  checked,
@@ -8,14 +8,13 @@
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
- import React__default, { useRef, useState, useMemo, useEffect } from 'react';
11
+ import React__default, { useRef, useState, useEffect } from 'react';
12
12
  import Search from '../Search/Search.js';
13
13
  import '../Search/Search.Skeleton.js';
14
- import setupGetInstanceId from './tools/instanceId.js';
14
+ import { useId } from '../../internal/useId.js';
15
15
  import { usePrefix } from '../../internal/usePrefix.js';
16
16
  import { noopFn } from '../../internal/noopFn.js';
17
17
 
18
- const getInstanceId = setupGetInstanceId();
19
18
  const translationKeys = {
20
19
  'carbon.table.toolbar.search.label': 'Filter table',
21
20
  'carbon.table.toolbar.search.placeholder': 'Filter table'
@@ -51,7 +50,7 @@ const TableToolbarSearch = _ref => {
51
50
  const [expandedState, setExpandedState] = useState(Boolean(defaultExpanded || defaultValue));
52
51
  const expanded = controlled ? expandedProp : expandedState;
53
52
  const [value, setValue] = useState(defaultValue || '');
54
- const uniqueId = useMemo(getInstanceId, []);
53
+ const uniqueId = useId();
55
54
  const [focusTarget, setFocusTarget] = useState(null);
56
55
  const prefix = usePrefix();
57
56
  useEffect(() => {
@@ -12,11 +12,10 @@ import React__default, { useContext } from 'react';
12
12
  import { usePrefix } from '../../internal/usePrefix.js';
13
13
  import '../FluidForm/FluidForm.js';
14
14
  import { FormContext } from '../FluidForm/FormContext.js';
15
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
15
+ import { useId } from '../../internal/useId.js';
16
16
  import '../Text/index.js';
17
17
  import { Text } from '../Text/Text.js';
18
18
 
19
- const getInstanceId = setupGetInstanceId();
20
19
  const DatePickerInput = /*#__PURE__*/React__default.forwardRef(function DatePickerInput(props, ref) {
21
20
  const {
22
21
  datePickerType,
@@ -42,7 +41,7 @@ const DatePickerInput = /*#__PURE__*/React__default.forwardRef(function DatePick
42
41
  const {
43
42
  isFluid
44
43
  } = useContext(FormContext);
45
- const datePickerInputInstanceId = getInstanceId();
44
+ const datePickerInputInstanceId = useId();
46
45
  const datePickerInputProps = {
47
46
  id,
48
47
  onChange: event => {
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useEffect, useContext, useRef, useState, useMemo } from 'react';
9
+ import React__default, { useEffect, useContext, useState, useMemo } from 'react';
10
10
  import { useSelect } from 'downshift';
11
11
  import cx from 'classnames';
12
12
  import PropTypes from 'prop-types';
@@ -17,11 +17,10 @@ import deprecate from '../../prop-types/deprecate.js';
17
17
  import { usePrefix } from '../../internal/usePrefix.js';
18
18
  import '../FluidForm/FluidForm.js';
19
19
  import { FormContext } from '../FluidForm/FormContext.js';
20
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
20
+ import { useId } from '../../internal/useId.js';
21
21
  import { useFloating, size, flip, autoUpdate } from '@floating-ui/react';
22
22
  import { ListBoxSize, ListBoxType } from '../ListBox/ListBoxPropTypes.js';
23
23
 
24
- const getInstanceId = setupGetInstanceId();
25
24
  const {
26
25
  ToggleButtonKeyDownArrowDown,
27
26
  ToggleButtonKeyDownArrowUp,
@@ -125,9 +124,7 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
125
124
  return isObject && 'disabled' in item && item.disabled === true;
126
125
  }
127
126
  };
128
- const {
129
- current: dropdownInstanceId
130
- } = useRef(getInstanceId());
127
+ const dropdownInstanceId = useId();
131
128
  function stateReducer(state, actionAndChanges) {
132
129
  const {
133
130
  changes,
@@ -0,0 +1,40 @@
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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import PropTypes from 'prop-types';
10
+ import React__default from 'react';
11
+ import cx from 'classnames';
12
+ import { usePrefix } from '../../internal/usePrefix.js';
13
+ import { FormContext } from '../FluidForm/FormContext.js';
14
+
15
+ function FluidSearchSkeleton(_ref) {
16
+ let {
17
+ className,
18
+ ...other
19
+ } = _ref;
20
+ const prefix = usePrefix();
21
+ return /*#__PURE__*/React__default.createElement(FormContext.Provider, {
22
+ value: {
23
+ isFluid: true
24
+ }
25
+ }, /*#__PURE__*/React__default.createElement("div", _extends({
26
+ className: cx(`${prefix}--form-item ${prefix}--text-input--fluid__skeleton`, className)
27
+ }, other), /*#__PURE__*/React__default.createElement("span", {
28
+ className: `${prefix}--label ${prefix}--skeleton`
29
+ }), /*#__PURE__*/React__default.createElement("div", {
30
+ className: `${prefix}--skeleton ${prefix}--text-input`
31
+ })));
32
+ }
33
+ FluidSearchSkeleton.propTypes = {
34
+ /**
35
+ * Specify an optional className to be applied to the outer FluidForm wrapper
36
+ */
37
+ className: PropTypes.string
38
+ };
39
+
40
+ export { FluidSearchSkeleton as default };
@@ -0,0 +1,96 @@
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 { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import PropTypes from 'prop-types';
10
+ import React__default from 'react';
11
+ import cx from 'classnames';
12
+ import Search from '../Search/Search.js';
13
+ import '../Search/Search.Skeleton.js';
14
+ import { usePrefix } from '../../internal/usePrefix.js';
15
+ import { FormContext } from '../FluidForm/FormContext.js';
16
+
17
+ const FluidSearch = /*#__PURE__*/React__default.forwardRef(function FluidSearch(_ref, ref) {
18
+ let {
19
+ className,
20
+ ...other
21
+ } = _ref;
22
+ const prefix = usePrefix();
23
+ const classNames = cx(`${prefix}--search--fluid`, className);
24
+ return /*#__PURE__*/React__default.createElement(FormContext.Provider, {
25
+ value: {
26
+ isFluid: true
27
+ }
28
+ }, /*#__PURE__*/React__default.createElement(Search, _extends({
29
+ ref: ref,
30
+ className: classNames
31
+ }, other)));
32
+ });
33
+ FluidSearch.propTypes = {
34
+ /**
35
+ * Specify an optional value for the `autocomplete` property on the underlying
36
+ * `<input>`, defaults to "off"
37
+ */
38
+ autoComplete: PropTypes.string,
39
+ /**
40
+ * Specify an optional className to be applied to the container node
41
+ */
42
+ className: PropTypes.string,
43
+ /**
44
+ * Specify a label to be read by screen readers on the "close" button
45
+ */
46
+ closeButtonLabelText: PropTypes.string,
47
+ /**
48
+ * Optionally provide the default value of the `<input>`
49
+ */
50
+ defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
51
+ /**
52
+ * Specify whether the `<input>` should be disabled
53
+ */
54
+ disabled: PropTypes.bool,
55
+ /**
56
+ * Specify a custom `id` for the input
57
+ */
58
+ id: PropTypes.string,
59
+ /**
60
+ * Provide the label text for the Search icon
61
+ */
62
+ labelText: PropTypes.node.isRequired,
63
+ /**
64
+ * Optional callback called when the search value changes.
65
+ */
66
+ onChange: PropTypes.func,
67
+ /**
68
+ * Optional callback called when the search value is cleared.
69
+ */
70
+ onClear: PropTypes.func,
71
+ /**
72
+ * Provide a handler that is invoked on the key down event for the input
73
+ */
74
+ onKeyDown: PropTypes.func,
75
+ /**
76
+ * Provide an optional placeholder text for the Search.
77
+ * Note: if the label and placeholder differ,
78
+ * VoiceOver on Mac will read both
79
+ */
80
+ placeholder: PropTypes.string,
81
+ /**
82
+ * Specify the role for the underlying `<input>`, defaults to `searchbox`
83
+ */
84
+ role: PropTypes.string,
85
+ /**
86
+ * Optional prop to specify the type of the `<input>`
87
+ */
88
+ type: PropTypes.string,
89
+ /**
90
+ * Specify the value of the `<input>`
91
+ */
92
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
93
+ };
94
+ var FluidSearch$1 = FluidSearch;
95
+
96
+ export { FluidSearch$1 as default };
@@ -20,7 +20,7 @@ import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsT
20
20
  import wrapFocus, { wrapFocusWithoutSentinels, elementOrParentIsFloatingMenu } from '../../internal/wrapFocus.js';
21
21
  import debounce from 'lodash.debounce';
22
22
  import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
23
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
23
+ import { useId } from '../../internal/useId.js';
24
24
  import { usePrefix } from '../../internal/usePrefix.js';
25
25
  import { IconButton } from '../IconButton/index.js';
26
26
  import { noopFn } from '../../internal/noopFn.js';
@@ -31,7 +31,6 @@ import { Text } from '../Text/Text.js';
31
31
  import { match } from '../../internal/keyboard/match.js';
32
32
  import { Escape, Enter, Tab } from '../../internal/keyboard/keys.js';
33
33
 
34
- const getInstanceId = setupGetInstanceId();
35
34
  const ModalSizes = ['xs', 'sm', 'md', 'lg'];
36
35
  const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
37
36
  let {
@@ -76,7 +75,7 @@ const Modal = /*#__PURE__*/React__default.forwardRef(function Modal(_ref, ref) {
76
75
  const startTrap = useRef(null);
77
76
  const endTrap = useRef(null);
78
77
  const [isScrollable, setIsScrollable] = useState(false);
79
- const modalInstanceId = `modal-${getInstanceId()}`;
78
+ const modalInstanceId = `modal-${useId()}`;
80
79
  const modalLabelId = `${prefix}--modal-header__label--${modalInstanceId}`;
81
80
  const modalHeadingId = `${prefix}--modal-header__heading--${modalInstanceId}`;
82
81
  const modalBodyId = `${prefix}--modal-body--${modalInstanceId}`;
@@ -11,7 +11,7 @@ import cx from 'classnames';
11
11
  import Downshift, { useCombobox, useMultipleSelection } from 'downshift';
12
12
  import isEqual from 'lodash.isequal';
13
13
  import PropTypes from 'prop-types';
14
- import React__default, { useContext, useState, useLayoutEffect, useRef, useEffect } from 'react';
14
+ import React__default, { useContext, useState, useLayoutEffect, useRef, useEffect, useMemo } 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';
@@ -460,9 +460,13 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
460
460
  setInputValue('');
461
461
  }
462
462
  }));
463
- const menuProps = getMenuProps({}, {
463
+
464
+ // Memoize the value of getMenuProps to avoid an infinite loop
465
+ const menuProps = useMemo(() => getMenuProps({
466
+ ref: autoAlign ? refs.setFloating : null
467
+ }, {
464
468
  suppressRefError: true
465
- });
469
+ }), [autoAlign]);
466
470
  const handleFocus = evt => {
467
471
  if (evt?.target.classList.contains(`${prefix}--tag__close-icon`) || evt?.target.classList.contains(`${prefix}--list-box__selection`)) {
468
472
  setIsFocused(false);
@@ -488,6 +492,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
488
492
  disabled: disabled,
489
493
  light: light,
490
494
  ref: ref,
495
+ id: id,
491
496
  invalid: invalid,
492
497
  invalidText: invalidText,
493
498
  warn: warn,
@@ -496,7 +501,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
496
501
  size: size$1
497
502
  }, /*#__PURE__*/React__default.createElement("div", {
498
503
  className: `${prefix}--list-box__field`,
499
- ref: refs.setReference
504
+ ref: autoAlign ? refs.setReference : null
500
505
  }, controlledSelectedItems.length > 0 &&
501
506
  /*#__PURE__*/
502
507
  // @ts-expect-error: It is expecting a non-required prop called: "onClearSelection"
@@ -537,9 +542,7 @@ const FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function Fi
537
542
  // @ts-expect-error
538
543
  isOpen: isOpen,
539
544
  translateWithId: translateWithId
540
- }))), normalizedSlug, /*#__PURE__*/React__default.createElement(ListBox.Menu, _extends({}, menuProps, {
541
- ref: refs.setFloating
542
- }), isOpen ? sortedItems.map((item, index) => {
545
+ }))), normalizedSlug, /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, isOpen ? sortedItems.map((item, index) => {
543
546
  const isChecked = controlledSelectedItems.filter(selected => isEqual(selected, item)).length > 0;
544
547
  const itemProps = getItemProps({
545
548
  item,
@@ -11,12 +11,12 @@ import cx from 'classnames';
11
11
  import { useSelect } from 'downshift';
12
12
  import isEqual from 'lodash.isequal';
13
13
  import PropTypes from 'prop-types';
14
- import React__default, { useContext, useRef, useState, useLayoutEffect, useMemo } from 'react';
14
+ import React__default, { useContext, useState, useLayoutEffect, useMemo } from 'react';
15
15
  import ListBox from '../ListBox/index.js';
16
16
  import { sortingPropTypes } from './MultiSelectPropTypes.js';
17
17
  import { defaultSortItems, defaultCompareItems } from './tools/sorting.js';
18
18
  import { useSelection } from '../../internal/Selection.js';
19
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
19
+ import { useId } from '../../internal/useId.js';
20
20
  import mergeRefs from '../../tools/mergeRefs.js';
21
21
  import deprecate from '../../prop-types/deprecate.js';
22
22
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -28,7 +28,6 @@ import { match } from '../../internal/keyboard/match.js';
28
28
  import { ListBoxSize } from '../ListBox/ListBoxPropTypes.js';
29
29
  import { Delete, Escape, Space, ArrowDown, Enter } from '../../internal/keyboard/keys.js';
30
30
 
31
- const getInstanceId = setupGetInstanceId();
32
31
  const {
33
32
  ItemClick,
34
33
  ToggleButtonBlur,
@@ -99,9 +98,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
99
98
  const {
100
99
  isFluid
101
100
  } = useContext(FormContext);
102
- const {
103
- current: multiSelectInstanceId
104
- } = useRef(getInstanceId());
101
+ const multiSelectInstanceId = useId();
105
102
  const [isFocused, setIsFocused] = useState(false);
106
103
  const [inputFocused, setInputFocused] = useState(false);
107
104
  const [isOpen, setIsOpen] = useState(open || false);
@@ -395,6 +392,11 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
395
392
  });
396
393
  }
397
394
  const itemsSelectedText = selectedItems.length > 0 && selectedItems.map(item => item?.text);
395
+
396
+ // Memoize the value of getMenuProps to avoid an infinite loop
397
+ const menuProps = useMemo(() => getMenuProps({
398
+ ref: autoAlign ? refs.setFloating : null
399
+ }), [autoAlign]);
398
400
  return /*#__PURE__*/React__default.createElement("div", {
399
401
  className: wrapperClasses
400
402
  }, /*#__PURE__*/React__default.createElement("label", _extends({
@@ -421,7 +423,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
421
423
  className: `${prefix}--list-box__invalid-icon ${prefix}--list-box__invalid-icon--warning`
422
424
  }), /*#__PURE__*/React__default.createElement("div", {
423
425
  className: multiSelectFieldWrapperClasses,
424
- ref: refs.setReference
426
+ ref: autoAlign ? refs.setReference : null
425
427
  }, selectedItems.length > 0 && /*#__PURE__*/React__default.createElement(ListBox.Selection, {
426
428
  readOnly: readOnly,
427
429
  clearSelection: !disabled && !readOnly ? clearSelection : noopFn,
@@ -444,9 +446,7 @@ const MultiSelect = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
444
446
  }, label), /*#__PURE__*/React__default.createElement(ListBox.MenuIcon, {
445
447
  isOpen: isOpen,
446
448
  translateWithId: translateWithId
447
- })), normalizedSlug), /*#__PURE__*/React__default.createElement(ListBox.Menu, getMenuProps({
448
- ref: refs.setFloating
449
- }), isOpen &&
449
+ })), normalizedSlug), /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, isOpen &&
450
450
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
451
451
  sortItems(filteredItems, sortOptions).map((item, index) => {
452
452
  const isChecked = selectedItems.filter(selected => isEqual(selected, item)).length > 0;
@@ -9,13 +9,12 @@ import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers
9
9
  import React__default from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
- import setupGetInstanceId from '../../../tools/setupGetInstanceId.js';
12
+ import { useId } from '../../../internal/useId.js';
13
13
  import Select from '../../Select/Select.js';
14
14
  import '../../Select/Select.Skeleton.js';
15
15
  import SelectItem from '../../SelectItem/SelectItem.js';
16
16
  import { usePrefix } from '../../../internal/usePrefix.js';
17
17
 
18
- const getInstanceId = setupGetInstanceId();
19
18
  function PageSelector(_ref) {
20
19
  let {
21
20
  className = null,
@@ -27,7 +26,7 @@ function PageSelector(_ref) {
27
26
  } = _ref;
28
27
  const prefix = usePrefix();
29
28
  const namespace = `${prefix}--unstable-pagination__page-selector`;
30
- const instanceId = `${namespace}__select-${getInstanceId()}`;
29
+ const instanceId = `${namespace}__select-${useId()}`;
31
30
  const renderPages = total => {
32
31
  const pages = [];
33
32
  for (let counter = 1; counter <= total; counter += 1) {
@@ -13,9 +13,8 @@ import { Legend } from '../Text/index.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
15
15
  import mergeRefs from '../../tools/mergeRefs.js';
16
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
16
+ import { useId } from '../../internal/useId.js';
17
17
 
18
- const getInstanceId = setupGetInstanceId();
19
18
  const RadioButtonGroup = /*#__PURE__*/React__default.forwardRef((props, ref) => {
20
19
  const {
21
20
  children,
@@ -41,9 +40,7 @@ const RadioButtonGroup = /*#__PURE__*/React__default.forwardRef((props, ref) =>
41
40
  const prefix = usePrefix();
42
41
  const [selected, setSelected] = useState(valueSelected ?? defaultSelected);
43
42
  const [prevValueSelected, setPrevValueSelected] = useState(valueSelected);
44
- const {
45
- current: radioButtonGroupInstanceId
46
- } = useRef(getInstanceId());
43
+ const radioButtonGroupInstanceId = useId();
47
44
 
48
45
  /**
49
46
  * prop + state alignment - getDerivedStateFromProps
@@ -7,19 +7,18 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default, { useContext, useState, useRef } from 'react';
10
+ import React__default, { useContext, useState } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { ChevronDown, WarningFilled, WarningAltFilled } from '@carbon/icons-react';
13
13
  import deprecate from '../../prop-types/deprecate.js';
14
14
  import { usePrefix } from '../../internal/usePrefix.js';
15
15
  import '../FluidForm/FluidForm.js';
16
16
  import { FormContext } from '../FluidForm/FormContext.js';
17
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
17
+ import { useId } from '../../internal/useId.js';
18
18
  import { composeEventHandlers } from '../../tools/events.js';
19
19
  import '../Text/index.js';
20
20
  import { Text } from '../Text/Text.js';
21
21
 
22
- const getInstanceId = setupGetInstanceId();
23
22
  const Select = /*#__PURE__*/React__default.forwardRef(function Select(_ref, ref) {
24
23
  let {
25
24
  className,
@@ -50,9 +49,7 @@ const Select = /*#__PURE__*/React__default.forwardRef(function Select(_ref, ref)
50
49
  } = useContext(FormContext);
51
50
  const [isFocused, setIsFocused] = useState(false);
52
51
  const [title, setTitle] = useState('');
53
- const {
54
- current: selectInstanceId
55
- } = useRef(getInstanceId());
52
+ const selectInstanceId = useId();
56
53
  const selectClasses = cx({
57
54
  [`${prefix}--select`]: true,
58
55
  [`${prefix}--select--inline`]: inline,
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
9
9
  import PropTypes from 'prop-types';
10
10
  import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
12
+ import { useId } from '../../internal/useId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import Tag, { SIZES, TYPES } from './Tag.js';
15
15
  import { Close } from '@carbon/icons-react';
@@ -20,7 +20,6 @@ import { isEllipsisActive } from './isEllipsisActive.js';
20
20
  import { Text } from '../Text/Text.js';
21
21
 
22
22
  var _Close;
23
- const getInstanceId = setupGetInstanceId();
24
23
  const DismissibleTag = _ref => {
25
24
  let {
26
25
  className,
@@ -37,7 +36,7 @@ const DismissibleTag = _ref => {
37
36
  } = _ref;
38
37
  const prefix = usePrefix();
39
38
  const tagLabelRef = useRef();
40
- const tagId = id || `tag-${getInstanceId()}`;
39
+ const tagId = id || `tag-${useId()}`;
41
40
  const tagClasses = cx(`${prefix}--tag--filter`, className);
42
41
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
43
42
  useLayoutEffect(() => {
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
9
9
  import PropTypes from 'prop-types';
10
10
  import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
12
+ import { useId } from '../../internal/useId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import Tag, { SIZES } from './Tag.js';
15
15
  import '../Tooltip/DefinitionTooltip.js';
@@ -18,7 +18,6 @@ import '../Text/index.js';
18
18
  import { isEllipsisActive } from './isEllipsisActive.js';
19
19
  import { Text } from '../Text/Text.js';
20
20
 
21
- const getInstanceId = setupGetInstanceId();
22
21
  const TYPES = {
23
22
  red: 'Red',
24
23
  magenta: 'Magenta',
@@ -45,7 +44,7 @@ const OperationalTag = _ref => {
45
44
  } = _ref;
46
45
  const prefix = usePrefix();
47
46
  const tagRef = useRef();
48
- const tagId = id || `tag-${getInstanceId()}`;
47
+ const tagId = id || `tag-${useId()}`;
49
48
  const tagClasses = cx(`${prefix}--tag--operational`, className);
50
49
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
51
50
  useLayoutEffect(() => {
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
9
9
  import PropTypes from 'prop-types';
10
10
  import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
- import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
12
+ import { useId } from '../../internal/useId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
14
  import Tag, { SIZES } from './Tag.js';
15
15
  import '../Tooltip/DefinitionTooltip.js';
@@ -18,7 +18,6 @@ import '../Text/index.js';
18
18
  import { isEllipsisActive } from './isEllipsisActive.js';
19
19
  import { Text } from '../Text/Text.js';
20
20
 
21
- const getInstanceId = setupGetInstanceId();
22
21
  const SelectableTag = _ref => {
23
22
  let {
24
23
  className,
@@ -33,7 +32,7 @@ const SelectableTag = _ref => {
33
32
  } = _ref;
34
33
  const prefix = usePrefix();
35
34
  const tagRef = useRef();
36
- const tagId = id || `tag-${getInstanceId()}`;
35
+ const tagId = id || `tag-${useId()}`;
37
36
  const [selectedTag, setSelectedTag] = useState(selected);
38
37
  const tagClasses = cx(`${prefix}--tag--selectable`, className, {
39
38
  [`${prefix}--tag--selectable-selected`]: selectedTag