Files
SCM-Manager/scm-ui/ui-components/src/forms/Textarea.tsx

52 lines
1.2 KiB
TypeScript
Raw Normal View History

import React, { ChangeEvent } from "react";
import LabelWithHelpIcon from "./LabelWithHelpIcon";
type Props = {
name?: string;
label?: string;
placeholder?: string;
value?: string;
autofocus?: boolean;
onChange: (value: string, name?: string) => void;
helpText?: string;
disabled?: boolean;
};
class Textarea extends React.Component<Props> {
field: HTMLTextAreaElement | null | undefined;
componentDidMount() {
if (this.props.autofocus && this.field) {
this.field.focus();
}
}
handleInput = (event: ChangeEvent<HTMLTextAreaElement>) => {
2018-11-09 14:04:26 +01:00
this.props.onChange(event.target.value, this.props.name);
};
render() {
const { placeholder, value, label, helpText, disabled } = this.props;
return (
<div className="field">
2018-10-04 10:16:20 +02:00
<LabelWithHelpIcon label={label} helpText={helpText} />
2018-10-02 13:04:34 +02:00
<div className="control">
<textarea
className="textarea"
ref={input => {
this.field = input;
}}
placeholder={placeholder}
onChange={this.handleInput}
value={value}
disabled={!!disabled}
/>
</div>
</div>
);
}
}
export default Textarea;