Skip to content

Commit 9e8e3c3

Browse files
committed
Fixed issue with manual enableOnClickOutside calls - which resulted with duplicated handlers
1 parent f9765ec commit 9e8e3c3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as DOMHelpers from './dom-helpers';
44
import uid from './uid';
55

66
const handlersMap = {};
7+
const enabledInstances = {};
78

89
const touchEvents = ['touchstart', 'touchmove'];
910
export const IGNORE_CLASS_NAME = 'ignore-react-onclickoutside';
@@ -107,7 +108,8 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
107108
* for clicks and touches outside of this element.
108109
*/
109110
enableOnClickOutside = () => {
110-
if (typeof document === 'undefined') return;
111+
if (typeof document === 'undefined' || enabledInstances[this._uid]) return;
112+
enabledInstances[this._uid] = true;
111113

112114
let events = this.props.eventTypes;
113115
if (!events.forEach) {
@@ -154,7 +156,9 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
154156
* for clicks and touches outside of this element.
155157
*/
156158
disableOnClickOutside = () => {
159+
delete enabledInstances[this._uid];
157160
const fn = handlersMap[this._uid];
161+
158162
if (fn && typeof document !== 'undefined') {
159163
let events = this.props.eventTypes;
160164
if (!events.forEach) {
@@ -171,10 +175,12 @@ export default function onClickOutsideHOC(WrappedComponent, config) {
171175
* Pass-through render
172176
*/
173177
render() {
174-
var props = Object.keys(this.props).filter(prop => prop !== 'excludeScrollbar').reduce((props, prop) => {
175-
props[prop] = this.props[prop];
176-
return props;
177-
}, {});
178+
var props = Object.keys(this.props)
179+
.filter(prop => prop !== 'excludeScrollbar')
180+
.reduce((props, prop) => {
181+
props[prop] = this.props[prop];
182+
return props;
183+
}, {});
178184

179185
if (WrappedComponent.prototype.isReactComponent) {
180186
props.ref = this.getRef;

0 commit comments

Comments
 (0)