carbon-react 114.17.1 → 114.17.3

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.
@@ -1,4 +1,4 @@
1
- import { ButtonTypes } from "./button.component";
1
+ import { ButtonTypes, ButtonIconPosition, SizeOptions } from "./button.component";
2
2
  export declare const BUTTON_VARIANTS: ButtonTypes[];
3
- export declare const BUTTON_SIZES: string[];
4
- export declare const BUTTON_ICON_POSITIONS: string[];
3
+ export declare const BUTTON_SIZES: SizeOptions[];
4
+ export declare const BUTTON_ICON_POSITIONS: ButtonIconPosition[];
@@ -103,7 +103,7 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
103
103
  }, [openSubmenuId, closeSubmenu]);
104
104
  const findCurrentIndex = useCallback(id => {
105
105
  const index = submenuItemIds.findIndex(itemId => itemId === id);
106
- return index === -1 ? 0 : index;
106
+ return index;
107
107
  }, [submenuItemIds]);
108
108
  const handleKeyDown = useCallback(event => {
109
109
  if (!submenuOpen) {
@@ -137,7 +137,7 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
137
137
  }
138
138
 
139
139
  if (Events.isTabKey(event) && Events.isShiftKey(event)) {
140
- if (nextIndex === 0) {
140
+ if (nextIndex <= 0) {
141
141
  closeSubmenu();
142
142
  return;
143
143
  }
@@ -371,11 +371,10 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
371
371
  return [...previousValue, newValue];
372
372
  });
373
373
  }, [textboxRef, actualValue, updateValue]);
374
-
375
- function onSelectListClose() {
374
+ const onSelectListClose = useCallback(() => {
376
375
  setOpenState(false);
377
376
  setFilterText("");
378
- }
377
+ }, []);
379
378
 
