@arco-design/mobile-react 2.29.0 → 2.29.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.29.1](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.29.0...@arco-design/mobile-react@2.29.1) (2023-08-21)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix wrong logic after click clear icon of `Input`, `Textarea` and `SearchBar` ([#156](https://github.com/arco-design/arco-design-mobile/issues/156)) ([b741263](https://github.com/arco-design/arco-design-mobile/commit/b741263fd1a1b9c3da9c106f7487714e33e042f2))
12
+
13
+
14
+
15
+
16
+
6
17
  # [2.29.0](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.28.2...@arco-design/mobile-react@2.29.0) (2023-08-17)
7
18
 
8
19
 
package/README.en-US.md CHANGED
@@ -59,8 +59,8 @@ React & ReactDOM: **<a href="https://reactjs.org/docs/cdn-links.html" target="_b
59
59
  React Transition Group: **<a href="https://reactcommunity.org/react-transition-group/" target="_blank">Click here</a>**
60
60
 
61
61
  ```
62
- <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.28.2/dist/style.min.css">
63
- <script src="https://unpkg.com/@arco-design/mobile-react@2.28.2/dist/index.min.js"></script>
62
+ <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.29.0/dist/style.min.css">
63
+ <script src="https://unpkg.com/@arco-design/mobile-react@2.29.0/dist/index.min.js"></script>
64
64
  ```
65
65
 
66
66
  ## Full import
package/README.md CHANGED
@@ -59,8 +59,8 @@ React & ReactDOM: **<a href="https://reactjs.org/docs/cdn-links.html" target="
59
59
  React Transition Group: **<a href="https://reactcommunity.org/react-transition-group/" target="_blank">戳这里获取</a>**
60
60
 
61
61
  ```
62
- <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.28.2/dist/style.min.css">
63
- <script src="https://unpkg.com/@arco-design/mobile-react@2.28.2/dist/index.min.js"></script>
62
+ <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.29.0/dist/style.min.css">
63
+ <script src="https://unpkg.com/@arco-design/mobile-react@2.29.0/dist/index.min.js"></script>
64
64
  ```
65
65
 
66
66
  ## 引入全部
@@ -5,6 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  exports.__esModule = true;
6
6
  exports.useInputLogic = useInputLogic;
7
7
 
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
8
10
  var _react = _interopRequireWildcard(require("react"));
9
11
 
10
12
  var _mobileUtils = require("@arco-design/mobile-utils");
@@ -62,23 +64,6 @@ function useInputLogic(props, inputRef) {
62
64
  toggleClear = _useState2[1];
63
65
 
64
66
  var compositingRef = (0, _react.useRef)(false);
65
- /**
66
- * clear相关问题背景
67
- * 如果点击clear按钮之前已经是focusing状态了,那么在点完clear按钮之后会手动聚焦一下
68
- * 该行为将导致onClear事件触发时,也会触发一次onBlur和onFocus事件,可能影响一些组件外的代码逻辑
69
- *
70
- * e.g. 假设input按钮右侧有一个按钮仅在聚焦时展示
71
- * 实现代码大致是:onBlur设置其visible为false,onFocus设置其visible为true
72
- * 那么这个按钮就会因为clear的点击造成一瞬的闪烁
73
- *
74
- * 解决思路
75
- * 先来看一下,在输入框已激活的状态时,点击清除按钮后,组件的一些事件的触发顺序
76
- * handleBlur -> handleClear -> handleFocus -> onBlur(外部回调) -> onFocus(外部回调)
77
- * 可以看到外部的onBlur和onFocus回调都是在handleClear函数之后被调用
78
- * 因此可以在handleClear中设置一个shouldPreventEvent的boolean标志
79
- * 如果这个标志为true,则跳过调用外部的onBlur和onFocus,并在最后再将标志置回false
80
- *
81
- */
82
67
 
83
68
  var _useState3 = (0, _react.useState)(false),
84
69
  isFocusing = _useState3[0],
@@ -178,28 +163,24 @@ function useInputLogic(props, inputRef) {
178
163
  }
179
164
 
180
165
  function handleFocus(e) {
181
- (0, _mobileUtils.nextTick)(function () {
182
- if (preventEventWhenClearing && shouldPreventEvent.current) {
183
- shouldPreventEvent.current = false;
184
- return;
185
- }
166
+ if (preventEventWhenClearing && shouldPreventEvent.current) {
167
+ shouldPreventEvent.current = false;
168
+ return;
169
+ }
186
170
 
187
- setIsFocusing(true);
188
- clearShowType === 'focus' && toggleClear(true);
189
- onFocus && onFocus(e);
190
- });
171
+ setIsFocusing(true);
172
+ clearShowType === 'focus' && toggleClear(true);
173
+ onFocus && onFocus(e);
191
174
  }
192
175
 
193
176
  function handleBlur(e) {
194
- (0, _mobileUtils.nextTick)(function () {
195
- if (preventEventWhenClearing && shouldPreventEvent.current) {
196
- return;
197
- }
177
+ if (preventEventWhenClearing && shouldPreventEvent.current) {
178
+ return;
179
+ }
198
180
 
199
- setIsFocusing(false);
200
- clearShowType === 'focus' && toggleClear(false);
201
- onBlur && onBlur(e);
202
- });
181
+ setIsFocusing(false);
182
+ clearShowType === 'focus' && toggleClear(false);
183
+ onBlur && onBlur(e);
203
184
  }
204
185
 
205
186
  function handleClick(e) {
@@ -230,10 +211,17 @@ function useInputLogic(props, inputRef) {
230
211
 
231
212
  if (isFocusing) {
232
213
  if (preventEventWhenClearing) {
233
- shouldPreventEvent.current = true;
214
+ shouldPreventEvent.current = true; // 一段时间未执行blur或focus则重置,避免对下次事件循环造成影响
215
+ // @en If blur or focus is not executed for a period of time, it will be reset to avoid affecting the next event loop
216
+
217
+ setTimeout(function () {
218
+ shouldPreventEvent.current = false;
219
+ }, 200);
234
220
  }
235
221
 
236
- inputRef.current && inputRef.current.focus();
222
+ (0, _mobileUtils.nextTick)(function () {
223
+ inputRef.current && inputRef.current.focus();
224
+ });
237
225
  }
238
226
  });
239
227
  }
@@ -243,6 +231,12 @@ function useInputLogic(props, inputRef) {
243
231
  }
244
232
 
245
233
  function renderWrapper(prefixCls, type, children) {
234
+ var _clearEvent;
235
+
236
+ // handleClear必须早于handleBlur执行,pc端仅mousedown事件触发早于blur,移动端touch相关事件均早于blur
237
+ // @en handleClear must be executed earlier than handleBlur
238
+ // @en only the mousedown event on the PC side is triggered earlier than blur, and the touch-related events on the mobile side are all earlier than blur
239
+ var clearEvent = (_clearEvent = {}, _clearEvent[system === 'pc' ? 'onMouseDown' : 'onTouchEnd'] = handleClear, _clearEvent);
246
240
  return /*#__PURE__*/_react.default.createElement("div", {
247
241
  role: "search",
248
242
  className: prefixCls + "-container all-border-box " + (className || ''),
@@ -262,10 +256,9 @@ function useInputLogic(props, inputRef) {
262
256
  className: (0, _mobileUtils.cls)(prefixCls + "-label", {
263
257
  required: required
264
258
  })
265
- }, label) : prefix) : null, children, clearable && showClear ? /*#__PURE__*/_react.default.createElement("div", {
266
- className: prefixCls + "-clear",
267
- onClick: handleClear
268
- }, clearIcon) : null, suffix ? /*#__PURE__*/_react.default.createElement("div", {
259
+ }, label) : prefix) : null, children, clearable && showClear ? /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
260
+ className: prefixCls + "-clear"
261
+ }, clearEvent), clearIcon) : null, suffix ? /*#__PURE__*/_react.default.createElement("div", {
269
262
  className: prefixCls + "-suffix"
270
263
  }, suffix) : null), renderPendNode(append));
