Skip to content

Commit

Permalink
Listening to document events only when the dropdown is open | Fixes l…
Browse files Browse the repository at this point in the history
  • Loading branch information
matuzalemsteles committed May 30, 2018
1 parent 457206f commit 0754d60
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/clay-dropdown/src/ClayDropdownBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ class ClayDropdownBase extends ClayComponent {
*/
created() {
this._eventHandler = new EventHandler();
this._eventHandlerKeyup = new EventHandler();

this._eventHandler.add(
dom.on(document, 'click', this._handleDocClick.bind(this), true),
dom.on(document, 'touchend', this._handleDocClick.bind(this), true),
);
}

/**
Expand All @@ -61,7 +55,7 @@ class ClayDropdownBase extends ClayComponent {
*/
_close() {
this.expanded = false;
this._eventHandlerKeyup.removeAllListeners();
this._eventHandler.removeAllListeners();
}

/**
Expand Down Expand Up @@ -218,8 +212,20 @@ class ClayDropdownBase extends ClayComponent {
*/
syncExpanded() {
if (this.expanded) {
this._eventHandlerKeyup.add(
dom.on(document, 'keyup', this._handleKeyup.bind(this), true)
this._eventHandler.add(
dom.on(
document,
'click',
this._handleDocClick.bind(this),
true
),
dom.on(document, 'keyup', this._handleKeyup.bind(this), true),
dom.on(
document,
'touchend',
this._handleDocClick.bind(this),
true
)
);
}
}
Expand Down

0 comments on commit 0754d60

Please sign in to comment.