blob: dbe6ad2d724a4249ff538c5cd5e743b519ea8e88 [file] [log] [blame]
class Input extends Component {
constructor(props) {
super(props);
this.inputRef = findRef(".filterableInput");
this.onChangeFn = withEvent(this.inputRef, "input", this.onInputChange);
this.onKeydownFn = withEvent(this.inputRef, "keydown", this.onKeydown);
}
onInputChange = ({ currentTarget: { value } }) => {
this.props.onInputChange(value);
};
onKeydown = (e) => {
// if the user hits Escape while typing in the filter input,
// clear the filter and un-focus the input
if (e.keyCode == 27) {
this.inputRef.value = '';
this.onInputChange(e);
setTimeout(() => this.inputRef.blur(), 1);
}
}
componentWillUnmount() {
if (this.onChangeFn) {
this.onChangeFn();
this.onKeydownFn();
}
}
}