Browse Source

Update: Enter触发submit事件,不是订阅Enter事件

Evo 4 years ago
parent
commit
556bf1c6ca
2 changed files with 8 additions and 15 deletions
  1. 7
    13
      src/components/Editor/index.js
  2. 1
    2
      src/index.js

+ 7
- 13
src/components/Editor/index.js View File

71
   }
71
   }
72
 
72
 
73
   componentDidMount() {
73
   componentDidMount() {
74
-    const { app, onRef, allowEnter, onPressEnter } = this.props;
74
+    const { app, onRef } = this.props;
75
     if (
75
     if (
76
       app.currentUser &&
76
       app.currentUser &&
77
       (app.currentUser.user_id > 0 || app.currentUser.id > 0)
77
       (app.currentUser.user_id > 0 || app.currentUser.id > 0)
81
     if (isFunction(onRef)) {
81
     if (isFunction(onRef)) {
82
       onRef(this);
82
       onRef(this);
83
     }
83
     }
84
-
85
-    if ((allowEnter && !onPressEnter) || (!allowEnter && onPressEnter))
86
-      console.error("`onPressEnter` must be undefined when `allowEnter`!");
87
   }
84
   }
88
 
85
 
89
   handleEmojiScroll(e) {
86
   handleEmojiScroll(e) {
298
 
295
 
299
   /**
296
   /**
300
    *  **处理Enter事件**
297
    *  **处理Enter事件**
301
-   *  1. `allowEnter` & `onPressEnter`同时有效时才能触发
298
+   *  1. `allowEnterSubmit`为true时enter触发submit事件
302
    *  2. `e.preventDefault`为了防止enter事件后仍触发换行
299
    *  2. `e.preventDefault`为了防止enter事件后仍触发换行
303
-   *  3. enter事件开启,仍可以用`shift + enter`触发换行
300
+   *  3. enter事件开启,仍可以用`shift + enter`触发换行
304
    *  -- evo 20200222
301
    *  -- evo 20200222
305
    */
302
    */
306
   handlePressEnter = e => {
303
   handlePressEnter = e => {
307
-    const { allowEnter, onPressEnter } = this.props;
308
-    if (allowEnter && onPressEnter) {
304
+    if (this.props.allowEnterSubmit) {
309
       if (!e.shiftKey) {
305
       if (!e.shiftKey) {
310
         e.preventDefault();
306
         e.preventDefault();
311
-        onPressEnter();
307
+        this.handleSubmit();
312
       }
308
       }
313
     }
309
     }
314
   };
310
   };
530
   onError: PropTypes.func,
526
   onError: PropTypes.func,
531
   maxLength: PropTypes.number,
527
   maxLength: PropTypes.number,
532
   // Enter事件相关
528
   // Enter事件相关
533
-  allowEnter: PropTypes.bool,
534
-  onPressEnter: PropTypes.func
529
+  allowEnterSubmit: PropTypes.bool
535
 };
530
 };
536
 
531
 
537
 Editor.defaultProps = {
532
 Editor.defaultProps = {
553
   app: {},
548
   app: {},
554
   handleChangeFileList: () => {},
549
   handleChangeFileList: () => {},
555
   // Enter事件相关
550
   // Enter事件相关
556
-  allowEnter: false,
557
-  onPressEnter: undefined
551
+  allowEnterSubmit: false
558
 };
552
 };
559
 
553
 
560
 export default Comment(Editor);
554
 export default Comment(Editor);

+ 1
- 2
src/index.js View File

43
               fileList
43
               fileList
44
             });
44
             });
45
           }}
45
           }}
46
-          allowEnter
47
-          onPressEnter={e => alert("enter pressed")}
46
+          allowEnterSubmit
48
         />
47
         />
49
       </App>
48
       </App>
50
     );
49
     );