diff --git a/src/components/fileBrowser.jsx b/src/components/fileBrowser.jsx index 7c81c81..e6ecc01 100644 --- a/src/components/fileBrowser.jsx +++ b/src/components/fileBrowser.jsx @@ -223,14 +223,15 @@ class FileBrowser extends Component { componentDidMount = () => { this.setState({ prevPath: this.props.currentPath, files: this.props.files }) + + // add click event listener for closing menu + window.addEventListener('click', this.handleWindowClick) } componentDidUpdate = () => { // if the component was just created set the path if (this.state.prevPath === "" && this.props.currentPath !== "") return this.setState({ prevPath: this.props.currentPath, files: this.props.files }) - // add click event listener for closing menu - window.addEventListener('click', () => this.setState({ renderMenu: false })) // the path changed if (this.props.currentPath !== this.state.prevPath) { @@ -248,6 +249,12 @@ class FileBrowser extends Component { } } + componentWillUnmount = () => { + window.removeEventListener('click', this.handleWindowClick) + } + + handleWindowClick = () => this.setState({ renderMenu: false }) + // used to filter the files handleInputChange({target}) { const value = target.type === 'checkbox' ? target.checked : target.value