Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/ClickOutside/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,27 @@ class ClickOutside extends React.Component {
document.removeEventListener('mousedown', this.handleDocumentClick);
}

setClickedInsideStatus = (status) => {
this.isClickedInside = status || false;
}

handleDocumentClick = (e) => {
if (this.isClickedInside) {
this.isClickedInside = false;
this.setClickedInsideStatus(false);
return;
}

this.props.onClickOutside(e);
};

handleMouseDown = () => {
this.isClickedInside = true;
this.setClickedInsideStatus(true);
};

render() {
return React.cloneElement(
React.Children.only(this.props.children), {
onMouseDownCapture: this.handleMouseDown
}
);
return React.cloneElement(React.Children.only(this.props.children), {
onMouseDownCapture: this.handleMouseDown
});
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/SelectOptionGroup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class SelectOptionGroup extends Component {
if (isInModal) {
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();

// ClickOutside set isClickedInside to true via mouse down capture first
// Set isClickedInside to false after mouse down
this.clickOutsideRef && this.clickOutsideRef.setClickedInsideStatus(false);
}
};

Expand Down Expand Up @@ -177,7 +181,7 @@ class SelectOptionGroup extends Component {
};
}
return (
<ClickOutside onClickOutside={this.props.onClickOutside}>
<ClickOutside ref={ref => this.clickOutsideRef = ref} onClickOutside={this.props.onClickOutside}>
<div
className={classnames('option-group', className ? 'option-group-' + className : '', {
'pt-0': isShowSelected,
Expand Down