carbon-react 95.0.0 → 95.0.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.
|
@@ -344,10 +344,6 @@ const StyledTabTitle = _styledComponents.default.li`
|
|
|
344
344
|
padding-bottom: 0px;
|
|
345
345
|
`}
|
|
346
346
|
|
|
347
|
-
&:focus {
|
|
348
|
-
outline: ${isInSidebar ? "none;" : `2px solid ${theme.colors.focus};`}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
347
|
&:hover {
|
|
352
348
|
background-color: ${theme.colors.white};
|
|
353
349
|
border-bottom-color: ${alternateStyling ? `${theme.tab.background};` : `${theme.colors.primary};`}
|
|
@@ -355,6 +351,16 @@ const StyledTabTitle = _styledComponents.default.li`
|
|
|
355
351
|
cursor: default;
|
|
356
352
|
}
|
|
357
353
|
`}
|
|
354
|
+
|
|
355
|
+
${({
|
|
356
|
+
theme,
|
|
357
|
+
isInSidebar
|
|
358
|
+
}) => `
|
|
359
|
+
&:focus {
|
|
360
|
+
outline: ${isInSidebar ? "none;" : `2px solid ${theme.colors.focus};`}
|
|
361
|
+
z-index: 1;
|
|
362
|
+
}
|
|
363
|
+
`}
|
|
358
364
|
|
|
359
365
|
${({
|
|
360
366
|
position,
|
|
@@ -59,9 +59,22 @@ const Tabs = ({
|
|
|
59
59
|
headerWidth,
|
|
60
60
|
...rest
|
|
61
61
|
}) => {
|
|
62
|
-
|
|
62
|
+
/** The children nodes converted into an Array */
|
|
63
|
+
const filteredChildren = (0, _react.useMemo)(() => _react.Children.toArray(children).filter(child => child), [children]);
|
|
64
|
+
/** Array of the tabIds for the child nodes */
|
|
65
|
+
|
|
66
|
+
const tabIds = () => {
|
|
67
|
+
return filteredChildren.map(child => child.props.tabId);
|
|
68
|
+
};
|
|
69
|
+
/** Array of refs to the TabTitle nodes */
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
const tabRefs = (0, _react.useMemo)(() => Array.from({
|
|
73
|
+
length: filteredChildren.length
|
|
74
|
+
}).map(() => /*#__PURE__*/(0, _react.createRef)()), [filteredChildren.length]);
|
|
63
75
|
const previousSelectedTabId = (0, _react.useRef)(selectedTabId);
|
|
64
76
|
const [selectedTabIdState, setSelectedTabIdState] = (0, _react.useState)();
|
|
77
|
+
const [tabStopId, setTabStopId] = (0, _react.useState)();
|
|
65
78
|
const {
|
|
66
79
|
isInSidebar
|
|
67
80
|
} = (0, _react.useContext)(_drawer.DrawerSidebarContext);
|
|
@@ -69,7 +82,13 @@ const Tabs = ({
|
|
|
69
82
|
const [tabsWarnings, setTabsWarnings] = (0, _react.useState)({});
|
|
70
83
|
const [tabsInfos, setTabsInfos] = (0, _react.useState)({});
|
|
71
84
|
(0, _react.useLayoutEffect)(() => {
|
|
72
|
-
const selectedTab = selectedTabId || _react.
|
|
85
|
+
const selectedTab = selectedTabId || _react.Children.toArray(children)[0].props.tabId;
|
|
86
|
+
|
|
87
|
+
if (!tabIds().includes(selectedTabId)) {
|
|
88
|
+
setTabStopId(_react.default.Children.toArray(children)[0].props.tabId);
|
|
89
|
+
} else {
|
|
90
|
+
setTabStopId(selectedTab);
|
|
91
|
+
}
|
|
73
92
|
|
|
74
93
|
setSelectedTabIdState(selectedTab); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
94
|
}, []);
|
|
@@ -94,15 +113,25 @@ const Tabs = ({
|
|
|
94
113
|
});
|
|
95
114
|
}
|
|
96
115
|
}, [tabsInfos]);
|
|
116
|
+
/** Returns true/false for if the given tab id is selected. */
|
|
117
|
+
|
|
118
|
+
const isTabSelected = (0, _react.useCallback)(tabId => tabId === selectedTabIdState, [selectedTabIdState]);
|
|
119
|
+
const hasTabStop = (0, _react.useCallback)(tabId => tabId === tabStopId, [tabStopId]);
|
|
97
120
|
/** Updates the currently visible tab */
|
|
98
121
|
|
|
99
122
|
const updateVisibleTab = (0, _react.useCallback)(tabid => {
|
|
100
|
-
|
|
123
|
+
if (!isTabSelected(tabid)) {
|
|
124
|
+
setSelectedTabIdState(tabid);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!hasTabStop(tabid)) {
|
|
128
|
+
setTabStopId(tabid);
|
|
129
|
+
}
|
|
101
130
|
|
|
102
131
|
if (onTabChange) {
|
|
103
132
|
onTabChange(tabid);
|
|
104
133
|
}
|
|
105
|
-
}, [onTabChange]);
|
|
134
|
+
}, [onTabChange, isTabSelected, hasTabStop]);
|
|
106
135
|
/** Determines if the tab titles are in a vertical format. */
|
|
107
136
|
|
|
108
137
|
const isVertical = currentPosition => currentPosition === "left";
|
|
@@ -122,17 +151,7 @@ const Tabs = ({
|
|
|
122
151
|
/** Focuses the tab for the reference specified */
|
|
123
152
|
|
|
124
153
|
|
|
125
|
-
const focusTab = ref => ref.focus();
|
|
126
|
-
/** The children nodes converted into an Array */
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const filteredChildren = _react.default.useMemo(() => _react.default.Children.toArray(children).filter(child => child), [children]);
|
|
130
|
-
/** Array of the tabIds for the child nodes */
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const tabIds = () => {
|
|
134
|
-
return filteredChildren.map(child => child.props.tabId);
|
|
135
|
-
};
|
|
154
|
+
const focusTab = ref => ref.current.focus();
|
|
136
155
|
/** Will trigger the tab at the given index. */
|
|
137
156
|
|
|
138
157
|
|
|
@@ -148,7 +167,7 @@ const Tabs = ({
|
|
|
148
167
|
}
|
|
149
168
|
|
|
150
169
|
const nextTabId = ids[newIndex];
|
|
151
|
-
const nextRef = tabRefs
|
|
170
|
+
const nextRef = tabRefs[newIndex];
|
|
152
171
|
updateVisibleTab(nextTabId);
|
|
153
172
|
focusTab(nextRef);
|
|
154
173
|
};
|
|
@@ -174,16 +193,6 @@ const Tabs = ({
|
|
|
174
193
|
}
|
|
175
194
|
};
|
|
176
195
|
};
|
|
177
|
-
/** Returns true/false for if the given tab id is selected. */
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const isTabSelected = tabId => tabId === selectedTabIdState;
|
|
181
|
-
|
|
182
|
-
const addRef = ref => {
|
|
183
|
-
if (ref && !tabRefs.current.includes(ref)) {
|
|
184
|
-
tabRefs.current.push(ref);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
196
|
/** Build the headers for the tab component */
|
|
188
197
|
|
|
189
198
|
|
|
@@ -220,8 +229,8 @@ const Tabs = ({
|
|
|
220
229
|
key: tabId,
|
|
221
230
|
onClick: handleTabClick,
|
|
222
231
|
onKeyDown: handleKeyDown(index),
|
|
223
|
-
ref:
|
|
224
|
-
tabIndex: isTabSelected(tabId) ? "0" : "-1",
|
|
232
|
+
ref: tabRefs[index],
|
|
233
|
+
tabIndex: isTabSelected(tabId) || hasTabStop(tabId) ? "0" : "-1",
|
|
225
234
|
title: title,
|
|
226
235
|
href: href,
|
|
227
236
|
isTabSelected: isTabSelected(tabId),
|
|
@@ -239,7 +248,16 @@ const Tabs = ({
|
|
|
239
248
|
noLeftBorder: ["no left side", "no sides"].includes(borders),
|
|
240
249
|
noRightBorder: ["no right side", "no sides"].includes(borders),
|
|
241
250
|
customLayout: customLayout,
|
|
242
|
-
isInSidebar: isInSidebar
|
|
251
|
+
isInSidebar: isInSidebar,
|
|
252
|
+
onFocus: () => {
|
|
253
|
+
if (!hasTabStop(tabId)) {
|
|
254
|
+
setTabStopId(tabId);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!isTabSelected(tabId)) {
|
|
258
|
+
updateVisibleTab(tabId);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
243
261
|
});
|
|
244
262
|
|
|
245
263
|
return tabTitle;
|
|
@@ -264,7 +282,7 @@ const Tabs = ({
|
|
|
264
282
|
tab = child;
|
|
265
283
|
}
|
|
266
284
|
});
|
|
267
|
-
return tab ? /*#__PURE__*/_react.
|
|
285
|
+
return tab ? /*#__PURE__*/(0, _react.cloneElement)(tab, {
|
|
268
286
|
isTabSelected: isTabSelected(tab.props.tabId)
|
|
269
287
|
}) : null;
|
|
270
288
|
};
|
|
@@ -279,7 +297,7 @@ const Tabs = ({
|
|
|
279
297
|
}
|
|
280
298
|
|
|
281
299
|
const tabs = filteredChildren.map(child => {
|
|
282
|
-
return /*#__PURE__*/_react.
|
|
300
|
+
return /*#__PURE__*/(0, _react.cloneElement)(child, { ...child.props,
|
|
283
301
|
role: "tabpanel",
|
|
284
302
|
position,
|
|
285
303
|
isTabSelected: isTabSelected(child.props.tabId),
|