mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +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";
|
import LabelWithHelpIcon from "./LabelWithHelpIcon";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -10,6 +10,7 @@ type Props = {
|
|||||||
onChange: (value: string, name?: string) => void;
|
onChange: (value: string, name?: string) => void;
|
||||||
helpText?: string;
|
helpText?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
onSubmit?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Textarea extends React.Component<Props> {
|
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);
|
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() {
|
render() {
|
||||||
const { placeholder, value, label, helpText, disabled } = this.props;
|
const { placeholder, value, label, helpText, disabled } = this.props;
|
||||||
|
|
||||||
@@ -41,6 +49,7 @@ class Textarea extends React.Component<Props> {
|
|||||||
onChange={this.handleInput}
|
onChange={this.handleInput}
|
||||||
value={value}
|
value={value}
|
||||||
disabled={!!disabled}
|
disabled={!!disabled}
|
||||||
|
onKeyPress={this.onKeyPress}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user