File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ const Textarea = props => {
71
71
} ;
72
72
73
73
const onKeyPress = e => {
74
- if ( setProps && e . key === 'Enter' ) {
74
+ if ( setProps && e . key === 'Enter' && ! e . shiftKey ) {
75
+ e . preventDefault ( ) ; // don't create newline if submitting
75
76
const payload = {
76
77
n_submit : n_submit + 1 ,
77
78
n_submit_timestamp : Date . now ( )
Original file line number Diff line number Diff line change @@ -200,6 +200,15 @@ describe('Textarea', () => {
200
200
expect ( n_submit_timestamp ) . toBeLessThanOrEqual ( after ) ;
201
201
expect ( value ) . toEqual ( 'some text' ) ;
202
202
} ) ;
203
+
204
+ test ( 'submit not dispatched if shift+enter pressed' , ( ) => {
205
+ userEvent . type (
206
+ textarea ,
207
+ 'some text{shift>}{enter}{/shift}some more text'
208
+ ) ;
209
+ // one click, no submits
210
+ expect ( mockSetProps . mock . calls ) . toHaveLength ( 1 ) ;
211
+ } ) ;
203
212
} ) ;
204
213
} ) ;
205
214
} ) ;
You can’t perform that action at this time.
0 commit comments