carbon-react 111.3.1 → 111.3.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,6 +1,6 @@
|
|
|
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
|
-
import React, { useCallback, useContext, useEffect,
|
|
3
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState, createRef, cloneElement, Children } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import styledSystemPropTypes from "@styled-system/prop-types";
|
|
6
6
|
import Tab from "./tab";
|
|
@@ -40,7 +40,7 @@ const Tabs = ({
|
|
|
40
40
|
length: filteredChildren.length
|
|
41
41
|
}).map(() => /*#__PURE__*/createRef()), [filteredChildren.length]);
|
|
42
42
|
const previousSelectedTabId = useRef(selectedTabId);
|
|
43
|
-
const [selectedTabIdState, setSelectedTabIdState] = useState();
|
|
43
|
+
const [selectedTabIdState, setSelectedTabIdState] = useState(selectedTabId || filteredChildren[0].props.tabId);
|
|
44
44
|
const [tabStopId, setTabStopId] = useState();
|
|
45
45
|
const {
|
|
46
46
|
isInSidebar
|
|
@@ -48,17 +48,6 @@ const Tabs = ({
|
|
|
48
48
|
const [tabsErrors, setTabsErrors] = useState({});
|
|
49
49
|
const [tabsWarnings, setTabsWarnings] = useState({});
|
|
50
50
|
const [tabsInfos, setTabsInfos] = useState({});
|
|
51
|
-
useLayoutEffect(() => {
|
|
52
|
-
const selectedTab = selectedTabId || Children.toArray(children)[0].props.tabId;
|
|
53
|
-
|
|
54
|
-
if (!tabIds.includes(selectedTabId)) {
|
|
55
|
-
setTabStopId(React.Children.toArray(children)[0].props.tabId);
|
|
56
|
-
} else {
|
|
57
|
-
setTabStopId(selectedTab);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setSelectedTabIdState(selectedTab);
|
|
61
|
-
}, [children, selectedTabId, tabIds]);
|
|
62
51
|
const updateErrors = useCallback((id, hasError) => {
|
|
63
52
|
if (tabsErrors[id] !== hasError) {
|
|
64
53
|
setTabsErrors({ ...tabsErrors,
|
|
@@ -249,13 +238,8 @@ const Tabs = ({
|
|
|
249
238
|
|
|
250
239
|
|
|
251
240
|
const visibleTab = () => {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (isTabSelected(child.props.tabId)) {
|
|
255
|
-
tab = child;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
return tab ? /*#__PURE__*/cloneElement(tab, { ...tab.props,
|
|
241
|
+
const tab = filteredChildren.find(child => isTabSelected(child.props.tabId));
|
|
242
|
+
return tab && /*#__PURE__*/cloneElement(tab, { ...tab.props,
|
|
259
243
|
role: "tabpanel",
|
|
260
244
|
position,
|
|
261
245
|
isTabSelected: isTabSelected(tab.props.tabId),
|
|
@@ -264,7 +248,7 @@ const Tabs = ({
|
|
|
264
248
|
updateErrors,
|
|
265
249
|
updateWarnings,
|
|
266
250
|
updateInfos
|
|
267
|
-
})
|
|
251
|
+
});
|
|
268
252
|
};
|
|
269
253
|
/** Builds all tabs where non selected tabs have class of hidden */
|
|
270
254
|
|
|
@@ -70,7 +70,7 @@ const Tabs = ({
|
|
|
70
70
|
length: filteredChildren.length
|
|
71
71
|
}).map(() => /*#__PURE__*/(0, _react.createRef)()), [filteredChildren.length]);
|
|
72
72
|
const previousSelectedTabId = (0, _react.useRef)(selectedTabId);
|
|
73
|
-
const [selectedTabIdState, setSelectedTabIdState] = (0, _react.useState)();
|
|
73
|
+
const [selectedTabIdState, setSelectedTabIdState] = (0, _react.useState)(selectedTabId || filteredChildren[0].props.tabId);
|
|
74
74
|
const [tabStopId, setTabStopId] = (0, _react.useState)();
|
|
75
75
|
const {
|
|
76
76
|
isInSidebar
|
|
@@ -78,17 +78,6 @@ const Tabs = ({
|
|
|
78
78
|
const [tabsErrors, setTabsErrors] = (0, _react.useState)({});
|
|
79
79
|
const [tabsWarnings, setTabsWarnings] = (0, _react.useState)({});
|
|
80
80
|
const [tabsInfos, setTabsInfos] = (0, _react.useState)({});
|
|
81
|
-
(0, _react.useLayoutEffect)(() => {
|
|
82
|
-
const selectedTab = selectedTabId || _react.Children.toArray(children)[0].props.tabId;
|
|
83
|
-
|
|
84
|
-
if (!tabIds.includes(selectedTabId)) {
|
|
85
|
-
setTabStopId(_react.default.Children.toArray(children)[0].props.tabId);
|
|
86
|
-
} else {
|
|
87
|
-
setTabStopId(selectedTab);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
setSelectedTabIdState(selectedTab);
|
|
91
|
-
}, [children, selectedTabId, tabIds]);
|
|
92
81
|
const updateErrors = (0, _react.useCallback)((id, hasError) => {
|
|
93
82
|
if (tabsErrors[id] !== hasError) {
|
|
94
83
|
setTabsErrors({ ...tabsErrors,
|
|
@@ -285,13 +274,8 @@ const Tabs = ({
|
|
|
285
274
|
|
|
286
275
|
|
|
287
276
|
const visibleTab = () => {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (isTabSelected(child.props.tabId)) {
|
|
291
|
-
tab = child;
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
return tab ? /*#__PURE__*/(0, _react.cloneElement)(tab, { ...tab.props,
|
|
277
|
+
const tab = filteredChildren.find(child => isTabSelected(child.props.tabId));
|
|
278
|
+
return tab && /*#__PURE__*/(0, _react.cloneElement)(tab, { ...tab.props,
|
|
295
279
|
role: "tabpanel",
|
|
296
280
|
position,
|
|
297
281
|
isTabSelected: isTabSelected(tab.props.tabId),
|
|
@@ -300,7 +284,7 @@ const Tabs = ({
|
|
|
300
284
|
updateErrors,
|
|
301
285
|
updateWarnings,
|
|
302
286
|
updateInfos
|
|
303
|
-
})
|
|
287
|
+
});
|
|
304
288
|
};
|
|
305
289
|
/** Builds all tabs where non selected tabs have class of hidden */
|
|
306
290
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-react",
|
|
3
|
-
"version": "111.3.
|
|
3
|
+
"version": "111.3.3",
|
|
4
4
|
"description": "A library of reusable React components for easily building user interfaces.",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
@@ -61,6 +61,8 @@
|
|
|
61
61
|
"@babel/preset-typescript": "7.12.7",
|
|
62
62
|
"@babel/template": "^7.16.7",
|
|
63
63
|
"@babel/types": "^7.16.0",
|
|
64
|
+
"@badeball/cypress-cucumber-preprocessor": "^11.4.0",
|
|
65
|
+
"@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
|
|
64
66
|
"@commitlint/cli": "^11.0.0",
|
|
65
67
|
"@commitlint/config-conventional": "^11.0.0",
|
|
66
68
|
"@sage/design-tokens": "^2.41.0",
|
|
@@ -161,8 +163,6 @@
|
|
|
161
163
|
"webpack-dev-server": "^4.0.0"
|
|
162
164
|
},
|
|
163
165
|
"dependencies": {
|
|
164
|
-
"@badeball/cypress-cucumber-preprocessor": "^11.4.0",
|
|
165
|
-
"@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
|
|
166
166
|
"@floating-ui/dom": "^1.0.2",
|
|
167
167
|
"@octokit/rest": "^18.12.0",
|
|
168
168
|
"@styled-system/prop-types": "^5.1.5",
|