mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 20:15:52 +01:00
Add optional submit function for text areas
This commit is contained in:
@@ -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<Props> {
|
||||
@@ -25,6 +26,13 @@ class Textarea extends React.Component<Props> {
|
||||
this.props.onChange(event.target.value, this.props.name);
|
||||
};
|
||||
|
||||
onKeyPress = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
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<Props> {
|
||||
onChange={this.handleInput}
|
||||
value={value}
|
||||
disabled={!!disabled}
|
||||
onKeyPress={this.onKeyPress}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user