carbon-react 119.9.2 → 119.10.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/components/button/button.component.js +8 -1
- package/esm/components/checkbox/checkbox-group.component.d.ts +4 -0
- package/esm/components/checkbox/checkbox-group.component.js +45 -5
- package/esm/components/checkbox/checkbox-group.style.d.ts +2 -0
- package/esm/components/checkbox/checkbox-group.style.js +18 -1
- package/esm/components/checkbox/checkbox.component.js +17 -13
- package/esm/components/multi-action-button/multi-action-button.component.js +21 -68
- package/esm/components/split-button/__internal__/split-button.context.d.ts +7 -0
- package/esm/components/split-button/__internal__/split-button.context.js +4 -0
- package/esm/components/split-button/split-button.component.js +20 -61
- package/esm/hooks/__internal__/useChildButtons/index.d.ts +1 -0
- package/esm/hooks/__internal__/useChildButtons/index.js +1 -0
- package/esm/hooks/__internal__/useChildButtons/useChildButtons.d.ts +21 -0
- package/esm/hooks/__internal__/useChildButtons/useChildButtons.js +71 -0
- package/esm/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.d.ts +1 -1
- package/esm/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.js +8 -7
- package/lib/components/button/button.component.js +8 -1
- package/lib/components/checkbox/checkbox-group.component.d.ts +4 -0
- package/lib/components/checkbox/checkbox-group.component.js +47 -5
- package/lib/components/checkbox/checkbox-group.style.d.ts +2 -0
- package/lib/components/checkbox/checkbox-group.style.js +20 -2
- package/lib/components/checkbox/checkbox.component.js +17 -13
- package/lib/components/multi-action-button/multi-action-button.component.js +20 -67
- package/lib/components/split-button/__internal__/split-button.context.d.ts +7 -0
- package/lib/components/split-button/__internal__/split-button.context.js +12 -0
- package/lib/components/split-button/split-button.component.js +19 -60
- package/lib/hooks/__internal__/useChildButtons/index.d.ts +1 -0
- package/lib/hooks/__internal__/useChildButtons/index.js +13 -0
- package/lib/hooks/__internal__/useChildButtons/package.json +6 -0
- package/lib/hooks/__internal__/useChildButtons/useChildButtons.d.ts +21 -0
- package/lib/hooks/__internal__/useChildButtons/useChildButtons.js +79 -0
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.d.ts +1 -1
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.js +7 -6
- package/package.json +1 -1
|
@@ -9,8 +9,7 @@ var _events = _interopRequireDefault(require("../../../__internal__/utils/helper
|
|
|
9
9
|
var _focusTrapUtils = require("../../../__internal__/focus-trap/focus-trap-utils");
|
|
10
10
|
var _useModalManager = _interopRequireDefault(require("../useModalManager"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
var _default = (mainControlRef,
|
|
13
|
-
const childrenLength = (0, _react.useMemo)(() => childrenRefs.length, [childrenRefs]);
|
|
12
|
+
var _default = (mainControlRef, getButtonChildren, hide, isOpen) => {
|
|
14
13
|
const refocusMainControl = (0, _react.useCallback)(() => {
|
|
15
14
|
hide();
|
|
16
15
|
mainControlRef.current?.focus();
|
|
@@ -33,8 +32,10 @@ var _default = (mainControlRef, childrenRefs, hide, isOpen) => {
|
|
|
33
32
|
if (!(_events.default.isEnterKey(ev) || _events.default.isSpaceKey(ev))) {
|
|
34
33
|
ev.preventDefault();
|
|
35
34
|
}
|
|
36
|
-
const
|
|
35
|
+
const buttonChildren = getButtonChildren();
|
|
36
|
+
const childrenLength = buttonChildren?.length;
|
|
37
37
|
let nextIndex = -1;
|
|
38
|
+
const currentIndex = Array.from(buttonChildren).indexOf(document.activeElement);
|
|
38
39
|
const arrowModifierPressed = ev.ctrlKey || ev.metaKey;
|
|
39
40
|
if (_events.default.isEndKey(ev) || arrowModifierPressed && _events.default.isDownKey(ev)) {
|
|
40
41
|
nextIndex = childrenLength - 1;
|
|
@@ -61,16 +62,16 @@ var _default = (mainControlRef, childrenRefs, hide, isOpen) => {
|
|
|
61
62
|
const elements = Array.from(document.querySelectorAll(_focusTrapUtils.defaultFocusableSelectors)).filter(el => Number(el.tabIndex) !== -1);
|
|
62
63
|
const indexOf = elements.indexOf(mainControlRef.current);
|
|
63
64
|
elements[indexOf + 1]?.focus();
|
|
64
|
-
//
|
|
65
|
+
// timeout enforces that the "hide" method will be run after browser focuses on the next element
|
|
65
66
|
setTimeout(hide, 0);
|
|
66
67
|
} else {
|
|
67
68
|
nextIndex = currentIndex + 1;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
if (nextIndex > -1) {
|
|
71
|
-
|
|
72
|
+
buttonChildren?.[nextIndex]?.focus();
|
|
72
73
|
}
|
|
73
|
-
}, [
|
|
74
|
+
}, [hide, refocusMainControl, mainControlRef, getButtonChildren]);
|
|
74
75
|
return handleKeyDown;
|
|
75
76
|
};
|
|
76
77
|
exports.default = _default;
|