From 0ae185ef01c1206f54fe6b35865a7025d3dae5eb Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Tue, 10 Dec 2019 11:29:55 +0100 Subject: [PATCH] Add optional submit function for text areas --- scm-ui/ui-components/src/forms/Textarea.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scm-ui/ui-components/src/forms/Textarea.tsx b/scm-ui/ui-components/src/forms/Textarea.tsx index b16c33b708..9486e3e273 100644 --- a/scm-ui/ui-components/src/forms/Textarea.tsx +++ b/scm-ui/ui-components/src/forms/Textarea.tsx @@ -1,4 +1,4 @@ -import React, { ChangeEvent } from "react"; +import React, { ChangeEvent, KeyboardEvent } from "react"; import LabelWithHelpIcon from "./LabelWithHelpIcon"; type Props = { @@ -10,6 +10,7 @@ type Props = { onChange: (value: string, name?: string) => void; helpText?: string; disabled?: boolean; + onSubmit?: () => void; }; class Textarea extends React.Component { @@ -25,6 +26,13 @@ class Textarea extends React.Component { this.props.onChange(event.target.value, this.props.name); }; + onKeyPress = (event: KeyboardEvent) => { + const { onSubmit } = this.props; + if (onSubmit && event.key === "Enter" && event.ctrlKey) { + onSubmit(); + } + }; + render() { const { placeholder, value, label, helpText, disabled } = this.props; @@ -41,6 +49,7 @@ class Textarea extends React.Component { onChange={this.handleInput} value={value} disabled={!!disabled} + onKeyPress={this.onKeyPress} />