271
264
  }
@@ -124,7 +124,7 @@ export interface BasicInputProps<T = HTMLInputElement> {
124
124
  * 按下清除按钮回调
125
125
  * @en Callback when clear button is pressed
126
126
  */
127
- onClear?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
127
+ onClear?: (e: React.TouchEvent<HTMLElement>) => void;
128
128
  /**
129
129
  * 输入框前置内容,在输入框内部,也可自定义
130
130
  * @en The prefix of the input box, inside the input box, can also be customized
package/dist/index.js CHANGED
@@ -941,7 +941,7 @@
941
941
  try {
942
942
  var u = navigator.userAgent;
943
943
  var android = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
944
- var ios = u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) || u.indexOf('Mac OS X') > -1;
944
+ var ios = u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
945
945
  var pc = !android && !ios;
946
946
  var system = android ? 'android' : 'ios';
947
947
  return pc ? 'pc' : system;
@@ -17316,7 +17316,7 @@
17316
17316
  var index$h = componentWrapper(ImagePicker, 'ImagePicker');
17317
17317
 
17318
17318
  /*!
17319
- * @arco-design/transformable v1.0.2
17319
+ * @arco-design/transformable v1.0.1
17320
17320
  * (c) 2022 ludan.kibbon
17321
17321
  */
17322
17322
  function _defineProperty(obj, key, value) {
@@ -21029,23 +21029,6 @@
21029
21029
  toggleClear = _f[1];
21030
21030
 
21031
21031
  var compositingRef = React.useRef(false);
21032
- /**
21033
- * clear相关问题背景
21034
- * 如果点击clear按钮之前已经是focusing状态了,那么在点完clear按钮之后会手动聚焦一下
21035
- * 该行为将导致onClear事件触发时,也会触发一次onBlur和onFocus事件,可能影响一些组件外的代码逻辑
21036
- *
21037
- * e.g. 假设input按钮右侧有一个按钮仅在聚焦时展示
21038
- * 实现代码大致是:onBlur设置其visible为false,onFocus设置其visible为true
21039
- * 那么这个按钮就会因为clear的点击造成一瞬的闪烁
21040
- *
21041
- * 解决思路
21042
- * 先来看一下,在输入框已激活的状态时,点击清除按钮后,组件的一些事件的触发顺序
21043
- * handleBlur -> handleClear -> handleFocus -> onBlur(外部回调) -> onFocus(外部回调)
21044
- * 可以看到外部的onBlur和onFocus回调都是在handleClear函数之后被调用
21045
- * 因此可以在handleClear中设置一个shouldPreventEvent的boolean标志
21046
- * 如果这个标志为true,则跳过调用外部的onBlur和onFocus,并在最后再将标志置回false
21047
- *
21048
- */
21049
21032
 
21050
21033
  var _g = React.useState(false),
21051
21034
  isFocusing = _g[0],
@@ -21145,28 +21128,24 @@
21145
21128
  }
21146
21129
 
21147
21130
  function handleFocus(e) {
21148
- nextTick(function () {
21149
- if (preventEventWhenClearing && shouldPreventEvent.current) {
21150
- shouldPreventEvent.current = false;
21151
- return;
21152
- }
21131
+ if (preventEventWhenClearing && shouldPreventEvent.current) {
21132
+ shouldPreventEvent.current = false;
21133
+ return;
21134
+ }
21153
21135
 
21154
- setIsFocusing(true);
21155
- clearShowType === 'focus' && toggleClear(true);
21156
- onFocus && onFocus(e);
21157
- });
21136
+ setIsFocusing(true);
21137
+ clearShowType === 'focus' && toggleClear(true);
21138
+ onFocus && onFocus(e);
21158
21139
  }
21159
21140
 
21160
21141
  function handleBlur(e) {
21161
- nextTick(function () {
21162
- if (preventEventWhenClearing && shouldPreventEvent.current) {
21163
- return;
21164
- }
21142
+ if (preventEventWhenClearing && shouldPreventEvent.current) {
21143
+ return;
21144
+ }
21165
21145
 
21166
- setIsFocusing(false);
21167
- clearShowType === 'focus' && toggleClear(false);
21168
- onBlur && onBlur(e);
21169
- });
21146
+ setIsFocusing(false);
21147
+ clearShowType === 'focus' && toggleClear(false);
21148
+ onBlur && onBlur(e);
21170
21149
  }
21171
21150
 
21172
21151
  function handleClick(e) {
@@ -21197,10 +21176,17 @@
21197
21176
 
21198
21177
  if (isFocusing) {
21199
21178
  if (preventEventWhenClearing) {
21200
- shouldPreventEvent.current = true;
21179
+ shouldPreventEvent.current = true; // 一段时间未执行blur或focus则重置,避免对下次事件循环造成影响
21180
+ // @en If blur or focus is not executed for a period of time, it will be reset to avoid affecting the next event loop
21181
+
21182
+ setTimeout(function () {
21183
+ shouldPreventEvent.current = false;
21184
+ }, 200);
21201
21185
  }
21202
21186
 
21203
- inputRef.current && inputRef.current.focus();
21187
+ nextTick(function () {
21188
+ inputRef.current && inputRef.current.focus();
21189
+ });
21204
21190
  }
21205
21191
  });
