carbon-react 144.1.1 → 144.2.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/esm/components/box/box.component.d.ts +1 -1
- package/esm/components/box/box.component.js +6 -0
- package/esm/components/multi-action-button/multi-action-button.component.js +2 -0
- package/esm/components/split-button/split-button.component.js +17 -4
- package/esm/components/text-editor/text-editor.component.js +4 -2
- package/esm/hooks/__internal__/useChildButtons/useChildButtons.js +6 -11
- package/lib/components/box/box.component.d.ts +1 -1
- package/lib/components/box/box.component.js +6 -0
- package/lib/components/multi-action-button/multi-action-button.component.js +2 -0
- package/lib/components/split-button/split-button.component.js +17 -4
- package/lib/components/text-editor/text-editor.component.js +4 -2
- package/lib/hooks/__internal__/useChildButtons/useChildButtons.js +5 -10
- package/package.json +1 -1
- package/esm/__internal__/utils/helpers/tags/tags-specs/index.d.ts +0 -1
- package/esm/__internal__/utils/helpers/tags/tags-specs/index.js +0 -1
- package/esm/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +0 -3
- package/esm/__internal__/utils/helpers/tags/tags-specs/tags-specs.js +0 -6
- package/lib/__internal__/utils/helpers/tags/tags-specs/index.d.ts +0 -1
- package/lib/__internal__/utils/helpers/tags/tags-specs/index.js +0 -13
- package/lib/__internal__/utils/helpers/tags/tags-specs/package.json +0 -6
- package/lib/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +0 -3
- package/lib/__internal__/utils/helpers/tags/tags-specs/tags-specs.js +0 -12
|
@@ -23,7 +23,7 @@ export interface BoxProps extends FlexboxProps, Omit<GridProps, "gridGap" | "gri
|
|
|
23
23
|
scrollVariant?: ScrollVariant;
|
|
24
24
|
/** Set the box-sizing attribute of the Box component */
|
|
25
25
|
boxSizing?: BoxSizing;
|
|
26
|
-
/** Allows a tabindex to be specified */
|
|
26
|
+
/** (Deprecated) Allows a tabindex to be specified */
|
|
27
27
|
tabIndex?: number;
|
|
28
28
|
/** Gap, an integer multiplier of the base spacing constant (8px) or any valid CSS string." */
|
|
29
29
|
gap?: Gap;
|
|
@@ -4,6 +4,8 @@ import PropTypes from "prop-types";
|
|
|
4
4
|
import { filterStyledSystemMarginProps, filterStyledSystemPaddingProps, filterStyledSystemLayoutProps, filterStyledSystemFlexboxProps, filterStyledSystemGridProps } from "../../style/utils";
|
|
5
5
|
import StyledBox from "./box.style";
|
|
6
6
|
import tagComponent from "../../__internal__/utils/helpers/tags";
|
|
7
|
+
import Logger from "../../__internal__/utils/logger";
|
|
8
|
+
let deprecatedTabIndex = false;
|
|
7
9
|
const Box = /*#__PURE__*/React.forwardRef(({
|
|
8
10
|
"data-component": dataComponent,
|
|
9
11
|
as,
|
|
@@ -27,6 +29,10 @@ const Box = /*#__PURE__*/React.forwardRef(({
|
|
|
27
29
|
"aria-hidden": ariaHidden,
|
|
28
30
|
...rest
|
|
29
31
|
}, ref) => {
|
|
32
|
+
if (!deprecatedTabIndex && tabIndex !== undefined) {
|
|
33
|
+
deprecatedTabIndex = true;
|
|
34
|
+
Logger.deprecate("The `tabIndex` prop for `Box` component has been deprecated and will soon be removed.");
|
|
35
|
+
}
|
|
30
36
|
return /*#__PURE__*/React.createElement(StyledBox, _extends({
|
|
31
37
|
as: as,
|
|
32
38
|
id: id,
|
|
@@ -36,6 +36,8 @@ export const MultiActionButton = ({
|
|
|
36
36
|
} = useChildButtons(buttonRef);
|
|
37
37
|
const handleInsideClick = useClickAwayListener(hideButtons);
|
|
38
38
|
const handleClick = ev => {
|
|
39
|
+
// ensure button is focused when clicked (Safari)
|
|
40
|
+
buttonRef.current?.focus();
|
|
39
41
|
showButtons();
|
|
40
42
|
handleInsideClick();
|
|
41
43
|
if (onClick) {
|
|
@@ -37,6 +37,7 @@ export const SplitButton = ({
|
|
|
37
37
|
const locale = useLocale();
|
|
38
38
|
const theme = useContext(ThemeContext) || baseTheme;
|
|
39
39
|
const buttonLabelId = useRef(guid());
|
|
40
|
+
const mainButtonRef = useRef(null);
|
|
40
41
|
const toggleButton = useRef(null);
|
|
41
42
|
const {
|
|
42
43
|
showAdditionalButtons,
|
|
@@ -47,25 +48,36 @@ export const SplitButton = ({
|
|
|
47
48
|
wrapperProps,
|
|
48
49
|
contextValue
|
|
49
50
|
} = useChildButtons(toggleButton, CONTENT_WIDTH_RATIO);
|
|
51
|
+
const handleMainClick = ev => {
|
|
52
|
+
// ensure button is focused when clicked (Safari)
|
|
53
|
+
mainButtonRef.current?.focus();
|
|
54
|
+
if (onClick) {
|
|
55
|
+
onClick(ev);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
50
58
|
const mainButtonProps = {
|
|
51
|
-
onMouseEnter: hideButtons,
|
|
52
59
|
onFocus: hideButtons,
|
|
53
60
|
onTouchStart: hideButtons,
|
|
54
61
|
iconPosition,
|
|
55
62
|
buttonType,
|
|
56
63
|
disabled,
|
|
57
64
|
iconType,
|
|
58
|
-
onClick:
|
|
65
|
+
onClick: handleMainClick,
|
|
59
66
|
size,
|
|
60
67
|
subtext,
|
|
61
68
|
...filterOutStyledSystemSpacingProps(rest)
|
|
62
69
|
};
|
|
70
|
+
const handleToggleClick = () => {
|
|
71
|
+
// ensure button is focused when clicked (Safari)
|
|
72
|
+
toggleButton.current?.focus();
|
|
73
|
+
showButtons();
|
|
74
|
+
};
|
|
63
75
|
const toggleButtonProps = {
|
|
64
76
|
disabled,
|
|
65
77
|
displayed: showAdditionalButtons,
|
|
66
78
|
onTouchStart: showButtons,
|
|
67
79
|
onKeyDown: handleToggleButtonKeyDown,
|
|
68
|
-
onClick:
|
|
80
|
+
onClick: handleToggleClick,
|
|
69
81
|
buttonType,
|
|
70
82
|
size
|
|
71
83
|
};
|
|
@@ -87,7 +99,8 @@ export const SplitButton = ({
|
|
|
87
99
|
return [/*#__PURE__*/React.createElement(Button, _extends({
|
|
88
100
|
"data-element": "main-button",
|
|
89
101
|
key: "main-button",
|
|
90
|
-
id: buttonLabelId.current
|
|
102
|
+
id: buttonLabelId.current,
|
|
103
|
+
ref: mainButtonRef
|
|
91
104
|
}, mainButtonProps), text), /*#__PURE__*/React.createElement(StyledSplitButtonToggle, _extends({
|
|
92
105
|
"aria-haspopup": "true",
|
|
93
106
|
"aria-expanded": showAdditionalButtons,
|
|
@@ -258,7 +258,8 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
|
|
|
258
258
|
editMode: true
|
|
259
259
|
}
|
|
260
260
|
}, /*#__PURE__*/React.createElement(StyledEditorWrapper, _extends({
|
|
261
|
-
ref: wrapper
|
|
261
|
+
ref: wrapper,
|
|
262
|
+
"data-role": "text-editor-wrapper"
|
|
262
263
|
}, rest), /*#__PURE__*/React.createElement(LabelWrapper, {
|
|
263
264
|
onClick: () => handleEditorFocus(true)
|
|
264
265
|
}, /*#__PURE__*/React.createElement(Label, {
|
|
@@ -277,7 +278,8 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
|
|
|
277
278
|
warning: !!(!error && warning)
|
|
278
279
|
})), /*#__PURE__*/React.createElement(StyledEditorOutline, {
|
|
279
280
|
isFocused: isFocused,
|
|
280
|
-
hasError: !!error
|
|
281
|
+
hasError: !!error,
|
|
282
|
+
"data-role": "editor-outline"
|
|
281
283
|
}, /*#__PURE__*/React.createElement(StyledEditorContainer, {
|
|
282
284
|
"data-component": "text-editor-container",
|
|
283
285
|
hasError: !!error,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useRef,
|
|
1
|
+
import { useState, useRef, useCallback } from "react";
|
|
2
2
|
import Events from "../../../__internal__/utils/helpers/events";
|
|
3
3
|
import useMenuKeyboardNavigation from "../useMenuKeyboardNavigation";
|
|
4
4
|
const useChildButtons = (toggleButtonRef, widthRatio = 1) => {
|
|
@@ -6,7 +6,6 @@ const useChildButtons = (toggleButtonRef, widthRatio = 1) => {
|
|
|
6
6
|
const [minWidth, setMinWidth] = useState(0);
|
|
7
7
|
const buttonNode = useRef(null);
|
|
8
8
|
const childrenContainer = useRef(null);
|
|
9
|
-
const focusFirstChildButtonOnOpen = useRef(false);
|
|
10
9
|
const hideButtons = useCallback(() => {
|
|
11
10
|
setShowAdditionalButtons(false);
|
|
12
11
|
}, []);
|
|
@@ -19,20 +18,16 @@ const useChildButtons = (toggleButtonRef, widthRatio = 1) => {
|
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
const getButtonChildren = useCallback(() => childrenContainer.current?.querySelectorAll('[data-component="button"]'), []);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
const firstChild = getButtonChildren()?.[0];
|
|
24
|
-
if (focusFirstChildButtonOnOpen.current && showAdditionalButtons && firstChild) {
|
|
25
|
-
focusFirstChildButtonOnOpen.current = false;
|
|
26
|
-
firstChild.focus();
|
|
27
|
-
}
|
|
28
|
-
}, [showAdditionalButtons, getButtonChildren]);
|
|
29
21
|
const handleToggleButtonKeyDown = ev => {
|
|
30
|
-
|
|
22
|
+
const isToggleKey = Events.isEnterKey(ev) || Events.isSpaceKey(ev) || Events.isDownKey(ev) || Events.isUpKey(ev) || showAdditionalButtons && Events.isTabKey(ev);
|
|
23
|
+
if (isToggleKey) {
|
|
31
24
|
ev.preventDefault();
|
|
32
25
|
if (!showAdditionalButtons) {
|
|
33
26
|
showButtons();
|
|
34
27
|
}
|
|
35
|
-
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
getButtonChildren()?.[0]?.focus();
|
|
30
|
+
});
|
|
36
31
|
}
|
|
37
32
|
};
|
|
38
33
|
const handleKeyDown = useMenuKeyboardNavigation(toggleButtonRef, getButtonChildren, hideButtons, showAdditionalButtons);
|
|
@@ -23,7 +23,7 @@ export interface BoxProps extends FlexboxProps, Omit<GridProps, "gridGap" | "gri
|
|
|
23
23
|
scrollVariant?: ScrollVariant;
|
|
24
24
|
/** Set the box-sizing attribute of the Box component */
|
|
25
25
|
boxSizing?: BoxSizing;
|
|
26
|
-
/** Allows a tabindex to be specified */
|
|
26
|
+
/** (Deprecated) Allows a tabindex to be specified */
|
|
27
27
|
tabIndex?: number;
|
|
28
28
|
/** Gap, an integer multiplier of the base spacing constant (8px) or any valid CSS string." */
|
|
29
29
|
gap?: Gap;
|
|
@@ -9,8 +9,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
var _utils = require("../../style/utils");
|
|
10
10
|
var _box = _interopRequireDefault(require("./box.style"));
|
|
11
11
|
var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags"));
|
|
12
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
15
|
+
let deprecatedTabIndex = false;
|
|
14
16
|
const Box = exports.Box = /*#__PURE__*/_react.default.forwardRef(({
|
|
15
17
|
"data-component": dataComponent,
|
|
16
18
|
as,
|
|
@@ -34,6 +36,10 @@ const Box = exports.Box = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
34
36
|
"aria-hidden": ariaHidden,
|
|
35
37
|
...rest
|
|
36
38
|
}, ref) => {
|
|
39
|
+
if (!deprecatedTabIndex && tabIndex !== undefined) {
|
|
40
|
+
deprecatedTabIndex = true;
|
|
41
|
+
_logger.default.deprecate("The `tabIndex` prop for `Box` component has been deprecated and will soon be removed.");
|
|
42
|
+
}
|
|
37
43
|
return /*#__PURE__*/_react.default.createElement(_box.default, _extends({
|
|
38
44
|
as: as,
|
|
39
45
|
id: id,
|
|
@@ -45,6 +45,8 @@ const MultiActionButton = ({
|
|
|
45
45
|
} = (0, _useChildButtons.default)(buttonRef);
|
|
46
46
|
const handleInsideClick = (0, _useClickAwayListener.default)(hideButtons);
|
|
47
47
|
const handleClick = ev => {
|
|
48
|
+
// ensure button is focused when clicked (Safari)
|
|
49
|
+
buttonRef.current?.focus();
|
|
48
50
|
showButtons();
|
|
49
51
|
handleInsideClick();
|
|
50
52
|
if (onClick) {
|
|
@@ -46,6 +46,7 @@ const SplitButton = ({
|
|
|
46
46
|
const locale = (0, _useLocale.default)();
|
|
47
47
|
const theme = (0, _react.useContext)(_styledComponents.ThemeContext) || _themes.baseTheme;
|
|
48
48
|
const buttonLabelId = (0, _react.useRef)((0, _guid.default)());
|
|
49
|
+
const mainButtonRef = (0, _react.useRef)(null);
|
|
49
50
|
const toggleButton = (0, _react.useRef)(null);
|
|
50
51
|
const {
|
|
51
52
|
showAdditionalButtons,
|
|
@@ -56,25 +57,36 @@ const SplitButton = ({
|
|
|
56
57
|
wrapperProps,
|
|
57
58
|
contextValue
|
|
58
59
|
} = (0, _useChildButtons.default)(toggleButton, CONTENT_WIDTH_RATIO);
|
|
60
|
+
const handleMainClick = ev => {
|
|
61
|
+
// ensure button is focused when clicked (Safari)
|
|
62
|
+
mainButtonRef.current?.focus();
|
|
63
|
+
if (onClick) {
|
|
64
|
+
onClick(ev);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
59
67
|
const mainButtonProps = {
|
|
60
|
-
onMouseEnter: hideButtons,
|
|
61
68
|
onFocus: hideButtons,
|
|
62
69
|
onTouchStart: hideButtons,
|
|
63
70
|
iconPosition,
|
|
64
71
|
buttonType,
|
|
65
72
|
disabled,
|
|
66
73
|
iconType,
|
|
67
|
-
onClick:
|
|
74
|
+
onClick: handleMainClick,
|
|
68
75
|
size,
|
|
69
76
|
subtext,
|
|
70
77
|
...(0, _utils.filterOutStyledSystemSpacingProps)(rest)
|
|
71
78
|
};
|
|
79
|
+
const handleToggleClick = () => {
|
|
80
|
+
// ensure button is focused when clicked (Safari)
|
|
81
|
+
toggleButton.current?.focus();
|
|
82
|
+
showButtons();
|
|
83
|
+
};
|
|
72
84
|
const toggleButtonProps = {
|
|
73
85
|
disabled,
|
|
74
86
|
displayed: showAdditionalButtons,
|
|
75
87
|
onTouchStart: showButtons,
|
|
76
88
|
onKeyDown: handleToggleButtonKeyDown,
|
|
77
|
-
onClick:
|
|
89
|
+
onClick: handleToggleClick,
|
|
78
90
|
buttonType,
|
|
79
91
|
size
|
|
80
92
|
};
|
|
@@ -96,7 +108,8 @@ const SplitButton = ({
|
|
|
96
108
|
return [/*#__PURE__*/_react.default.createElement(_button.default, _extends({
|
|
97
109
|
"data-element": "main-button",
|
|
98
110
|
key: "main-button",
|
|
99
|
-
id: buttonLabelId.current
|
|
111
|
+
id: buttonLabelId.current,
|
|
112
|
+
ref: mainButtonRef
|
|
100
113
|
}, mainButtonProps), text), /*#__PURE__*/_react.default.createElement(_splitButtonToggle.default, _extends({
|
|
101
114
|
"aria-haspopup": "true",
|
|
102
115
|
"aria-expanded": showAdditionalButtons,
|
|
@@ -267,7 +267,8 @@ const TextEditor = exports.TextEditor = /*#__PURE__*/_react.default.forwardRef((
|
|
|
267
267
|
editMode: true
|
|
268
268
|
}
|
|
269
269
|
}, /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorWrapper, _extends({
|
|
270
|
-
ref: wrapper
|
|
270
|
+
ref: wrapper,
|
|
271
|
+
"data-role": "text-editor-wrapper"
|
|
271
272
|
}, rest), /*#__PURE__*/_react.default.createElement(_labelWrapper.default, {
|
|
272
273
|
onClick: () => handleEditorFocus(true)
|
|
273
274
|
}, /*#__PURE__*/_react.default.createElement(_label.default, {
|
|
@@ -286,7 +287,8 @@ const TextEditor = exports.TextEditor = /*#__PURE__*/_react.default.forwardRef((
|
|
|
286
287
|
warning: !!(!error && warning)
|
|
287
288
|
})), /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorOutline, {
|
|
288
289
|
isFocused: isFocused,
|
|
289
|
-
hasError: !!error
|
|
290
|
+
hasError: !!error,
|
|
291
|
+
"data-role": "editor-outline"
|
|
290
292
|
}, /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorContainer, {
|
|
291
293
|
"data-component": "text-editor-container",
|
|
292
294
|
hasError: !!error,
|
|
@@ -13,7 +13,6 @@ const useChildButtons = (toggleButtonRef, widthRatio = 1) => {
|
|
|
13
13
|
const [minWidth, setMinWidth] = (0, _react.useState)(0);
|
|
14
14
|
const buttonNode = (0, _react.useRef)(null);
|
|
15
15
|
const childrenContainer = (0, _react.useRef)(null);
|
|
16
|
-
const focusFirstChildButtonOnOpen = (0, _react.useRef)(false);
|
|
17
16
|
const hideButtons = (0, _react.useCallback)(() => {
|
|
18
17
|
setShowAdditionalButtons(false);
|
|
19
18
|
}, []);
|
|
@@ -26,20 +25,16 @@ const useChildButtons = (toggleButtonRef, widthRatio = 1) => {
|
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
const getButtonChildren = (0, _react.useCallback)(() => childrenContainer.current?.querySelectorAll('[data-component="button"]'), []);
|
|
29
|
-
(0, _react.useEffect)(() => {
|
|
30
|
-
const firstChild = getButtonChildren()?.[0];
|
|
31
|
-
if (focusFirstChildButtonOnOpen.current && showAdditionalButtons && firstChild) {
|
|
32
|
-
focusFirstChildButtonOnOpen.current = false;
|
|
33
|
-
firstChild.focus();
|
|
34
|
-
}
|
|
35
|
-
}, [showAdditionalButtons, getButtonChildren]);
|
|
36
28
|
const handleToggleButtonKeyDown = ev => {
|
|
37
|
-
|
|
29
|
+
const isToggleKey = _events.default.isEnterKey(ev) || _events.default.isSpaceKey(ev) || _events.default.isDownKey(ev) || _events.default.isUpKey(ev) || showAdditionalButtons && _events.default.isTabKey(ev);
|
|
30
|
+
if (isToggleKey) {
|
|
38
31
|
ev.preventDefault();
|
|
39
32
|
if (!showAdditionalButtons) {
|
|
40
33
|
showButtons();
|
|
41
34
|
}
|
|
42
|
-
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
getButtonChildren()?.[0]?.focus();
|
|
37
|
+
});
|
|
43
38
|
}
|
|
44
39
|
};
|
|
45
40
|
const handleKeyDown = (0, _useMenuKeyboardNavigation.default)(toggleButtonRef, getButtonChildren, hideButtons, showAdditionalButtons);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./tags-specs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./tags-specs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./tags-specs";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "default", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _tagsSpecs.default;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _tagsSpecs = _interopRequireDefault(require("./tags-specs"));
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
const rootTagTest = (rootNode, comp, elem, role) => {
|
|
8
|
-
expect(rootNode.prop("data-component")).toEqual(comp);
|
|
9
|
-
expect(rootNode.prop("data-element")).toEqual(elem);
|
|
10
|
-
expect(rootNode.prop("data-role")).toEqual(role);
|
|
11
|
-
};
|
|
12
|
-
var _default = exports.default = rootTagTest;
|