I have an auto-sizing <textarea>
that's working great. I want to allow the user to manually resize it with the handlebar, at which point, auto-sizing becomes disabled. How do I capture the onresize
event? According to @types/react, onResize
isn't available.
Here's what I have so far.
import React, { PureComponent } from 'react';
export default class MyInput extends PureComponent {
constructor(props) {
super(props);
this.state = {
autosize: true,
value: ''
};
}
onChange(event) {
const input = event.target;
this.setState({ value: input.value });
if (this.state.autosize) {
const offset = input.offsetHeight - input.clientHeight;
input.style.height = 'auto';
input.style.height = input.scrollHeight + offset + 'px';
}
}
onResize() {
this.setState({ autosize: false });
}
render() {
return <textarea value={this.state.value} onChange={e => this.onChange(e)} />;
}
}