carbon-react 107.1.3 → 107.1.4
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.
|
@@ -33,12 +33,9 @@ const Tabs = ({
|
|
|
33
33
|
const filteredChildren = useMemo(() => Children.toArray(children).filter(child => child), [children]);
|
|
34
34
|
/** Array of the tabIds for the child nodes */
|
|
35
35
|
|
|
36
|
-
const tabIds = () =>
|
|
37
|
-
return filteredChildren.map(child => child.props.tabId);
|
|
38
|
-
};
|
|
36
|
+
const tabIds = useMemo(() => filteredChildren.map(child => child.props.tabId), [filteredChildren]);
|
|
39
37
|
/** Array of refs to the TabTitle nodes */
|
|
40
38
|
|
|
41
|
-
|
|
42
39
|
const tabRefs = useMemo(() => Array.from({
|
|
43
40
|
length: filteredChildren.length
|
|
44
41
|
}).map(() => /*#__PURE__*/createRef()), [filteredChildren.length]);
|
|
@@ -54,14 +51,14 @@ const Tabs = ({
|
|
|
54
51
|
useLayoutEffect(() => {
|
|
55
52
|
const selectedTab = selectedTabId || Children.toArray(children)[0].props.tabId;
|
|
56
53
|
|
|
57
|
-
if (!tabIds
|
|
54
|
+
if (!tabIds.includes(selectedTabId)) {
|
|
58
55
|
setTabStopId(React.Children.toArray(children)[0].props.tabId);
|
|
59
56
|
} else {
|
|
60
57
|
setTabStopId(selectedTab);
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
setSelectedTabIdState(selectedTab);
|
|
64
|
-
}, []);
|
|
60
|
+
setSelectedTabIdState(selectedTab);
|
|
61
|
+
}, [children, selectedTabId, tabIds]);
|
|
65
62
|
const updateErrors = useCallback((id, hasError) => {
|
|
66
63
|
if (tabsErrors[id] !== hasError) {
|
|
67
64
|
setTabsErrors({ ...tabsErrors,
|
|
@@ -102,6 +99,27 @@ const Tabs = ({
|
|
|
102
99
|
onTabChange(tabid);
|
|
103
100
|
}
|
|
104
101
|
}, [onTabChange, isTabSelected, hasTabStop]);
|
|
102
|
+
const blurPreviousSelectedTab = useCallback(() => {
|
|
103
|
+
const previousTabIndex = tabIds.indexOf(previousSelectedTabId.current);
|
|
104
|
+
/* istanbul ignore else */
|
|
105
|
+
|
|
106
|
+
if (previousTabIndex !== -1) {
|
|
107
|
+
var _previousTabRef$curre;
|
|
108
|
+
|
|
109
|
+
const previousTabRef = tabRefs[previousTabIndex];
|
|
110
|
+
(_previousTabRef$curre = previousTabRef.current) === null || _previousTabRef$curre === void 0 ? void 0 : _previousTabRef$curre.blur();
|
|
111
|
+
}
|
|
112
|
+
}, [tabIds, tabRefs]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (previousSelectedTabId.current !== selectedTabId) {
|
|
115
|
+
if (selectedTabId !== selectedTabIdState) {
|
|
116
|
+
setSelectedTabIdState(selectedTabId);
|
|
117
|
+
blurPreviousSelectedTab();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
previousSelectedTabId.current = selectedTabId;
|
|
121
|
+
}
|
|
122
|
+
}, [blurPreviousSelectedTab, previousSelectedTabId, selectedTabId, selectedTabIdState]);
|
|
105
123
|
/** Determines if the tab titles are in a vertical format. */
|
|
106
124
|
|
|
107
125
|
const isVertical = currentPosition => currentPosition === "left";
|
|
@@ -128,15 +146,14 @@ const Tabs = ({
|
|
|
128
146
|
const goToTab = (event, index) => {
|
|
129
147
|
event.preventDefault();
|
|
130
148
|
let newIndex = index;
|
|
131
|
-
const ids = tabIds();
|
|
132
149
|
|
|
133
150
|
if (index < 0) {
|
|
134
|
-
newIndex =
|
|
135
|
-
} else if (index ===
|
|
151
|
+
newIndex = tabIds.length - 1;
|
|
152
|
+
} else if (index === tabIds.length) {
|
|
136
153
|
newIndex = 0;
|
|
137
154
|
}
|
|
138
155
|
|
|
139
|
-
const nextTabId =
|
|
156
|
+
const nextTabId = tabIds[newIndex];
|
|
140
157
|
const nextRef = tabRefs[newIndex];
|
|
141
158
|
updateVisibleTab(nextTabId);
|
|
142
159
|
focusTab(nextRef);
|
|
@@ -274,15 +291,6 @@ const Tabs = ({
|
|
|
274
291
|
return tabs;
|
|
275
292
|
};
|
|
276
293
|
|
|
277
|
-
useEffect(() => {
|
|
278
|
-
if (previousSelectedTabId.current !== selectedTabId) {
|
|
279
|
-
if (selectedTabId !== selectedTabIdState) {
|
|
280
|
-
setSelectedTabIdState(selectedTabId);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
previousSelectedTabId.current = selectedTabId;
|
|
284
|
-
}
|
|
285
|
-
}, [previousSelectedTabId, selectedTabId, selectedTabIdState]);
|
|
286
294
|
return /*#__PURE__*/React.createElement(StyledTabs, _extends({
|
|
287
295
|
className: className,
|
|
288
296
|
position: isInSidebar ? "left" : position,
|
|
@@ -63,12 +63,9 @@ const Tabs = ({
|
|
|
63
63
|
const filteredChildren = (0, _react.useMemo)(() => _react.Children.toArray(children).filter(child => child), [children]);
|
|
64
64
|
/** Array of the tabIds for the child nodes */
|
|
65
65
|
|
|
66
|
-
const tabIds = () =>
|
|
67
|
-
return filteredChildren.map(child => child.props.tabId);
|
|
68
|
-
};
|
|
66
|
+
const tabIds = (0, _react.useMemo)(() => filteredChildren.map(child => child.props.tabId), [filteredChildren]);
|
|
69
67
|
/** Array of refs to the TabTitle nodes */
|
|
70
68
|
|
|
71
|
-
|
|
72
69
|
const tabRefs = (0, _react.useMemo)(() => Array.from({
|
|
73
70
|
length: filteredChildren.length
|
|
74
71
|
}).map(() => /*#__PURE__*/(0, _react.createRef)()), [filteredChildren.length]);
|
|
@@ -84,14 +81,14 @@ const Tabs = ({
|
|
|
84
81
|
(0, _react.useLayoutEffect)(() => {
|
|
85
82
|
const selectedTab = selectedTabId || _react.Children.toArray(children)[0].props.tabId;
|
|
86
83
|
|
|
87
|
-
if (!tabIds
|
|
84
|
+
if (!tabIds.includes(selectedTabId)) {
|
|
88
85
|
setTabStopId(_react.default.Children.toArray(children)[0].props.tabId);
|
|
89
86
|
} else {
|
|
90
87
|
setTabStopId(selectedTab);
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
setSelectedTabIdState(selectedTab);
|
|
94
|
-
}, []);
|
|
90
|
+
setSelectedTabIdState(selectedTab);
|
|
91
|
+
}, [children, selectedTabId, tabIds]);
|
|
95
92
|
const updateErrors = (0, _react.useCallback)((id, hasError) => {
|
|
96
93
|
if (tabsErrors[id] !== hasError) {
|
|
97
94
|
setTabsErrors({ ...tabsErrors,
|
|
@@ -132,6 +129,27 @@ const Tabs = ({
|
|
|
132
129
|
onTabChange(tabid);
|
|
133
130
|
}
|
|
134
131
|
}, [onTabChange, isTabSelected, hasTabStop]);
|
|
132
|
+
const blurPreviousSelectedTab = (0, _react.useCallback)(() => {
|
|
133
|
+
const previousTabIndex = tabIds.indexOf(previousSelectedTabId.current);
|
|
134
|
+
/* istanbul ignore else */
|
|
135
|
+
|
|
136
|
+
if (previousTabIndex !== -1) {
|
|
137
|
+
var _previousTabRef$curre;
|
|
138
|
+
|
|
139
|
+
const previousTabRef = tabRefs[previousTabIndex];
|
|
140
|
+
(_previousTabRef$curre = previousTabRef.current) === null || _previousTabRef$curre === void 0 ? void 0 : _previousTabRef$curre.blur();
|
|
141
|
+
}
|
|
142
|
+
}, [tabIds, tabRefs]);
|
|
143
|
+
(0, _react.useEffect)(() => {
|
|
144
|
+
if (previousSelectedTabId.current !== selectedTabId) {
|
|
145
|
+
if (selectedTabId !== selectedTabIdState) {
|
|
146
|
+
setSelectedTabIdState(selectedTabId);
|
|
147
|
+
blurPreviousSelectedTab();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
previousSelectedTabId.current = selectedTabId;
|
|
151
|
+
}
|
|
152
|
+
}, [blurPreviousSelectedTab, previousSelectedTabId, selectedTabId, selectedTabIdState]);
|
|
135
153
|
/** Determines if the tab titles are in a vertical format. */
|
|
136
154
|
|
|
137
155
|
const isVertical = currentPosition => currentPosition === "left";
|
|
@@ -158,15 +176,14 @@ const Tabs = ({
|
|
|
158
176
|
const goToTab = (event, index) => {
|
|
159
177
|
event.preventDefault();
|
|
160
178
|
let newIndex = index;
|
|
161
|
-
const ids = tabIds();
|
|
162
179
|
|
|
163
180
|
if (index < 0) {
|
|
164
|
-
newIndex =
|
|
165
|
-
} else if (index ===
|
|
181
|
+
newIndex = tabIds.length - 1;
|
|
182
|
+
} else if (index === tabIds.length) {
|
|
166
183
|
newIndex = 0;
|
|
167
184
|
}
|
|
168
185
|
|
|
169
|
-
const nextTabId =
|
|
186
|
+
const nextTabId = tabIds[newIndex];
|
|
170
187
|
const nextRef = tabRefs[newIndex];
|
|
171
188
|
updateVisibleTab(nextTabId);
|
|
172
189
|
focusTab(nextRef);
|
|
@@ -310,15 +327,6 @@ const Tabs = ({
|
|
|
310
327
|
return tabs;
|
|
311
328
|
};
|
|
312
329
|
|
|
313
|
-
(0, _react.useEffect)(() => {
|
|
314
|
-
if (previousSelectedTabId.current !== selectedTabId) {
|
|
315
|
-
if (selectedTabId !== selectedTabIdState) {
|
|
316
|
-
setSelectedTabIdState(selectedTabId);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
previousSelectedTabId.current = selectedTabId;
|
|
320
|
-
}
|
|
321
|
-
}, [previousSelectedTabId, selectedTabId, selectedTabIdState]);
|
|
322
330
|
return /*#__PURE__*/_react.default.createElement(_tabs.default, _extends({
|
|
323
331
|
className: className,
|
|
324
332
|
position: isInSidebar ? "left" : position,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-react",
|
|
3
|
-
"version": "107.1.
|
|
3
|
+
"version": "107.1.4",
|
|
4
4
|
"description": "A library of reusable React components for easily building user interfaces.",
|
|
5
5
|
"engineStrict": true,
|
|
6
6
|
"engines": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"start:debug-theme": "cross-env STORYBOOK_DEBUG_THEME=true npm run start",
|
|
19
19
|
"test": "jest --config=./jest.conf.json",
|
|
20
20
|
"test-update": "jest --config=./jest.conf.json --updateSnapshot",
|
|
21
|
-
"test:cypress": "cypress open",
|
|
22
|
-
"cypress:react": "npx cypress open
|
|
21
|
+
"test:cypress": "npx cypress open --e2e",
|
|
22
|
+
"cypress:react": "npx cypress open --component",
|
|
23
23
|
"debug": "node --inspect ./node_modules/jest-cli/bin/jest --watch --config=./jest.conf.json",
|
|
24
24
|
"format": "prettier --write './src'",
|
|
25
25
|
"lint": "eslint ./src",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"core-js": "^3.20.3",
|
|
116
116
|
"cross-env": "^5.2.0",
|
|
117
117
|
"css-loader": "4.0.0",
|
|
118
|
-
"cypress": "^
|
|
118
|
+
"cypress": "^10.1.0",
|
|
119
119
|
"cypress-axe": "^0.14.0",
|
|
120
120
|
"cypress-cucumber-preprocessor": "^4.3.1",
|
|
121
121
|
"cypress-each": "^1.11.0",
|