carbon-react 114.17.0 → 114.17.2
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/esm/components/menu/__internal__/submenu/submenu.component.js +5 -2
- package/esm/components/menu/menu-item/menu-item.component.js +3 -2
- package/esm/components/select/multi-select/multi-select.component.js +2 -3
- package/esm/components/select/select-list/select-list.component.js +8 -1
- package/esm/components/select/simple-select/simple-select.component.js +2 -3
- package/lib/components/menu/__internal__/submenu/submenu.component.js +5 -2
- package/lib/components/menu/menu-item/menu-item.component.js +3 -2
- package/lib/components/select/multi-select/multi-select.component.js +2 -3
- package/lib/components/select/select-list/select-list.component.js +9 -1
- package/lib/components/select/simple-select/simple-select.component.js +2 -3
- package/package.json +2 -2
|
@@ -43,6 +43,7 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
43
43
|
const [submenuItemIds, setSubmenuItemIds] = useState([]);
|
|
44
44
|
const [characterString, setCharacterString] = useState("");
|
|
45
45
|
const shiftTabPressed = useRef(false);
|
|
46
|
+
const focusFirstMenuItemOnOpen = useRef(false);
|
|
46
47
|
const registerItem = useCallback(id => {
|
|
47
48
|
setSubmenuItemIds(prevState => {
|
|
48
49
|
return [...prevState, id];
|
|
@@ -109,6 +110,7 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
109
110
|
if (Events.isEnterKey(event) || Events.isSpaceKey(event) || Events.isDownKey(event) || Events.isUpKey(event)) {
|
|
110
111
|
event.preventDefault();
|
|
111
112
|
openSubmenu();
|
|
113
|
+
focusFirstMenuItemOnOpen.current = !href;
|
|
112
114
|
}
|
|
113
115
|
}
|
|
114
116
|
|
|
@@ -212,10 +214,11 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
212
214
|
}
|
|
213
215
|
}, [submenuItemIds, submenuOpen, href, numberOfChildren, submenuFocusId, findCurrentIndex, openSubmenu, closeSubmenu, onKeyDown, characterString, restartCharacterTimeout, startCharacterTimeout]);
|
|
214
216
|
useEffect(() => {
|
|
215
|
-
if (
|
|
217
|
+
if (focusFirstMenuItemOnOpen.current && submenuOpen && !submenuFocusId && submenuItemIds.length) {
|
|
218
|
+
focusFirstMenuItemOnOpen.current = false;
|
|
216
219
|
setSubmenuFocusId(submenuItemIds[0]);
|
|
217
220
|
}
|
|
218
|
-
}, [submenuOpen,
|
|
221
|
+
}, [submenuOpen, submenuFocusId, submenuItemIds]);
|
|
219
222
|
|
|
220
223
|
const handleClickAway = () => {
|
|
221
224
|
document.removeEventListener("click", handleClickAway);
|
|
@@ -123,7 +123,7 @@ const MenuItem = ({
|
|
|
123
123
|
href,
|
|
124
124
|
target,
|
|
125
125
|
rel,
|
|
126
|
-
onClick
|
|
126
|
+
onClick,
|
|
127
127
|
icon,
|
|
128
128
|
selected,
|
|
129
129
|
variant,
|
|
@@ -172,7 +172,8 @@ const MenuItem = ({
|
|
|
172
172
|
}, rest, {
|
|
173
173
|
inFullscreenView: inFullscreenView && !Object.keys(submenuContext).length,
|
|
174
174
|
menuOpen: menuOpen,
|
|
175
|
-
id: menuItemId.current
|
|
175
|
+
id: menuItemId.current,
|
|
176
|
+
onClick: updateFocusOnClick
|
|
176
177
|
}), /*#__PURE__*/React.createElement(StyledMenuItemWrapper, _extends({
|
|
177
178
|
as: inputRef.current ? "div" : Link,
|
|
178
179
|
isSearch: inputRef.current,
|
|
@@ -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"
|
|
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
|
-
|
|
297
|
+
const onSelectListClose = useCallback(() => {
|
|
298
298
|
setOpenState(false);
|
|
299
|
-
}
|
|
300
|
-
|
|
299
|
+
}, []);
|
|
301
300
|
const assignInput = useCallback(element => {
|
|
302
301
|
setTextboxRef(element);
|
|
303
302
|
|
|
@@ -68,6 +68,7 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
68
68
|
const [submenuItemIds, setSubmenuItemIds] = (0, _react.useState)([]);
|
|
69
69
|
const [characterString, setCharacterString] = (0, _react.useState)("");
|
|
70
70
|
const shiftTabPressed = (0, _react.useRef)(false);
|
|
71
|
+
const focusFirstMenuItemOnOpen = (0, _react.useRef)(false);
|
|
71
72
|
const registerItem = (0, _react.useCallback)(id => {
|
|
72
73
|
setSubmenuItemIds(prevState => {
|
|
73
74
|
return [...prevState, id];
|
|
@@ -134,6 +135,7 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
134
135
|
if (_events.default.isEnterKey(event) || _events.default.isSpaceKey(event) || _events.default.isDownKey(event) || _events.default.isUpKey(event)) {
|
|
135
136
|
event.preventDefault();
|
|
136
137
|
openSubmenu();
|
|
138
|
+
focusFirstMenuItemOnOpen.current = !href;
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -237,10 +239,11 @@ const Submenu = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
237
239
|
}
|
|
238
240
|
}, [submenuItemIds, submenuOpen, href, numberOfChildren, submenuFocusId, findCurrentIndex, openSubmenu, closeSubmenu, onKeyDown, characterString, restartCharacterTimeout, startCharacterTimeout]);
|
|
239
241
|
(0, _react.useEffect)(() => {
|
|
240
|
-
if (
|
|
242
|
+
if (focusFirstMenuItemOnOpen.current && submenuOpen && !submenuFocusId && submenuItemIds.length) {
|
|
243
|
+
focusFirstMenuItemOnOpen.current = false;
|
|
241
244
|
setSubmenuFocusId(submenuItemIds[0]);
|
|
242
245
|
}
|
|
243
|
-
}, [submenuOpen,
|
|
246
|
+
}, [submenuOpen, submenuFocusId, submenuItemIds]);
|
|
244
247
|
|
|
245
248
|
const handleClickAway = () => {
|
|
246
249
|
document.removeEventListener("click", handleClickAway);
|
|
@@ -147,7 +147,7 @@ const MenuItem = ({
|
|
|
147
147
|
href,
|
|
148
148
|
target,
|
|
149
149
|
rel,
|
|
150
|
-
onClick
|
|
150
|
+
onClick,
|
|
151
151
|
icon,
|
|
152
152
|
selected,
|
|
153
153
|
variant,
|
|
@@ -196,7 +196,8 @@ const MenuItem = ({
|
|
|
196
196
|
}, rest, {
|
|
197
197
|
inFullscreenView: inFullscreenView && !Object.keys(submenuContext).length,
|
|
198
198
|
menuOpen: menuOpen,
|
|
199
|
-
id: menuItemId.current
|
|
199
|
+
id: menuItemId.current,
|
|
200
|
+
onClick: updateFocusOnClick
|
|
200
201
|
}), /*#__PURE__*/_react.default.createElement(_menuItem.default, _extends({
|
|
201
202
|
as: inputRef.current ? "div" : _link.default,
|
|
202
203
|
isSearch: inputRef.current,
|
|
@@ -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"
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "114.17.2",
|
|
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.
|
|
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",
|