I have a modal box which has a couple buttons inside. On click outside I want that modal close. I've added ref to the parent element and it's works fine, everything closing when you click outside. But if you click on that buttons inside this modal box , it closes too. How to detect child elements inside this ref and do not allow close modal box?
public handleClickoutside() {
this.props.showMessage()
}
public handleClick = (e) => {
if (this.DOMArrowBox.current !== e.target) {
this.handleClickoutside()
}
}
public componentWillMount() {
document.addEventListener("mousedown", this.handleClick, false)
}
public componentWillUnmount() {
document.removeEventListener("mousedown", this.handleClick, false)
}
<div className={this.props.className} ref={this.DOMArrowBox}>
<Social />
<CallMe className="arrow__box-button" open={this.props.open} />
<Close
className="arrow-button_close"
onClick={this.props.showMessage}
/>
</div>