@nutui/nutui-react 2.0.0-alpha.7 → 2.0.0-alpha.8

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/dist/esm/tabs2.js CHANGED
@@ -1,6 +1,6 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  var _excluded = ["activeColor", "tabStyle", "direction", "activeType", "duration", "align", "title", "children", "onClick", "onChange", "className", "autoHeight"];
5
5
  function ownKeys(object, enumerableOnly) {
6
6
  var keys = Object.keys(object);
@@ -30,6 +30,12 @@ import { C as ComponentDefaults } from "./typings.js";
30
30
  import TabPane from "./TabPane.js";
31
31
  import { r as requestAniFrame } from "./raf.js";
32
32
  import { u as usePropsValue } from "./use-props-value.js";
33
+ function useForceUpdate() {
34
+ var _React__default$useSt = React__default.useState(), _React__default$useSt2 = _slicedToArray(_React__default$useSt, 2), updateState = _React__default$useSt2[1];
35
+ return React__default.useCallback(function() {
36
+ return updateState({});
37
+ }, []);
38
+ }
33
39
  var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
34
40
  tabStyle: {},
35
41
  activeColor: "",
@@ -100,16 +106,19 @@ var Tabs = function Tabs2(props) {
100
106
  return titles2;
101
107
  };
102
108
  var titles = useRef(getTitles());
109
+ var forceUpdate = useForceUpdate();
103
110
  useEffect(function() {
104
111
  titles.current = getTitles();
105
112
  var current = "";
106
113
  titles.current.forEach(function(title2) {
107
- if (title2.value === value) {
114
+ if (title2.value == value) {
108
115
  current = value;
109
116
  }
110
117
  });
111
- if (current !== "") {
118
+ if (current !== "" && current !== value) {
112
119
  setValue(current);
120
+ } else {
121
+ forceUpdate();
113
122
  }
114
123
  }, [children]);
115
124
  var classes = classNames(classPrefix, "".concat(classPrefix, "--").concat(direction), className);
@@ -120,15 +129,17 @@ var Tabs = function Tabs2(props) {
120
129
  };
121
130
  useEffect(function() {
122
131
  var index = titles.current.findIndex(function(t) {
123
- return t.value === value;
132
+ return t.value == value;
124
133
  });
125
134
  setContentStyle({
126
135
  transform: direction === "horizontal" ? "translate3d(-".concat(index * 100, "%, 0, 0)") : "translate3d( 0,-".concat(index * 100, "%, 0)"),
127
136
  transitionDuration: "".concat(duration, "ms")
128
137
  });
129
- scrollIntoView(index);
138
+ setTimeout(function() {
139
+ scrollIntoView(index);
140
+ });
130
141
  }, [value]);
131
- var tabChange = function tabChange2(item, index) {
142
+ var tabChange = function tabChange2(item) {
132
143
  onClick && onClick(item.value);
133
144
  if (item.disabled) {
134
145
  return;
@@ -141,10 +152,10 @@ var Tabs = function Tabs2(props) {
141
152
  className: classesTitle,
142
153
  style: _objectSpread({}, tabStyle),
143
154
  ref: navRef
144
- }, !!title && typeof title === "function" ? title() : titles.current.map(function(item, index) {
155
+ }, !!title && typeof title === "function" ? title() : titles.current.map(function(item) {
145
156
  var _classNames2;
146
157
  return React__default.createElement("div", {
147
- onClick: function onClick2(e) {
158
+ onClick: function onClick2() {
148
159
  tabChange(item);
149
160
  },
150
161
  className: classNames("".concat(classPrefix, "__titles-item"), (_classNames2 = {}, _defineProperty(_classNames2, "nut-tabs__titles-item--active", !item.disabled && String(item.value) === String(value)), _defineProperty(_classNames2, "nut-tabs__titles-item--disabled", item.disabled), _defineProperty(_classNames2, "nut-tabs__titles-item--".concat(align), align), _classNames2)),
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.7 Fri May 12 2023 15:35:59 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */