2016-09-12 11:14:21 +02:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
|
|
|
|
export default class StringControl extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
this.updateHeight();
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:26:49 -02:00
|
|
|
handleChange = (e) => {
|
2016-09-12 11:14:21 +02:00
|
|
|
this.props.onChange(e.target.value);
|
|
|
|
this.updateHeight();
|
2016-10-03 14:25:27 +02:00
|
|
|
};
|
2016-09-12 11:14:21 +02:00
|
|
|
|
|
|
|
updateHeight() {
|
|
|
|
if (this.element.scrollHeight > this.element.clientHeight) {
|
2017-01-19 14:26:49 -02:00
|
|
|
this.element.style.height = `${ this.element.scrollHeight }px`;
|
2016-09-12 11:14:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 14:26:49 -02:00
|
|
|
handleRef = (ref) => {
|
2016-09-12 11:14:21 +02:00
|
|
|
this.element = ref;
|
2016-10-03 14:25:27 +02:00
|
|
|
};
|
2016-09-12 11:14:21 +02:00
|
|
|
|
|
|
|
render() {
|
2017-01-19 14:26:49 -02:00
|
|
|
return <textarea ref={this.handleRef} id={this.props.forID} value={this.props.value || ''} onChange={this.handleChange} />;
|
2016-09-12 11:14:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringControl.propTypes = {
|
|
|
|
onChange: PropTypes.func.isRequired,
|
2017-06-04 17:20:40 +02:00
|
|
|
forID: PropTypes.string,
|
2016-09-12 11:14:21 +02:00
|
|
|
value: PropTypes.node,
|
|
|
|
};
|