Skip to content

Commit 394bae7

Browse files
authored
Textarea: allow shift+enter for newline without submit (#968)
* Allow newlines with shift+enter in Textarea component * add test
1 parent 00b8220 commit 394bae7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/components/input/Textarea.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const Textarea = props => {
7171
};
7272

7373
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
7576
const payload = {
7677
n_submit: n_submit + 1,
7778
n_submit_timestamp: Date.now()

src/components/input/__tests__/Textarea.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ describe('Textarea', () => {
200200
expect(n_submit_timestamp).toBeLessThanOrEqual(after);
201201
expect(value).toEqual('some text');
202202
});
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+
});
203212
});
204213
});
205214
});

0 commit comments

Comments
 (0)