Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 145ce63

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(menu): clean up the backdrop if the menu got destroyed mid-animation
The menu backdrop wasn't being cleaned up, if the menu got destroyed while it was animating. Fixes #8727. Closes #8766
1 parent 13734c0 commit 145ce63

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/components/menu/js/menuController.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout, $r
2323
this.init = function init(setMenuContainer, opts) {
2424
opts = opts || {};
2525
menuContainer = setMenuContainer;
26-
26+
2727
// Default element for ARIA attributes has the ngClick or ngMouseenter expression
2828
triggerElement = $element[0].querySelector(prefixer.buildSelector(['ng-click', 'ng-mouseenter']));
2929
triggerElement.setAttribute('aria-expanded', 'false');
@@ -44,7 +44,11 @@ function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout, $r
4444
'aria-haspopup': 'true'
4545
});
4646

47-
$scope.$on('$destroy', this.disableHoverListener);
47+
$scope.$on('$destroy', angular.bind(this, function() {
48+
this.disableHoverListener();
49+
$mdMenu.destroy();
50+
}));
51+
4852
menuContainer.on('$destroy', function() {
4953
$mdMenu.destroy();
5054
});

src/components/menu/js/menuServiceProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function MenuProvider($$interimElementProvider) {
7474
* and backdrop
7575
*/
7676
function onRemove(scope, element, opts) {
77-
opts.cleanupInteraction();
77+
opts.cleanupInteraction && opts.cleanupInteraction();
7878
opts.cleanupResizing();
7979
opts.hideBackdrop();
8080

@@ -437,7 +437,7 @@ function MenuProvider($$interimElementProvider) {
437437
}
438438

439439
var rtl = ($mdUtil.bidi() == 'rtl');
440-
440+
441441
switch (positionMode.left) {
442442
case 'target':
443443
position.left = existingOffsets.left + originNodeRect.left - alignTargetRect.left;

src/components/menu/menu.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ describe('material.components.menu', function() {
114114
expect($document.find('md-backdrop').length).toBe(0);
115115
}));
116116

117+
it('should remove the backdrop if the container scope got destroyed', inject(function($document, $rootScope) {
118+
var scope = $rootScope.$new();
119+
var menu = setup(null, null, scope);
120+
121+
openMenu(menu);
122+
expect($document.find('md-backdrop').length).not.toBe(0);
123+
124+
scope.$destroy();
125+
expect($document.find('md-backdrop').length).toBe(0);
126+
}));
127+
117128
it('closes on backdrop click', inject(function($document) {
118129

119130
var menu = setup();

0 commit comments

Comments
 (0)