forked from newthuhole/hole_thu_frontend
fix event listener not removed
This commit is contained in:
@@ -270,17 +270,22 @@ export class ReplyForm extends Component {
|
|||||||
};
|
};
|
||||||
this.on_change_bound=this.on_change.bind(this);
|
this.on_change_bound=this.on_change.bind(this);
|
||||||
this.area_ref=this.props.area_ref||React.createRef();
|
this.area_ref=this.props.area_ref||React.createRef();
|
||||||
|
this.global_keypress_handler_bound=this.global_keypress_handler.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
global_keypress_handler(e) {
|
||||||
document.addEventListener('keypress',(e)=>{
|
|
||||||
if(e.code==='Enter' && !e.ctrlKey && !e.altKey && ['input','textarea'].indexOf(e.target.tagName.toLowerCase())===-1) {
|
if(e.code==='Enter' && !e.ctrlKey && !e.altKey && ['input','textarea'].indexOf(e.target.tagName.toLowerCase())===-1) {
|
||||||
if(this.area_ref.current) {
|
if(this.area_ref.current) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.area_ref.current.focus();
|
this.area_ref.current.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
document.addEventListener('keypress',this.global_keypress_handler_bound);
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('keypress',this.global_keypress_handler_bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
on_change(value) {
|
on_change(value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user