Skip to content

Commit 1666fe0

Browse files
authored
fix: close selector via click outside (#371)
1 parent 7b9a7ee commit 1666fe0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/ClickOutside/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,27 @@ class ClickOutside extends React.Component {
6262
document.removeEventListener('mousedown', this.handleDocumentClick);
6363
}
6464

65+
setClickedInsideStatus = (status) => {
66+
this.isClickedInside = status || false;
67+
}
68+
6569
handleDocumentClick = (e) => {
6670
if (this.isClickedInside) {
67-
this.isClickedInside = false;
71+
this.setClickedInsideStatus(false);
6872
return;
6973
}
7074

7175
this.props.onClickOutside(e);
7276
};
7377

7478
handleMouseDown = () => {
75-
this.isClickedInside = true;
79+
this.setClickedInsideStatus(true);
7680
};
7781

7882
render() {
79-
return React.cloneElement(
80-
React.Children.only(this.props.children), {
81-
onMouseDownCapture: this.handleMouseDown
82-
}
83-
);
83+
return React.cloneElement(React.Children.only(this.props.children), {
84+
onMouseDownCapture: this.handleMouseDown
85+
});
8486
}
8587
}
8688

src/SelectOptionGroup/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class SelectOptionGroup extends Component {
9797
if (isInModal) {
9898
e.stopPropagation();
9999
e.nativeEvent.stopImmediatePropagation();
100+
101+
// ClickOutside set isClickedInside to true via mouse down capture first
102+
// Set isClickedInside to false after mouse down
103+
this.clickOutsideRef && this.clickOutsideRef.setClickedInsideStatus(false);
100104
}
101105
};
102106

@@ -177,7 +181,7 @@ class SelectOptionGroup extends Component {
177181
};
178182
}
179183
return (
180-
<ClickOutside onClickOutside={this.props.onClickOutside}>
184+
<ClickOutside ref={ref => this.clickOutsideRef = ref} onClickOutside={this.props.onClickOutside}>
181185
<div
182186
className={classnames('option-group', className ? 'option-group-' + className : '', {
183187
'pt-0': isShowSelected,

0 commit comments

Comments
 (0)