carbon-react 125.11.0 → 125.11.1

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Carbon [![npm](https://img.shields.io/npm/v/carbon-react.svg)](https://www.npmjs.com/package/carbon-react) [![Cypress](https://github.com/Sage/carbon/actions/workflows/cypress.yml/badge.svg)](https://github.com/Sage/carbon/actions/workflows/cypress.yml) [![Playwright](https://github.com/Sage/carbon/actions/workflows/playwright.yml/badge.svg)](https://github.com/Sage/carbon/actions/workflows/playwright.yml)
2
2
 
3
- Carbon is a [React](https://facebook.github.io/react/) component library developed by Sage.
3
+ Carbon is a [React](https://react.dev/) component library developed by Sage.
4
4
 
5
5
  ## Getting started
6
6
 
@@ -8,7 +8,7 @@ Our [getting started guide](https://carbon.sage.com/?path=/story/getting-started
8
8
 
9
9
  ## Examples
10
10
 
11
- See the [storybook](https://carbon.sage.com/) for live examples.
11
+ See our [docs](https://carbon.sage.com/) for live examples.
12
12
 
13
13
  ## Browser Support
14
14
 
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { TagProps } from "__internal__/utils/helpers/tags";
2
+ import { TagProps } from "../../../__internal__/utils/helpers/tags";
3
3
  export interface OptionProps extends Omit<React.InputHTMLAttributes<HTMLLIElement>, "value" | "onSelect" | "onClick">, TagProps {
4
4
  /**
5
5
  * Unique identifier for the component.
@@ -1,6 +1,7 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { useContext } from "react";
2
+ import React, { useContext, useRef } from "react";
3
3
  import PropTypes from "prop-types";
4
+ import guid from "../../../__internal__/utils/helpers/guid";
4
5
  import StyledOption from "./option.style";
5
6
  import SelectListContext from "../__internal__/select-list-context";
6
7
  const Option = /*#__PURE__*/React.forwardRef(({
@@ -18,6 +19,7 @@ const Option = /*#__PURE__*/React.forwardRef(({
18
19
  }, ref) => {
19
20
  const selectListContext = useContext(SelectListContext);
20
21
  let isSelected = selectListContext.currentOptionsListIndex === index;
22
+ const internalIdRef = useRef(id || guid());
21
23
  if (selectListContext.multiselectValues) {
22
24
  isSelected = selectListContext.multiselectValues.includes(value);
23
25
  }
@@ -29,7 +31,7 @@ const Option = /*#__PURE__*/React.forwardRef(({
29
31
  onSelect?.({
30
32
  text,
31
33
  value,
32
- id
34
+ id: internalIdRef.current
33
35
  });
34
36
  } else {
35
37
  onSelect?.();
@@ -37,7 +39,7 @@ const Option = /*#__PURE__*/React.forwardRef(({
37
39
  }
38
40
  }
39
41
  return /*#__PURE__*/React.createElement(StyledOption, _extends({
40
- id: id,
42
+ id: internalIdRef.current,
41
43
  ref: ref,
42
44
  "aria-selected": isSelected,
43
45
  "aria-disabled": disabled,
@@ -1,16 +1,20 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React from "react";
2
+ import React, { useRef } from "react";
3
3
  import PropTypes from "prop-types";
4
+ import guid from "../../../__internal__/utils/helpers/guid";
4
5
  import StyledOptionGroupHeader from "./option-group-header.style";
5
6
  import Icon from "../../icon";
6
7
  const OptionGroupHeader = /*#__PURE__*/React.forwardRef(({
7
8
  label,
8
9
  icon,
9
10
  style,
11
+ id,
10
12
  ...rest
11
13
  }, ref) => {
14
+ const internalIdRef = useRef(id || guid());
12
15
  return /*#__PURE__*/React.createElement(StyledOptionGroupHeader, _extends({
13
- style: style
16
+ style: style,
17
+ id: internalIdRef.current
14
18
  }, rest, {
15
19
  ref: ref
16
20
  }), icon && /*#__PURE__*/React.createElement(Icon, {
@@ -1,6 +1,7 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { useContext } from "react";
2
+ import React, { useContext, useRef } from "react";
3
3
  import PropTypes from "prop-types";
4
+ import guid from "../../../__internal__/utils/helpers/guid";
4
5
  import StyledOptionRow from "./option-row.style";
5
6
  import SelectListContext from "../__internal__/select-list-context";
6
7
  const OptionRow = /*#__PURE__*/React.forwardRef(({
@@ -15,14 +16,15 @@ const OptionRow = /*#__PURE__*/React.forwardRef(({
15
16
  style,
16
17
  ...rest
17
18
  }, ref) => {
19
+ const internalIdRef = useRef(id || guid());
18
20
  const handleClick = () => {
19
21
  if (disabled) {
20
22
  return;
21
23
  }
22
24
  onSelect?.({
23
- id,
24
25
  text,
25
- value
26
+ value,
27
+ id: internalIdRef.current
26
28
  });
27
29
  };
28
30
  const selectListContext = useContext(SelectListContext);
@@ -31,7 +33,7 @@ const OptionRow = /*#__PURE__*/React.forwardRef(({
31
33
  isSelected = selectListContext.multiselectValues.includes(value);
32
34
  }
33
35
  return /*#__PURE__*/React.createElement(StyledOptionRow, _extends({
34
- id: id,
36
+ id: internalIdRef.current,
35
37
  ref: ref,
36
38
  "aria-selected": isSelected,
37
39
  "aria-disabled": disabled,
@@ -17,7 +17,6 @@ import ListActionButton from "../list-action-button";
17
17
  import StyledSelectListContainer from "./select-list-container.style";
18
18
  import Loader from "../../loader";
19
19
  import Option from "../option";
20
- import guid from "../../../__internal__/utils/helpers/guid";
21
20
  import SelectListContext from "../__internal__/select-list-context";
22
21
  const TABLE_HEADER_HEIGHT = 48;
23
22
  const SCROLL_OPTIONS = {
@@ -92,16 +91,23 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
92
91
  rangeExtractor
93
92
  });
94
93
  const items = virtualizer.getVirtualItems();
94
+ const childrenList = useMemo(() => React.Children.toArray(children), [children]);
95
+ const getIndexOfMatch = useCallback(valueToMatch => {
96
+ return childrenList.findIndex(child => /*#__PURE__*/React.isValidElement(child) && child.props.value === valueToMatch);
97
+ }, [childrenList]);
95
98
 
96
99
  // getVirtualItems returns an empty array of items if the select list is currently closed - which is correct visually but
97
100
  // we need to ensure that any currently-selected option is still in the DOM to avoid any accessibility issues.
98
101
  // The isOpen prop will ensure that no options are visible regardless of what is in the items array.
99
- if (items.length === 0 && currentOptionsListIndex !== -1) {
100
- // only index property is required with the item not visible so the following type assertion, even though incorrect,
101
- // should be OK
102
- items.push({
103
- index: currentOptionsListIndex
104
- });
102
+ if (items.length === 0) {
103
+ const currentIndex = highlightedValue ? getIndexOfMatch(highlightedValue) : currentOptionsListIndex;
104
+ if (currentIndex > -1) {
105
+ // only index property is required with the item not visible so the following type assertion, even though incorrect,
106
+ // should be OK
107
+ items.push({
108
+ index: currentIndex
109
+ });
110
+ }
105
111
  }
106
112
  const listHeight = virtualizer.getTotalSize();
107
113
  useEffect(() => {
@@ -129,18 +135,9 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
129
135
  selectionConfirmed: true
130
136
  });
131
137
  }, [onSelect]);
132
- const childIdsRef = useRef(null);
133
-
134
- // childIds should be stable except when children are added or removed - can't use useMemo
135
- // as that isn't absolutely guaranteed to never rerun when dependencies haven't changed.
136
- const setChildIds = () => {
137
- childIdsRef.current = React.Children.map(children, child => /*#__PURE__*/React.isValidElement(child) && child?.props.id || guid()) || /* istanbul ignore next */null;
138
- };
139
- if (childIdsRef.current?.length !== React.Children.count(children)) {
140
- setChildIds();
141
- }
142
- const childIds = childIdsRef.current;
143
- const childrenList = useMemo(() => React.Children.toArray(children), [children]);
138
+ const childElementRefs = useRef(Array.from({
139
+ length: React.Children.count(children)
140
+ }));
144
141
  const optionChildrenList = useMemo(() => childrenList.filter(child => /*#__PURE__*/React.isValidElement(child) && (child.type === Option || child.type === OptionRow)), [childrenList]);
145
142
  const {
146
143
  measureElement
@@ -166,7 +163,6 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
166
163
  const isOption = optionChildIndex > -1;
167
164
  const newProps = {
168
165
  index,
169
- id: childIds ? childIds[index] : /* istanbul ignore next */undefined,
170
166
  onSelect: handleSelect,
171
167
  hidden: isLoading && childrenList.length === 1,
172
168
  // these need to be inline styles rather than implemented in styled-components to avoid it generating thousands of classes
@@ -175,8 +171,12 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
175
171
  },
176
172
  "aria-setsize": isOption ? optionChildrenList.length : undefined,
177
173
  "aria-posinset": isOption ? optionChildIndex + 1 : undefined,
178
- // needed to dynamically compute the size
179
- ref: measureCallback,
174
+ ref: optionElement => {
175
+ // needed to dynamically compute the size
176
+ measureCallback(optionElement);
177
+ // add the DOM element to the array of refs
178
+ childElementRefs.current[index] = optionElement;
179
+ },
180
180
  "data-index": index
181
181
  };
182
182
  return /*#__PURE__*/React.cloneElement(child, newProps);
@@ -194,9 +194,6 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
194
194
  }
195
195
  return nextIndex;
196
196
  }, [childrenList, lastOptionIndex, isLoading]);
197
- const getIndexOfMatch = useCallback(valueToMatch => {
198
- return childrenList.findIndex(child => /*#__PURE__*/React.isValidElement(child) && child.props.value === valueToMatch);
199
- }, [childrenList]);
200
197
  const highlightNextItem = useCallback(key => {
201
198
  let currentIndex = currentOptionsListIndex;
202
199
  if (highlightedValue) {
@@ -215,10 +212,10 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
215
212
  text,
216
213
  value,
217
214
  selectionType: "navigationKey",
218
- id: childIds ? childIds[nextIndex] : /* istanbul ignore next */undefined,
215
+ id: childElementRefs.current[nextIndex]?.id,
219
216
  selectionConfirmed: false
220
217
  });
221
- }, [childrenList, currentOptionsListIndex, getIndexOfMatch, getNextHighlightableItemIndex, highlightedValue, onSelect, childIds]);
218
+ }, [childrenList, currentOptionsListIndex, getIndexOfMatch, getNextHighlightableItemIndex, highlightedValue, onSelect]);
222
219
  const handleActionButtonTab = useCallback((event, isActionButtonFocused) => {
223
220
  if (isActionButtonFocused) {
224
221
  onSelect({
@@ -262,7 +259,7 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
262
259
  value
263
260
  } = currentOption.props;
264
261
  onSelect({
265
- id: childIds ? childIds[currentOptionsListIndex] : /* istanbul ignore next */undefined,
262
+ id: childElementRefs.current[currentOptionsListIndex]?.id,
266
263
  text,
267
264
  value,
268
265
  selectionType: "enterKey",
@@ -272,7 +269,7 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
272
269
  focusOnAnchor();
273
270
  highlightNextItem(key);
274
271
  }
275
- }, [childrenList, listActionButton, handleActionButtonTab, onSelectListClose, currentOptionsListIndex, onSelect, highlightNextItem, focusOnAnchor, isOpen, childIds]);
272
+ }, [childrenList, listActionButton, handleActionButtonTab, onSelectListClose, currentOptionsListIndex, onSelect, highlightNextItem, focusOnAnchor, isOpen]);
276
273
  const handleEscapeKey = useCallback(event => {
277
274
  if (event.key === "Escape") {
278
275
  onSelectListClose();
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { TagProps } from "__internal__/utils/helpers/tags";
2
+ import { TagProps } from "../../../__internal__/utils/helpers/tags";
3
3
  export interface OptionProps extends Omit<React.InputHTMLAttributes<HTMLLIElement>, "value" | "onSelect" | "onClick">, TagProps {
4
4
  /**
5
5
  * Unique identifier for the component.
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
9
10
  var _option = _interopRequireDefault(require("./option.style"));
10
11
  var _selectListContext = _interopRequireDefault(require("../__internal__/select-list-context"));
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -27,6 +28,7 @@ const Option = /*#__PURE__*/_react.default.forwardRef(({
27
28
  }, ref) => {
28
29
  const selectListContext = (0, _react.useContext)(_selectListContext.default);
29
30
  let isSelected = selectListContext.currentOptionsListIndex === index;
31
+ const internalIdRef = (0, _react.useRef)(id || (0, _guid.default)());
30
32
  if (selectListContext.multiselectValues) {
31
33
  isSelected = selectListContext.multiselectValues.includes(value);
32
34
  }
@@ -38,7 +40,7 @@ const Option = /*#__PURE__*/_react.default.forwardRef(({
38
40
  onSelect?.({
39
41
  text,
40
42
  value,
41
- id
43
+ id: internalIdRef.current
42
44
  });
43
45
  } else {
44
46
  onSelect?.();
@@ -46,7 +48,7 @@ const Option = /*#__PURE__*/_react.default.forwardRef(({
46
48
  }
47
49
  }
48
50
  return /*#__PURE__*/_react.default.createElement(_option.default, _extends({
49
- id: id,
51
+ id: internalIdRef.current,
50
52
  ref: ref,
51
53
  "aria-selected": isSelected,
52
54
  "aria-disabled": disabled,
@@ -4,20 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
9
10
  var _optionGroupHeader = _interopRequireDefault(require("./option-group-header.style"));
10
11
  var _icon = _interopRequireDefault(require("../../icon"));
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
15
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
13
16
  const OptionGroupHeader = /*#__PURE__*/_react.default.forwardRef(({
14
17
  label,
15
18
  icon,
16
19
  style,
20
+ id,
17
21
  ...rest
18
22
  }, ref) => {
23
+ const internalIdRef = (0, _react.useRef)(id || (0, _guid.default)());
19
24
  return /*#__PURE__*/_react.default.createElement(_optionGroupHeader.default, _extends({
20
- style: style
25
+ style: style,
26
+ id: internalIdRef.current
21
27
  }, rest, {
22
28
  ref: ref
23
29
  }), icon && /*#__PURE__*/_react.default.createElement(_icon.default, {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
9
10
  var _optionRow = _interopRequireDefault(require("./option-row.style"));
10
11
  var _selectListContext = _interopRequireDefault(require("../__internal__/select-list-context"));
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -24,14 +25,15 @@ const OptionRow = /*#__PURE__*/_react.default.forwardRef(({
24
25
  style,
25
26
  ...rest
26
27
  }, ref) => {
28
+ const internalIdRef = (0, _react.useRef)(id || (0, _guid.default)());
27
29
  const handleClick = () => {
28
30
  if (disabled) {
29
31
  return;
30
32
  }
31
33
  onSelect?.({
32
- id,
33
34
  text,
34
- value
35
+ value,
36
+ id: internalIdRef.current
35
37
  });
36
38
  };
37
39
  const selectListContext = (0, _react.useContext)(_selectListContext.default);
@@ -40,7 +42,7 @@ const OptionRow = /*#__PURE__*/_react.default.forwardRef(({
40
42
  isSelected = selectListContext.multiselectValues.includes(value);
41
43
  }
42
44
  return /*#__PURE__*/_react.default.createElement(_optionRow.default, _extends({
43
- id: id,
45
+ id: internalIdRef.current,
44
46
  ref: ref,
45
47
  "aria-selected": isSelected,
46
48
  "aria-disabled": disabled,
@@ -22,7 +22,6 @@ var _listActionButton = _interopRequireDefault(require("../list-action-button"))
22
22
  var _selectListContainer = _interopRequireDefault(require("./select-list-container.style"));
23
23
  var _loader = _interopRequireDefault(require("../../loader"));
24
24
  var _option = _interopRequireDefault(require("../option"));
25
- var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
26
25
  var _selectListContext = _interopRequireDefault(require("../__internal__/select-list-context"));
27
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
27
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -101,16 +100,23 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
101
100
  rangeExtractor
102
101
  });
103
102
  const items = virtualizer.getVirtualItems();
103
+ const childrenList = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
104
+ const getIndexOfMatch = (0, _react.useCallback)(valueToMatch => {
105
+ return childrenList.findIndex(child => /*#__PURE__*/_react.default.isValidElement(child) && child.props.value === valueToMatch);
106
+ }, [childrenList]);
104
107
 
105
108
  // getVirtualItems returns an empty array of items if the select list is currently closed - which is correct visually but
106
109
  // we need to ensure that any currently-selected option is still in the DOM to avoid any accessibility issues.
107
110
  // The isOpen prop will ensure that no options are visible regardless of what is in the items array.
108
- if (items.length === 0 && currentOptionsListIndex !== -1) {
109
- // only index property is required with the item not visible so the following type assertion, even though incorrect,
110
- // should be OK
111
- items.push({
112
- index: currentOptionsListIndex
113
- });
111
+ if (items.length === 0) {
112
+ const currentIndex = highlightedValue ? getIndexOfMatch(highlightedValue) : currentOptionsListIndex;
113
+ if (currentIndex > -1) {
114
+ // only index property is required with the item not visible so the following type assertion, even though incorrect,
115
+ // should be OK
116
+ items.push({
117
+ index: currentIndex
118
+ });
119
+ }
114
120
  }
115
121
  const listHeight = virtualizer.getTotalSize();
116
122
  (0, _react.useEffect)(() => {
@@ -138,18 +144,9 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
138
144
  selectionConfirmed: true
139
145
  });
140
146
  }, [onSelect]);
141
- const childIdsRef = (0, _react.useRef)(null);
142
-
143
- // childIds should be stable except when children are added or removed - can't use useMemo
144
- // as that isn't absolutely guaranteed to never rerun when dependencies haven't changed.
145
- const setChildIds = () => {
146
- childIdsRef.current = _react.default.Children.map(children, child => /*#__PURE__*/_react.default.isValidElement(child) && child?.props.id || (0, _guid.default)()) || /* istanbul ignore next */null;
147
- };
148
- if (childIdsRef.current?.length !== _react.default.Children.count(children)) {
149
- setChildIds();
150
- }
151
- const childIds = childIdsRef.current;
152
- const childrenList = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
147
+ const childElementRefs = (0, _react.useRef)(Array.from({
148
+ length: _react.default.Children.count(children)
149
+ }));
153
150
  const optionChildrenList = (0, _react.useMemo)(() => childrenList.filter(child => /*#__PURE__*/_react.default.isValidElement(child) && (child.type === _option.default || child.type === _optionRow.default)), [childrenList]);
154
151
  const {
155
152
  measureElement
@@ -175,7 +172,6 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
175
172
  const isOption = optionChildIndex > -1;
176
173
  const newProps = {
177
174
  index,
178
- id: childIds ? childIds[index] : /* istanbul ignore next */undefined,
179
175
  onSelect: handleSelect,
180
176
  hidden: isLoading && childrenList.length === 1,
181
177
  // these need to be inline styles rather than implemented in styled-components to avoid it generating thousands of classes
@@ -184,8 +180,12 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
184
180
  },
185
181
  "aria-setsize": isOption ? optionChildrenList.length : undefined,
186
182
  "aria-posinset": isOption ? optionChildIndex + 1 : undefined,
187
- // needed to dynamically compute the size
188
- ref: measureCallback,
183
+ ref: optionElement => {
184
+ // needed to dynamically compute the size
185
+ measureCallback(optionElement);
186
+ // add the DOM element to the array of refs
187
+ childElementRefs.current[index] = optionElement;
188
+ },
189
189
  "data-index": index
190
190
  };
191
191
  return /*#__PURE__*/_react.default.cloneElement(child, newProps);
@@ -203,9 +203,6 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
203
203
  }
204
204
  return nextIndex;
205
205
  }, [childrenList, lastOptionIndex, isLoading]);
206
- const getIndexOfMatch = (0, _react.useCallback)(valueToMatch => {
207
- return childrenList.findIndex(child => /*#__PURE__*/_react.default.isValidElement(child) && child.props.value === valueToMatch);
208
- }, [childrenList]);
209
206
  const highlightNextItem = (0, _react.useCallback)(key => {
210
207
  let currentIndex = currentOptionsListIndex;
211
208
  if (highlightedValue) {
@@ -224,10 +221,10 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
224
221
  text,
225
222
  value,
226
223
  selectionType: "navigationKey",
227
- id: childIds ? childIds[nextIndex] : /* istanbul ignore next */undefined,
224
+ id: childElementRefs.current[nextIndex]?.id,
228
225
  selectionConfirmed: false
229
226
  });
230
- }, [childrenList, currentOptionsListIndex, getIndexOfMatch, getNextHighlightableItemIndex, highlightedValue, onSelect, childIds]);
227
+ }, [childrenList, currentOptionsListIndex, getIndexOfMatch, getNextHighlightableItemIndex, highlightedValue, onSelect]);
231
228
  const handleActionButtonTab = (0, _react.useCallback)((event, isActionButtonFocused) => {
232
229
  if (isActionButtonFocused) {
233
230
  onSelect({
@@ -271,7 +268,7 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
271
268
  value
272
269
  } = currentOption.props;
273
270
  onSelect({
274
- id: childIds ? childIds[currentOptionsListIndex] : /* istanbul ignore next */undefined,
271
+ id: childElementRefs.current[currentOptionsListIndex]?.id,
275
272
  text,
276
273
  value,
277
274
  selectionType: "enterKey",
@@ -281,7 +278,7 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
281
278
  focusOnAnchor();
282
279
  highlightNextItem(key);
283
280
  }
284
- }, [childrenList, listActionButton, handleActionButtonTab, onSelectListClose, currentOptionsListIndex, onSelect, highlightNextItem, focusOnAnchor, isOpen, childIds]);
281
+ }, [childrenList, listActionButton, handleActionButtonTab, onSelectListClose, currentOptionsListIndex, onSelect, highlightNextItem, focusOnAnchor, isOpen]);
285
282
  const handleEscapeKey = (0, _react.useCallback)(event => {
286
283
  if (event.key === "Escape") {
287
284
  onSelectListClose();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "125.11.0",
3
+ "version": "125.11.1",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",