@@ -39,6 +39,7 @@ const Textarea = props => {
39
39
spellcheck,
40
40
tabIndex,
41
41
tabindex,
42
+ submit_on_enter,
42
43
...otherProps
43
44
} = props ;
44
45
const [ valueState , setValueState ] = useState ( value || '' ) ;
@@ -71,7 +72,7 @@ const Textarea = props => {
71
72
} ;
72
73
73
74
const onKeyPress = e => {
74
- if ( setProps && e . key === 'Enter' && ! e . shiftKey ) {
75
+ if ( submit_on_enter && setProps && e . key === 'Enter' && ! e . shiftKey ) {
75
76
e . preventDefault ( ) ; // don't create newline if submitting
76
77
const payload = {
77
78
n_submit : n_submit + 1 ,
@@ -404,15 +405,22 @@ Textarea.propTypes = {
404
405
n_blur_timestamp : PropTypes . number ,
405
406
406
407
/**
407
- * Number of times the `Enter` key was pressed while the textarea had focus.
408
+ * Number of times the `Enter` key was pressed while the textarea had focus. Only
409
+ * updates if submit_on_enter is True.
408
410
*/
409
411
n_submit : PropTypes . number ,
410
412
411
413
/**
412
- * Last time that `Enter` was pressed.
414
+ * Last time that `Enter` was pressed. Only updates if submit_on_enter is True.
413
415
*/
414
416
n_submit_timestamp : PropTypes . number ,
415
417
418
+ /**
419
+ * Whether or not the form should increment the n_submit and n_submit_timestamp props
420
+ * when enter key is pressed. If True, use shift + enter to create a newline. Default: True
421
+ */
422
+ submit_on_enter : PropTypes . bool ,
423
+
416
424
/**
417
425
* An integer that represents the number of times
418
426
* that this element has been clicked on.
@@ -490,7 +498,8 @@ Textarea.defaultProps = {
490
498
debounce : false ,
491
499
persisted_props : [ 'value' ] ,
492
500
persistence_type : 'local' ,
493
- value : ''
501
+ value : '' ,
502
+ submit_on_enter : true
494
503
} ;
495
504
496
505
export default Textarea ;
0 commit comments