380
379
  function findElementWithMatchingText(textToMatch, list) {
381
380
  return list.find(child => {
@@ -6,6 +6,7 @@ import { flip, offset, size } from "@floating-ui/dom";
6
6
  import { useVirtualizer } from "@tanstack/react-virtual";
7
7
  import findLastIndex from "lodash/findLastIndex";
8
8
  import useScrollBlock from "../../../hooks/__internal__/useScrollBlock";
9
+ import useModalManager from "../../../hooks/__internal__/useModalManager";
9
10
  import { StyledSelectList, StyledSelectLoaderContainer, StyledSelectListTable, StyledSelectListTableHeader, StyledSelectListTableBody } from "./select-list.style";
10
11
  import Popover from "../../../__internal__/popover";
11
12
  import OptionRow from "../option-row/option-row.component";
@@ -220,7 +221,7 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
220
221
 
221
222
  if (key === "Tab" && listActionButton) {
222
223
  handleActionButtonTab(event, isActionButtonFocused);
223
- } else if (key === "Tab" || key === "Escape") {
224
+ } else if (key === "Tab") {
224
225
  onSelectListClose();
225
226
  } else if (key === "Enter" && !isActionButtonFocused) {
226
227
  event.preventDefault();
@@ -246,6 +247,12 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
246
247
  highlightNextItem(key);
247
248
  }
248
249
  }, [childrenList, listActionButton, handleActionButtonTab, onSelectListClose, currentOptionsListIndex, onSelect, highlightNextItem, focusOnAnchor, isOpen, childIds]);
250
+ const handleEscapeKey = useCallback(event => {
251
+ if (event.key === "Escape") {
252
+ onSelectListClose();
253
+ }
254
+ }, [onSelectListClose]);
255
+ useModalManager(isOpen, handleEscapeKey, listRef);
249
256
  const handleListScroll = useCallback(event => {
250
257
  const element = event.target;
251
258
  /* istanbul ignore else */
@@ -294,10 +294,9 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
294
294
  }
295
295
  }
296
296
 
297
- function onSelectListClose() {
297
+ const onSelectListClose = useCallback(() => {
298
298
  setOpenState(false);
299
- }
300
-
299
+ }, []);
301
300
  const assignInput = useCallback(element => {
302
301
  setTextboxRef(element);
303
302
 
@@ -1,4 +1,4 @@
1
- import { ButtonTypes } from "./button.component";
1
+ import { ButtonTypes, ButtonIconPosition, SizeOptions } from "./button.component";
2
2
  export declare const BUTTON_VARIANTS: ButtonTypes[];
3
- export declare const BUTTON_SIZES: string[];
4
- export declare const BUTTON_ICON_POSITIONS: string[];
3
+ export declare const BUTTON_SIZES: SizeOptions[];
4
+ export declare const BUTTON_ICON_POSITIONS: ButtonIconPosition[];
@@ -128,7 +128,7 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
128
128
  }, [openSubmenuId, closeSubmenu]);
129
129
  const findCurrentIndex = (0, _react.useCallback)(id => {
130
130
  const index = submenuItemIds.findIndex(itemId => itemId === id);
131
- return index === -1 ? 0 : index;
131
+ return index;
132
132
  }, [submenuItemIds]);
133
133
  const handleKeyDown = (0, _react.useCallback)(event => {
134
134
  if (!submenuOpen) {
@@ -162,7 +162,7 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
162
162
  }
163
163
 
164
164
  if (_events.default.isTabKey(event) && _events.default.isShiftKey(event)) {
165
- if (nextIndex === 0) {
165
+ if (nextIndex <= 0) {
166
166
  closeSubmenu();
167
167
  return;
168
168
  }
@@ -402,11 +402,10 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
402
402
  return [...previousValue, newValue];
403
403
  });
404
404
  }, [textboxRef, actualValue, updateValue]);
405
-
406
- function onSelectListClose() {
405
+ const onSelectListClose = (0, _react.useCallback)(() => {
407
406
  setOpenState(false);
408
407
  setFilterText("");
409
- }
408
+ }, []);
410
409
 
411
410
  function findElementWithMatchingText(textToMatch, list) {
412
411
  return list.find(child => {
@@ -17,6 +17,8 @@ var _findLastIndex = _interopRequireDefault(require("lodash/findLastIndex"));
17
17
 
18
18
  var _useScrollBlock = _interopRequireDefault(require("../../../hooks/__internal__/useScrollBlock"));
19
19
 
20
+ var _useModalManager = _interopRequireDefault(require("../../../hooks/__internal__/useModalManager"));
21
+
20
22
  var _selectList = require("./select-list.style");
21
23
 
22
24
  var _popover = _interopRequireDefault(require("../../../__internal__/popover"));
@@ -252,7 +254,7 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
252
254
 
253
255
  if (key === "Tab" && listActionButton) {
254
256
  handleActionButtonTab(event, isActionButtonFocused);
255
- } else if (key === "Tab" || key === "Escape") {
257
+ } else if (key === "Tab") {
256
258
  onSelectListClose();
257
259
  } else if (key === "Enter" && !isActionButtonFocused) {
258
260
  event.preventDefault();
@@ -278,6 +280,12 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
278
280
  highlightNextItem(key);
279
281
  }
280
282
  }, [childrenList, listActionButton, handleActionButtonTab, onSelectListClose, currentOptionsListIndex, onSelect, highlightNextItem, focusOnAnchor, isOpen, childIds]);
283
+ const handleEscapeKey = (0, _react.useCallback)(event => {
284
+ if (event.key === "Escape") {
285
+ onSelectListClose();
286
+ }
287
+ }, [onSelectListClose]);
288
+ (0, _useModalManager.default)(isOpen, handleEscapeKey, listRef);
281
289
  const handleListScroll = (0, _react.useCallback)(event => {
282
290
  const element = event.target;
283
291
  /* istanbul ignore else */
@@ -322,10 +322,9 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
322
322
  }
323
323
  }
324
324
 
325
- function onSelectListClose() {
325
+ const onSelectListClose = (0, _react.useCallback)(() => {
326
326
  setOpenState(false);
327
- }
328
-
327
+ }, []);
329
328
  const assignInput = (0, _react.useCallback)(element => {
330
329
  setTextboxRef(element);
331
330
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "114.17.1",
3
+ "version": "114.17.3",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",
@@ -104,7 +104,7 @@
104
104
  "babel-eslint": "10.0.3",
105
105
  "babel-jest": "^26.6.3",
106
106
  "babel-plugin-dev-expression": "^0.2.3",
107
- "browserslist": "^4.16.6",
107
+ "browserslist": "^4.21.5",
108
108
  "chromatic": "^6.0.5",
109
109
  "commitizen": "^4.2.5",
110
110
  "conventional-changelog-conventionalcommits": "^4.5.0",