carbon-react 111.3.2 → 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.
@@ -21,6 +21,7 @@ const Tab = ({
21
21
  updateWarnings,
22
22
  updateInfos,
23
23
  href,
24
+ title,
24
25
  ...rest
25
26
  }) => {
26
27
  const [tabErrors, setTabErrors] = useState({});
@@ -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, useLayoutEffect, useMemo, useRef, useState, createRef, cloneElement, Children } from "react";
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
- let tab;
253
- filteredChildren.forEach(child => {
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
- }) : null;
251
+ });
268
252
  };
269
253
  /** Builds all tabs where non selected tabs have class of hidden */
270
254
 
@@ -42,6 +42,7 @@ const Tab = ({
42
42
  updateWarnings,
43
43
  updateInfos,
44
44
  href,
45
+ title,
45
46
  ...rest
46
47
  }) => {
47
48
  const [tabErrors, setTabErrors] = (0, _react.useState)({});
@@ -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
- let tab;
289
- filteredChildren.forEach(child => {
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
- }) : null;
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.2",
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",