carbon-react 114.13.1 → 114.14.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.
- package/esm/__internal__/input-icon-toggle/input-icon-toggle.component.js +2 -1
- package/esm/components/link/link.component.d.ts +2 -0
- package/esm/components/link/link.component.js +7 -1
- package/esm/components/menu/__internal__/keyboard-navigation/index.d.ts +4 -2
- package/esm/components/menu/__internal__/keyboard-navigation/index.js +16 -15
- package/esm/components/menu/__internal__/locators.d.ts +6 -0
- package/esm/components/menu/__internal__/locators.js +6 -0
- package/esm/components/menu/__internal__/submenu/submenu.component.js +109 -108
- package/esm/components/menu/menu-full-screen/menu-full-screen.component.js +1 -2
- package/esm/components/menu/menu-item/index.js +0 -1
- package/esm/components/menu/menu-item/menu-item.component.js +77 -51
- package/esm/components/menu/menu-item/menu-item.d.ts +7 -3
- package/esm/components/menu/menu.component.js +33 -37
- package/esm/components/menu/menu.context.d.ts +2 -2
- package/esm/components/menu/menu.context.js +2 -2
- package/esm/components/menu/scrollable-block/scrollable-block.component.js +6 -24
- package/esm/components/select/filterable-select/filterable-select.component.js +15 -2
- package/esm/components/select/filterable-select/filterable-select.d.ts +7 -0
- package/esm/components/select/list-action-button/list-action-button.style.js +4 -1
- package/esm/components/select/multi-select/multi-select.component.js +15 -2
- package/esm/components/select/multi-select/multi-select.d.ts +7 -0
- package/esm/components/select/option/option.component.js +16 -5
- package/esm/components/select/option/option.style.js +4 -0
- package/esm/components/select/option-group-header/option-group-header.component.js +20 -8
- package/esm/components/select/option-group-header/option-group-header.style.js +3 -2
- package/esm/components/select/option-row/option-row.component.js +16 -5
- package/esm/components/select/option-row/option-row.style.js +4 -0
- package/esm/components/select/select-list/select-list-container.style.js +11 -1
- package/esm/components/select/select-list/select-list.component.js +136 -62
- package/esm/components/select/select-list/select-list.style.js +15 -18
- package/esm/components/select/simple-select/simple-select.component.js +15 -2
- package/esm/components/select/simple-select/simple-select.d.ts +7 -0
- package/lib/__internal__/input-icon-toggle/input-icon-toggle.component.js +2 -1
- package/lib/components/link/link.component.d.ts +2 -0
- package/lib/components/link/link.component.js +7 -1
- package/lib/components/menu/__internal__/keyboard-navigation/index.d.ts +4 -2
- package/lib/components/menu/__internal__/keyboard-navigation/index.js +16 -15
- package/lib/components/menu/__internal__/locators.d.ts +6 -0
- package/lib/components/menu/__internal__/locators.js +18 -0
- package/lib/components/menu/__internal__/submenu/submenu.component.js +111 -113
- package/lib/components/menu/menu-full-screen/menu-full-screen.component.js +1 -2
- package/lib/components/menu/menu-item/menu-item.component.js +76 -52
- package/lib/components/menu/menu-item/menu-item.d.ts +7 -3
- package/lib/components/menu/menu.component.js +33 -37
- package/lib/components/menu/menu.context.d.ts +2 -2
- package/lib/components/menu/menu.context.js +2 -2
- package/lib/components/menu/scrollable-block/scrollable-block.component.js +6 -25
- package/lib/components/select/filterable-select/filterable-select.component.js +15 -2
- package/lib/components/select/filterable-select/filterable-select.d.ts +7 -0
- package/lib/components/select/list-action-button/list-action-button.style.js +4 -1
- package/lib/components/select/multi-select/multi-select.component.js +15 -2
- package/lib/components/select/multi-select/multi-select.d.ts +7 -0
- package/lib/components/select/option/option.component.js +16 -5
- package/lib/components/select/option/option.style.js +4 -0
- package/lib/components/select/option-group-header/option-group-header.component.js +20 -6
- package/lib/components/select/option-group-header/option-group-header.style.js +3 -2
- package/lib/components/select/option-row/option-row.component.js +16 -5
- package/lib/components/select/option-row/option-row.style.js +4 -0
- package/lib/components/select/select-list/select-list-container.style.js +11 -1
- package/lib/components/select/select-list/select-list.component.js +139 -63
- package/lib/components/select/select-list/select-list.style.js +15 -18
- package/lib/components/select/simple-select/simple-select.component.js +15 -2
- package/lib/components/select/simple-select/simple-select.d.ts +7 -0
- package/package.json +2 -1
- package/esm/components/select/select-list/update-list-scroll.js +0 -21
- package/lib/components/select/select-list/update-list-scroll.js +0 -28
|
@@ -26,6 +26,8 @@ export interface LinkProps extends StyledLinkProps, React.AriaAttributes {
|
|
|
26
26
|
ariaLabel?: string;
|
|
27
27
|
/** allows to set rel property in <a> tag */
|
|
28
28
|
rel?: string;
|
|
29
|
+
/** @ignore @private internal prop to be set when no href or onClick passed */
|
|
30
|
+
placeholderTabIndex?: boolean;
|
|
29
31
|
}
|
|
30
32
|
export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLButtonElement | HTMLLinkElement>>;
|
|
31
33
|
export default Link;
|
|
@@ -25,6 +25,7 @@ const Link = /*#__PURE__*/React.forwardRef(({
|
|
|
25
25
|
target,
|
|
26
26
|
variant = "default",
|
|
27
27
|
isDarkBackground,
|
|
28
|
+
placeholderTabIndex,
|
|
28
29
|
...rest
|
|
29
30
|
}, ref) => {
|
|
30
31
|
const l = useLocale();
|
|
@@ -84,7 +85,11 @@ const Link = /*#__PURE__*/React.forwardRef(({
|
|
|
84
85
|
type = "button";
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
return /*#__PURE__*/React.createElement(type, componentProps,
|
|
88
|
+
return /*#__PURE__*/React.createElement(type, { ...componentProps,
|
|
89
|
+
...(placeholderTabIndex && href === undefined && !onClick && {
|
|
90
|
+
tabIndex: -1
|
|
91
|
+
})
|
|
92
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, renderLinkIcon(), /*#__PURE__*/React.createElement(StyledContent, null, isSkipLink ? l.link.skipLinkLabel() : children), renderLinkIcon("right")));
|
|
88
93
|
};
|
|
89
94
|
|
|
90
95
|
return /*#__PURE__*/React.createElement(StyledLink, _extends({
|
|
@@ -160,6 +165,7 @@ Link.propTypes = {
|
|
|
160
165
|
"onClick": PropTypes.func,
|
|
161
166
|
"onKeyDown": PropTypes.func,
|
|
162
167
|
"onMouseDown": PropTypes.func,
|
|
168
|
+
"placeholderTabIndex": PropTypes.bool,
|
|
163
169
|
"rel": PropTypes.string,
|
|
164
170
|
"target": PropTypes.string,
|
|
165
171
|
"tooltipMessage": PropTypes.string,
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare function characterNavigation(inputString?: string, focusableItems?: Element[]): Element | undefined;
|
|
3
|
+
declare function menuKeyboardNavigation(event: React.KeyboardEvent, focusableItems: Element[]): number | undefined;
|
|
4
|
+
export { characterNavigation, menuKeyboardNavigation };
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import Events from "../../../../__internal__/utils/helpers/events";
|
|
2
|
-
import
|
|
2
|
+
import { MENU_ITEM, SCROLLABLE_BLOCK_PARENT } from "../locators";
|
|
3
3
|
|
|
4
|
-
function characterNavigation(inputString, focusableItems
|
|
5
|
-
if (!inputString) return
|
|
4
|
+
function characterNavigation(inputString, focusableItems) {
|
|
5
|
+
if (!inputString || !focusableItems) return undefined;
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
7
|
+
const getInnerText = element => {
|
|
8
|
+
var _element$textContent, _element$textContent$;
|
|
9
|
+
|
|
10
|
+
return element === null || element === void 0 ? void 0 : (_element$textContent = element.textContent) === null || _element$textContent === void 0 ? void 0 : (_element$textContent$ = _element$textContent.split("\n")) === null || _element$textContent$ === void 0 ? void 0 : _element$textContent$.map(text => text.trim()).join(" ");
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
const getMenuText = element => {
|
|
14
|
-
|
|
15
|
-
return element.submenu;
|
|
16
|
-
}
|
|
14
|
+
var _getInnerText;
|
|
17
15
|
|
|
18
|
-
return
|
|
16
|
+
return (_getInnerText = getInnerText(element)) === null || _getInnerText === void 0 ? void 0 : _getInnerText.toLowerCase();
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const matchingItem = focusableItems.find(item => {
|
|
20
|
+
var _getMenuText;
|
|
21
|
+
|
|
22
|
+
if (!(item !== null && item !== void 0 && item.getAttribute("data-component"))) return false;
|
|
23
|
+
return [MENU_ITEM, SCROLLABLE_BLOCK_PARENT].includes(item.getAttribute("data-component")) && ((_getMenuText = getMenuText(item)) === null || _getMenuText === void 0 ? void 0 : _getMenuText.startsWith(inputString.toLowerCase()));
|
|
24
|
+
});
|
|
25
|
+
return matchingItem;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function menuKeyboardNavigation(event, focusableItems) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const MENU_ITEM: "menu-item";
|
|
2
|
+
export const SCROLLABLE_BLOCK: "submenu-scrollable-block";
|
|
3
|
+
export const SCROLLABLE_BLOCK_PARENT: "scrollable-block-parent";
|
|
4
|
+
export const ALL_CHILDREN_SELECTOR: string;
|
|
5
|
+
export const BLOCK_INDEX_SELECTOR: string;
|
|
6
|
+
export const MENU_ITEM_CHILDREN_LOCATOR: string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const MENU_ITEM = "menu-item";
|
|
2
|
+
export const SCROLLABLE_BLOCK = "submenu-scrollable-block";
|
|
3
|
+
export const SCROLLABLE_BLOCK_PARENT = "scrollable-block-parent";
|
|
4
|
+
export const ALL_CHILDREN_SELECTOR = `[data-component='${MENU_ITEM}'], [data-component='${SCROLLABLE_BLOCK_PARENT}']`;
|
|
5
|
+
export const BLOCK_INDEX_SELECTOR = `[data-component='${MENU_ITEM}'], [data-component='${SCROLLABLE_BLOCK}']`;
|
|
6
|
+
export const MENU_ITEM_CHILDREN_LOCATOR = `[data-component='${MENU_ITEM}']`;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || 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
2
|
|
|
3
|
-
/* eslint-disable jsx-a11y/mouse-events-have-key-events */
|
|
4
3
|
import React, { useCallback, useEffect, useContext, useMemo, useRef, useState } from "react";
|
|
5
4
|
import PropTypes from "prop-types";
|
|
6
5
|
import StyledMenuItemWrapper from "../../menu-item/menu-item.style";
|
|
@@ -8,11 +7,11 @@ import { StyledSubmenu, StyledSubmenuWrapper } from "./submenu.style";
|
|
|
8
7
|
import Link from "../../../link";
|
|
9
8
|
import Events from "../../../../__internal__/utils/helpers/events";
|
|
10
9
|
import MenuContext from "../../menu.context";
|
|
11
|
-
import MenuItem from "../../menu-item";
|
|
12
10
|
import { characterNavigation } from "../keyboard-navigation";
|
|
13
|
-
import ScrollableBlock from "../../scrollable-block";
|
|
14
11
|
import SubmenuContext from "./submenu.context";
|
|
15
12
|
import useClickAwayListener from "../../../../hooks/__internal__/useClickAwayListener";
|
|
13
|
+
import guid from "../../../../__internal__/utils/helpers/guid";
|
|
14
|
+
import { SCROLLABLE_BLOCK, SCROLLABLE_BLOCK_PARENT, BLOCK_INDEX_SELECTOR, ALL_CHILDREN_SELECTOR } from "../locators";
|
|
16
15
|
const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
17
16
|
children,
|
|
18
17
|
className,
|
|
@@ -29,46 +28,44 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
29
28
|
onSubmenuOpen,
|
|
30
29
|
onSubmenuClose,
|
|
31
30
|
onClick,
|
|
32
|
-
indexInMenu,
|
|
33
31
|
...rest
|
|
34
32
|
}, ref) => {
|
|
35
|
-
const
|
|
33
|
+
const submenuRef = useRef(null);
|
|
34
|
+
const submenuId = useRef(guid());
|
|
36
35
|
const menuContext = useContext(MenuContext);
|
|
37
36
|
const {
|
|
38
37
|
inFullscreenView,
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
openSubmenuId,
|
|
39
|
+
setOpenSubmenuId
|
|
41
40
|
} = menuContext;
|
|
42
41
|
const [submenuOpen, setSubmenuOpen] = useState(false);
|
|
43
|
-
const [
|
|
42
|
+
const [submenuFocusId, setSubmenuFocusId] = useState(null);
|
|
43
|
+
const [submenuItemIds, setSubmenuItemIds] = useState([]);
|
|
44
44
|
const [characterString, setCharacterString] = useState("");
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
const arrayOfFormattedChildren = React.Children.toArray(formattedChildren);
|
|
59
|
-
const numberOfChildren = useMemo(() => React.Children.count(formattedChildren), [formattedChildren]);
|
|
45
|
+
const shiftTabPressed = useRef(false);
|
|
46
|
+
const registerItem = useCallback(id => {
|
|
47
|
+
setSubmenuItemIds(prevState => {
|
|
48
|
+
return [...prevState, id];
|
|
49
|
+
});
|
|
50
|
+
}, []);
|
|
51
|
+
const unregisterItem = useCallback(id => {
|
|
52
|
+
setSubmenuItemIds(prevState => {
|
|
53
|
+
return prevState.filter(itemId => itemId !== id);
|
|
54
|
+
});
|
|
55
|
+
}, []);
|
|
56
|
+
const numberOfChildren = submenuItemIds.length;
|
|
60
57
|
const blockIndex = useMemo(() => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const childrenArray = React.Children.toArray(children);
|
|
64
|
-
let index = childrenArray.findIndex(item => item.type === ScrollableBlock);
|
|
58
|
+
if (submenuOpen && numberOfChildren) {
|
|
59
|
+
var _submenuRef$current, _submenuRef$current2;
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const childrenArray = Array.from((_submenuRef$current = submenuRef.current) === null || _submenuRef$current === void 0 ? void 0 : _submenuRef$current.querySelectorAll(BLOCK_INDEX_SELECTOR));
|
|
62
|
+
const scrollableBlock = (_submenuRef$current2 = submenuRef.current) === null || _submenuRef$current2 === void 0 ? void 0 : _submenuRef$current2.querySelector(`[data-component='${SCROLLABLE_BLOCK}']`);
|
|
63
|
+
const index = childrenArray.indexOf(scrollableBlock);
|
|
64
|
+
return scrollableBlock !== null && scrollableBlock !== void 0 && scrollableBlock.querySelector(`[data-component='${SCROLLABLE_BLOCK_PARENT}']`) ? index + 1 : index;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
return
|
|
71
|
-
}, [
|
|
67
|
+
return -1;
|
|
68
|
+
}, [submenuOpen, numberOfChildren]);
|
|
72
69
|
const characterTimer = useRef();
|
|
73
70
|
const startCharacterTimeout = useCallback(() => {
|
|
74
71
|
characterTimer.current = setTimeout(() => {
|
|
@@ -81,83 +78,88 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
81
78
|
}, [startCharacterTimeout]);
|
|
82
79
|
const openSubmenu = useCallback(() => {
|
|
83
80
|
setSubmenuOpen(true);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
setOpenSubmenuId(submenuId.current);
|
|
82
|
+
|
|
83
|
+
if (onSubmenuOpen) {
|
|
84
|
+
onSubmenuOpen();
|
|
85
|
+
}
|
|
86
|
+
}, [onSubmenuOpen, setOpenSubmenuId]);
|
|
87
87
|
const closeSubmenu = useCallback(() => {
|
|
88
|
+
shiftTabPressed.current = false;
|
|
88
89
|
setSubmenuOpen(false);
|
|
90
|
+
setSubmenuFocusId(null);
|
|
89
91
|
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
+
if (onSubmenuClose) {
|
|
93
|
+
onSubmenuClose();
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
if (onSubmenuClose) onSubmenuClose();
|
|
95
|
-
setSubmenuFocusIndex(undefined);
|
|
96
|
-
setBlockDoubleFocus(false);
|
|
97
96
|
setCharacterString("");
|
|
98
|
-
}, [onSubmenuClose
|
|
97
|
+
}, [onSubmenuClose]);
|
|
99
98
|
useEffect(() => {
|
|
100
|
-
if (
|
|
99
|
+
if (openSubmenuId && openSubmenuId !== submenuId.current) {
|
|
101
100
|
closeSubmenu();
|
|
102
101
|
}
|
|
103
|
-
}, [
|
|
104
|
-
const
|
|
102
|
+
}, [openSubmenuId, closeSubmenu]);
|
|
103
|
+
const findCurrentIndex = useCallback(id => {
|
|
104
|
+
const index = submenuItemIds.findIndex(itemId => itemId === id);
|
|
105
|
+
return index === -1 ? 0 : index;
|
|
106
|
+
}, [submenuItemIds]);
|
|
107
|
+
const handleKeyDown = useCallback(event => {
|
|
105
108
|
if (!submenuOpen) {
|
|
106
109
|
if (Events.isEnterKey(event) || Events.isSpaceKey(event) || Events.isDownKey(event) || Events.isUpKey(event)) {
|
|
107
110
|
event.preventDefault();
|
|
108
111
|
openSubmenu();
|
|
109
|
-
|
|
110
|
-
if (!href) {
|
|
111
|
-
setSubmenuFocusIndex(0);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!event.defaultPrevented) {
|
|
116
|
-
menuContext.handleKeyDown(event);
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
114
|
|
|
120
115
|
if (submenuOpen) {
|
|
116
|
+
const index = findCurrentIndex(submenuFocusId);
|
|
121
117
|
let nextIndex = index;
|
|
122
118
|
|
|
119
|
+
if (href && !submenuFocusId) {
|
|
120
|
+
if (Events.isDownKey(event) || Events.isUpKey(event) || Events.isTabKey(event) && !Events.isShiftKey(event)) {
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
setSubmenuFocusId(submenuItemIds[0]);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
123
127
|
if (Events.isTabKey(event) && !Events.isShiftKey(event)) {
|
|
124
|
-
if (
|
|
128
|
+
if (nextIndex === numberOfChildren - 1) {
|
|
125
129
|
closeSubmenu();
|
|
126
130
|
return;
|
|
127
131
|
}
|
|
128
132
|
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
shiftTabPressed.current = false;
|
|
134
|
+
nextIndex += 1;
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
if (Events.isTabKey(event) && Events.isShiftKey(event)) {
|
|
134
|
-
if (
|
|
138
|
+
if (nextIndex === 0) {
|
|
135
139
|
closeSubmenu();
|
|
136
140
|
return;
|
|
137
141
|
}
|
|
138
142
|
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
shiftTabPressed.current = true;
|
|
144
|
+
nextIndex -= 1;
|
|
141
145
|
}
|
|
142
146
|
|
|
143
147
|
if (Events.isDownKey(event)) {
|
|
144
148
|
event.preventDefault();
|
|
149
|
+
shiftTabPressed.current = false;
|
|
145
150
|
|
|
146
|
-
if (
|
|
147
|
-
nextIndex
|
|
151
|
+
if (nextIndex < numberOfChildren - 1) {
|
|
152
|
+
nextIndex += 1;
|
|
148
153
|
}
|
|
149
|
-
|
|
150
|
-
setBlockDoubleFocus(false);
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
if (Events.isUpKey(event)) {
|
|
154
157
|
event.preventDefault();
|
|
158
|
+
shiftTabPressed.current = false;
|
|
155
159
|
|
|
156
|
-
if (
|
|
157
|
-
nextIndex
|
|
160
|
+
if (nextIndex > 0) {
|
|
161
|
+
nextIndex -= 1;
|
|
158
162
|
}
|
|
159
|
-
|
|
160
|
-
setBlockDoubleFocus(false);
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
if (Events.isEscKey(event)) {
|
|
@@ -168,16 +170,19 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
168
170
|
|
|
169
171
|
if (Events.isHomeKey(event)) {
|
|
170
172
|
event.preventDefault();
|
|
173
|
+
shiftTabPressed.current = false;
|
|
171
174
|
nextIndex = 0;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
if (Events.isEndKey(event)) {
|
|
175
178
|
event.preventDefault();
|
|
179
|
+
shiftTabPressed.current = false;
|
|
176
180
|
nextIndex = numberOfChildren - 1;
|
|
177
181
|
}
|
|
178
182
|
|
|
179
183
|
if (event.key.length === 1) {
|
|
180
184
|
event.stopPropagation();
|
|
185
|
+
shiftTabPressed.current = false;
|
|
181
186
|
|
|
182
187
|
if (characterTimer.current) {
|
|
183
188
|
restartCharacterTimeout();
|
|
@@ -196,31 +201,21 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
196
201
|
setTimeout(() => closeSubmenu());
|
|
197
202
|
}
|
|
198
203
|
|
|
199
|
-
if (href &&
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (Events.isSpaceKey(event) || Events.isDownKey(event) || Events.isUpKey(event) || Events.isTabKey(event)) {
|
|
206
|
-
nextIndex = 0;
|
|
207
|
-
}
|
|
208
|
-
} // Defensive check in case an unhandled key event from a child component
|
|
209
|
-
// has bubbled up
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (!nextIndex && nextIndex !== 0) return; // Check that next index contains a MenuItem
|
|
213
|
-
// If not, call handleKeyDown again
|
|
214
|
-
|
|
215
|
-
const nextChild = arrayOfFormattedChildren[nextIndex];
|
|
204
|
+
if (href && Events.isEnterKey(event)) {
|
|
205
|
+
closeSubmenu();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
216
208
|
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
} else {
|
|
220
|
-
handleKeyDown(event, nextIndex);
|
|
209
|
+
if (nextIndex !== index) {
|
|
210
|
+
setSubmenuFocusId(submenuItemIds[nextIndex]);
|
|
221
211
|
}
|
|
222
212
|
}
|
|
223
|
-
}, [
|
|
213
|
+
}, [submenuItemIds, submenuOpen, href, numberOfChildren, submenuFocusId, findCurrentIndex, openSubmenu, closeSubmenu, onKeyDown, characterString, restartCharacterTimeout, startCharacterTimeout]);
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
if (submenuOpen && !href && !submenuFocusId && submenuItemIds.length) {
|
|
216
|
+
setSubmenuFocusId(submenuItemIds[0]);
|
|
217
|
+
}
|
|
218
|
+
}, [submenuOpen, href, submenuFocusId, submenuItemIds]);
|
|
224
219
|
|
|
225
220
|
const handleClickAway = () => {
|
|
226
221
|
document.removeEventListener("click", handleClickAway);
|
|
@@ -237,11 +232,16 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
237
232
|
|
|
238
233
|
useEffect(() => {
|
|
239
234
|
if (characterString !== "") {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
235
|
+
var _submenuRef$current3;
|
|
236
|
+
|
|
237
|
+
const submenuChildren = Array.from((_submenuRef$current3 = submenuRef.current) === null || _submenuRef$current3 === void 0 ? void 0 : _submenuRef$current3.querySelectorAll(ALL_CHILDREN_SELECTOR));
|
|
238
|
+
const nextItem = characterNavigation(characterString, submenuChildren);
|
|
243
239
|
|
|
244
|
-
|
|
240
|
+
if (nextItem) {
|
|
241
|
+
setSubmenuFocusId(nextItem.id);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}, [characterString, submenuItemIds]);
|
|
245
245
|
const handleClickInside = useClickAwayListener(handleClickAway);
|
|
246
246
|
|
|
247
247
|
if (inFullscreenView) {
|
|
@@ -265,15 +265,17 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
265
265
|
"data-component": "submenu",
|
|
266
266
|
variant: variant,
|
|
267
267
|
menuType: menuContext.menuType,
|
|
268
|
-
inFullscreenView: inFullscreenView
|
|
269
|
-
|
|
268
|
+
inFullscreenView: inFullscreenView,
|
|
269
|
+
ref: submenuRef
|
|
270
|
+
}, /*#__PURE__*/React.createElement(SubmenuContext.Provider, {
|
|
270
271
|
value: {
|
|
271
|
-
isFocused: submenuFocusIndex === index,
|
|
272
|
-
focusIndex: submenuFocusIndex,
|
|
273
272
|
handleKeyDown,
|
|
274
|
-
blockIndex
|
|
273
|
+
blockIndex,
|
|
274
|
+
registerItem,
|
|
275
|
+
unregisterItem,
|
|
276
|
+
updateFocusId: setSubmenuFocusId
|
|
275
277
|
}
|
|
276
|
-
},
|
|
278
|
+
}, children)));
|
|
277
279
|
}
|
|
278
280
|
|
|
279
281
|
return /*#__PURE__*/React.createElement(StyledSubmenuWrapper, {
|
|
@@ -281,7 +283,8 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
281
283
|
onMouseOver: !clickToOpen ? () => openSubmenu() : undefined,
|
|
282
284
|
onMouseLeave: () => closeSubmenu(),
|
|
283
285
|
isSubmenuOpen: submenuOpen,
|
|
284
|
-
onClick: handleClickInside
|
|
286
|
+
onClick: handleClickInside,
|
|
287
|
+
ref: submenuRef
|
|
285
288
|
}, /*#__PURE__*/React.createElement(StyledMenuItemWrapper, _extends({}, rest, {
|
|
286
289
|
className: className,
|
|
287
290
|
menuType: menuContext.menuType,
|
|
@@ -305,16 +308,17 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
305
308
|
variant: variant,
|
|
306
309
|
menuType: menuContext.menuType,
|
|
307
310
|
role: blockIndex === 0 ? "presentation" : "list"
|
|
308
|
-
},
|
|
311
|
+
}, /*#__PURE__*/React.createElement(SubmenuContext.Provider, {
|
|
309
312
|
value: {
|
|
310
|
-
|
|
311
|
-
focusIndex: submenuFocusIndex,
|
|
313
|
+
submenuFocusId,
|
|
312
314
|
handleKeyDown,
|
|
313
315
|
blockIndex,
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
registerItem,
|
|
317
|
+
unregisterItem,
|
|
318
|
+
updateFocusId: setSubmenuFocusId,
|
|
319
|
+
shiftTabPressed: shiftTabPressed.current
|
|
316
320
|
}
|
|
317
|
-
},
|
|
321
|
+
}, children)));
|
|
318
322
|
});
|
|
319
323
|
Submenu.propTypes = {
|
|
320
324
|
/** Children elements */
|
|
@@ -364,9 +368,6 @@ Submenu.propTypes = {
|
|
|
364
368
|
onSubmenuClose: PropTypes.func,
|
|
365
369
|
|
|
366
370
|
/** Callback triggered when the top-level menu item is clicked */
|
|
367
|
-
onClick: PropTypes.func
|
|
368
|
-
|
|
369
|
-
/** index of child in the parent menu */
|
|
370
|
-
indexInMenu: PropTypes.number
|
|
371
|
+
onClick: PropTypes.func
|
|
371
372
|
};
|
|
372
373
|
export default Submenu;
|
|
@@ -85,8 +85,7 @@ const MenuFullscreen = ({
|
|
|
85
85
|
value: {
|
|
86
86
|
inFullscreenView: true,
|
|
87
87
|
menuType,
|
|
88
|
-
inMenu: true
|
|
89
|
-
setOpenSubmenuIndex: () => {}
|
|
88
|
+
inMenu: true
|
|
90
89
|
}
|
|
91
90
|
}, React.Children.map(children, (child, index) => /*#__PURE__*/React.createElement(React.Fragment, null, child, index < React.Children.count(children) - 1 && /*#__PURE__*/React.createElement(MenuDivider, null))))))))));
|
|
92
91
|
};
|