Skip to content
This repository has been archived by the owner on Sep 15, 2020. It is now read-only.

[BUGFIX] Destroying an opened popover removes all attached listeners #66

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "6"
- "8"

sudo: false
dist: trusty
Expand Down
32 changes: 21 additions & 11 deletions addon/components/-private/base-pop-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ export default class BasePopMenuComponent extends Component {
let possibleRootElements = self.document.querySelectorAll(rootElementSelector);

assert(
`ember-popper with popperContainer selector "${rootElementSelector}" found ${
possibleRootElements.length
} possible containers when there should be exactly 1`,
`ember-popper with popperContainer selector "${rootElementSelector}" found` +
` ${possibleRootElements.length} possible containers when there should be exactly 1`,
possibleRootElements.length === 1
);

Expand Down Expand Up @@ -215,6 +214,8 @@ export default class BasePopMenuComponent extends Component {
this._triggerElement.removeEventListener('blur', this._closePopoverBlurHandler);
}

this._removePopperEventListeners();

this._triggerElement.removeAttribute('data-popover-trigger');

this._rootElement.removeEventListener('mouseup', this._handleBodyClick);
Expand Down Expand Up @@ -346,20 +347,29 @@ export default class BasePopMenuComponent extends Component {
*/
@action
popoverClosed() {
if (this.get('triggerEvent') === 'hover') {
this._popperElement.removeEventListener('mouseenter', this._openPopoverHandler);
this._popperElement.removeEventListener('mouseleave', this._closePopoverHandler);
this._popperElement.removeEventListener('focus', this._openPopoverHandler);
this._popperElement.removeEventListener('blur', this._closePopoverBlurHandler);
}

this._popperElement.removeEventListener('keydown', this._popperKeyHandler);
this._removePopperEventListeners();
this._triggerElement.classList.remove('is-active');
this._triggerElement.setAttribute('aria-expanded', 'false');
this._popperElement.removeAttribute('data-popover-content');
this._popperElement = null;
}

/**
* Remove all event listeners added in `popoverOpened`
*/
_removePopperEventListeners() {
if (this._popperElement) {
if (this.get('triggerEvent') === 'hover') {
this._popperElement.removeEventListener('mouseenter', this._openPopoverHandler);
this._popperElement.removeEventListener('mouseleave', this._closePopoverHandler);
this._popperElement.removeEventListener('focus', this._openPopoverHandler);
this._popperElement.removeEventListener('blur', this._closePopoverBlurHandler);
}

this._popperElement.removeEventListener('keydown', this._popperKeyHandler);
}
}

// ----- Event Handlers -----

/**
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@
"loader.js": "^4.2.3"
},
"engines": {
"node": "6.* || >= 7.*"
"node": "8.* || >= 10.*"
},
"ember-addon": {
"configPath": "tests/dummy/config"
},
"publishConfig": {
"@addepar:registry": "https://registry.npmjs.org/"
},
"resolutions": {
"ember-cli-page-object": "1.15.1"
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4037,7 +4037,7 @@ ember-cli-normalize-entity-name@^1.0.0:
dependencies:
silent-error "^1.0.0"

ember-cli-page-object@^1.15.0-beta.3:
ember-cli-page-object@1.15.1, ember-cli-page-object@^1.15.0-beta.3:
version "1.15.1"
resolved "https://registry.npmjs.org/ember-cli-page-object/-/ember-cli-page-object-1.15.1.tgz#da1f870638584b17e183d0014b4efb15465fadd5"
integrity sha512-/oUkiha+CLUNQGkQLHJ+mw9rm/V6Gi3VGgzKo7laEGZe6Mk8jl13otxEKWKI2NTJmL69fZxPPfFsqQqpzN+0UA==
Expand Down