mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
Add optional cancel function for text areas
This commit is contained in:
@@ -11,6 +11,7 @@ type Props = {
|
|||||||
helpText?: string;
|
helpText?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onSubmit?: () => void;
|
onSubmit?: () => void;
|
||||||
|
onCancel?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Textarea extends React.Component<Props> {
|
class Textarea extends React.Component<Props> {
|
||||||
@@ -33,6 +34,13 @@ class Textarea extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
const { onCancel } = this.props;
|
||||||
|
if (onCancel && event.key === "Escape") {
|
||||||
|
onCancel();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { placeholder, value, label, helpText, disabled } = this.props;
|
const { placeholder, value, label, helpText, disabled } = this.props;
|
||||||
|
|
||||||
@@ -50,6 +58,7 @@ class Textarea extends React.Component<Props> {
|
|||||||
value={value}
|
value={value}
|
||||||
disabled={!!disabled}
|
disabled={!!disabled}
|
||||||
onKeyPress={this.onKeyPress}
|
onKeyPress={this.onKeyPress}
|
||||||
|
onKeyDown={this.onKeyDown}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user