21206
21192
  }
@@ -21210,6 +21196,12 @@
21210
21196
  }
21211
21197
 
21212
21198
  function renderWrapper(prefixCls, type, children) {
21199
+ var _a; // handleClear必须早于handleBlur执行,pc端仅mousedown事件触发早于blur,移动端touch相关事件均早于blur
21200
+ // @en handleClear must be executed earlier than handleBlur
21201
+ // @en only the mousedown event on the PC side is triggered earlier than blur, and the touch-related events on the mobile side are all earlier than blur
21202
+
21203
+
21204
+ var clearEvent = (_a = {}, _a[system === 'pc' ? 'onMouseDown' : 'onTouchEnd'] = handleClear, _a);
21213
21205
  return /*#__PURE__*/React__default["default"].createElement("div", {
21214
21206
  role: "search",
21215
21207
  className: prefixCls + "-container all-border-box " + (className || ''),
@@ -21229,10 +21221,9 @@
21229
21221
  className: cls(prefixCls + "-label", {
21230
21222
  required: required
21231
21223
  })
21232
- }, label) : prefix) : null, children, clearable && showClear ? /*#__PURE__*/React__default["default"].createElement("div", {
21233
- className: prefixCls + "-clear",
21234
- onClick: handleClear
21235
- }, clearIcon) : null, suffix ? /*#__PURE__*/React__default["default"].createElement("div", {
21224
+ }, label) : prefix) : null, children, clearable && showClear ? /*#__PURE__*/React__default["default"].createElement("div", __assign$2({
21225
+ className: prefixCls + "-clear"
21226
+ }, clearEvent), clearIcon) : null, suffix ? /*#__PURE__*/React__default["default"].createElement("div", {
21236
21227
  className: prefixCls + "-suffix"
21237
21228
  }, suffix) : null), renderPendNode(append));
21238
21229
  }