Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea: allow shift+enter for newline without submit #968

Merged
merged 2 commits into from Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/input/Textarea.js
Expand Up @@ -71,7 +71,8 @@ const Textarea = props => {
};

const onKeyPress = e => {
if (setProps && e.key === 'Enter') {
if (setProps && e.key === 'Enter' && !e.shiftKey) {
e.preventDefault(); // don't create newline if submitting
const payload = {
n_submit: n_submit + 1,
n_submit_timestamp: Date.now()
Expand Down
9 changes: 9 additions & 0 deletions src/components/input/__tests__/Textarea.test.js
Expand Up @@ -200,6 +200,15 @@ describe('Textarea', () => {
expect(n_submit_timestamp).toBeLessThanOrEqual(after);
expect(value).toEqual('some text');
});

test('submit not dispatched if shift+enter pressed', () => {
userEvent.type(
textarea,
'some text{shift>}{enter}{/shift}some more text'
);
// one click, no submits
expect(mockSetProps.mock.calls).toHaveLength(1);
});
});
});
});