@sheinx/base 3.7.3-beta.2 → 3.7.3-beta.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.
@@ -1 +1 @@
1
- {"version":3,"file":"simple-input.d.ts","sourceRoot":"","sources":["simple-input.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,QAAA,MAAM,KAAK;YAAW,gBAAgB;;CAgGrC,CAAC;AAGF,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"simple-input.d.ts","sourceRoot":"","sources":["simple-input.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,QAAA,MAAM,KAAK;YAAW,gBAAgB;;CAsHrC,CAAC;AAGF,eAAe,KAAK,CAAC"}
@@ -42,12 +42,33 @@ var Input = function Input(props) {
42
42
  addEnd = props.addEnd,
43
43
  hasSuffix = props.hasSuffix,
44
44
  rest = _objectWithoutProperties(props, _excluded);
45
+ var _useRef = (0, _react.useRef)({
46
+ needTriggerEnter: false
47
+ }),
48
+ context = _useRef.current;
45
49
  var inputStyle = jssStyle === null || jssStyle === void 0 || (_jssStyle$input = jssStyle.input) === null || _jssStyle$input === void 0 ? void 0 : _jssStyle$input.call(jssStyle);
46
50
  var config = (0, _config.useConfig)();
47
51
  var _useContext = (0, _react.useContext)(_formFieldContext.FormFieldContext),
48
52
  fieldId = _useContext.fieldId;
49
53
  var _useInput = (0, _hooks.useInput)(_objectSpread(_objectSpread({}, rest), {}, {
50
- onFocusedChange: onFocusedChange
54
+ onFocusedChange: onFocusedChange,
55
+ // 由于form的原生submit事件是在keydown中触发的,submit校验后触发scrollToError会导致当前焦点的input立即失焦,导致input的回车事件无法触发
56
+ // 所以这里在onKeyDown时机记录下needTriggerEnter标志,在onBlur时机判断是否需要触发onEnterPress
57
+ onKeyDown: function onKeyDown(e) {
58
+ var _props$onKeyDown;
59
+ if (e.key === 'Enter') {
60
+ context.needTriggerEnter = true;
61
+ }
62
+ (_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 || _props$onKeyDown.call(props, e);
63
+ },
64
+ onBlur: function onBlur(e) {
65
+ var _props$onBlur;
66
+ if (context.needTriggerEnter) {
67
+ context.needTriggerEnter = false;
68
+ _onEnterPress === null || _onEnterPress === void 0 || _onEnterPress(e.target.value || '', e);
69
+ }
70
+ (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, e);
71
+ }
51
72
  })),
52
73
  getRootProps = _useInput.getRootProps,
53
74
  getClearProps = _useInput.getClearProps,
@@ -63,6 +84,10 @@ var Input = function Input(props) {
63
84
  });
64
85
  var onKeyUp = (0, _hooks.usePersistFn)(function (e) {
65
86
  var _props$onKeyUp;
87
+ if (e.key === 'Enter') {
88
+ context.needTriggerEnter = false;
89
+ }
90
+ ;
66
91
  (_props$onKeyUp = props.onKeyUp) === null || _props$onKeyUp === void 0 || _props$onKeyUp.call(props, e);
67
92
  keyHandler(e);
68
93
  });
@@ -1 +1 @@
1
- {"version":3,"file":"simple-input.d.ts","sourceRoot":"","sources":["simple-input.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,QAAA,MAAM,KAAK;YAAW,gBAAgB;;CAgGrC,CAAC;AAGF,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"simple-input.d.ts","sourceRoot":"","sources":["simple-input.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,QAAA,MAAM,KAAK;YAAW,gBAAgB;;CAsHrC,CAAC;AAGF,eAAe,KAAK,CAAC"}
@@ -9,7 +9,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import { useInput, useKeyEvent, usePersistFn, util } from '@sheinx/hooks';
11
11
  import classNames from 'classnames';
12
- import React, { useContext } from 'react';
12
+ import React, { useContext, useRef } from 'react';
13
13
  import Icons from "../icons";
14
14
  import { useConfig } from "../config";
15
15
  import { FormFieldContext } from "../form/form-field-context";
@@ -34,12 +34,33 @@ var Input = function Input(props) {
34
34
  addEnd = props.addEnd,
35
35
  hasSuffix = props.hasSuffix,
36
36
  rest = _objectWithoutProperties(props, _excluded);
37
+ var _useRef = useRef({
38
+ needTriggerEnter: false
39
+ }),
40
+ context = _useRef.current;
37
41
  var inputStyle = jssStyle === null || jssStyle === void 0 || (_jssStyle$input = jssStyle.input) === null || _jssStyle$input === void 0 ? void 0 : _jssStyle$input.call(jssStyle);
38
42
  var config = useConfig();
39
43
  var _useContext = useContext(FormFieldContext),
40
44
  fieldId = _useContext.fieldId;
41
45
  var _useInput = useInput(_objectSpread(_objectSpread({}, rest), {}, {
42
- onFocusedChange: onFocusedChange
46
+ onFocusedChange: onFocusedChange,
47
+ // 由于form的原生submit事件是在keydown中触发的,submit校验后触发scrollToError会导致当前焦点的input立即失焦,导致input的回车事件无法触发
48
+ // 所以这里在onKeyDown时机记录下needTriggerEnter标志,在onBlur时机判断是否需要触发onEnterPress
49
+ onKeyDown: function onKeyDown(e) {
50
+ var _props$onKeyDown;
51
+ if (e.key === 'Enter') {
52
+ context.needTriggerEnter = true;
53
+ }
54
+ (_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 || _props$onKeyDown.call(props, e);
55
+ },
56
+ onBlur: function onBlur(e) {
57
+ var _props$onBlur;
58
+ if (context.needTriggerEnter) {
59
+ context.needTriggerEnter = false;
60
+ _onEnterPress === null || _onEnterPress === void 0 || _onEnterPress(e.target.value || '', e);
61
+ }
62
+ (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, e);
63
+ }
43
64
  })),
44
65
  getRootProps = _useInput.getRootProps,
45
66
  getClearProps = _useInput.getClearProps,
@@ -55,6 +76,10 @@ var Input = function Input(props) {
55
76
  });
56
77
  var onKeyUp = usePersistFn(function (e) {
57
78
  var _props$onKeyUp;
79
+ if (e.key === 'Enter') {
80
+ context.needTriggerEnter = false;
81
+ }
82
+ ;
58
83
  (_props$onKeyUp = props.onKeyUp) === null || _props$onKeyUp === void 0 || _props$onKeyUp.call(props, e);
59
84
  keyHandler(e);
60
85
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/base",
3
- "version": "3.7.3-beta.2",
3
+ "version": "3.7.3-beta.4",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "module": "./esm/index.js",
11
11
  "typings": "./cjs/index.d.ts",
12
12
  "dependencies": {
13
- "@sheinx/hooks": "3.7.3-beta.2",
13
+ "@sheinx/hooks": "3.7.3-beta.4",
14
14
  "immer": "^10.0.0",
15
15
  "classnames": "^2.0.0",
16
16
  "@shined/reactive": "^0.1.3-alpha.0"