Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Closed
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
8 changes: 6 additions & 2 deletions src/components/menu/js/menuController.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout, $r
this.init = function init(setMenuContainer, opts) {
opts = opts || {};
menuContainer = setMenuContainer;

// Default element for ARIA attributes has the ngClick or ngMouseenter expression
triggerElement = $element[0].querySelector(prefixer.buildSelector(['ng-click', 'ng-mouseenter']));
triggerElement.setAttribute('aria-expanded', 'false');
Expand All @@ -44,7 +44,11 @@ function MenuController($mdMenu, $attrs, $element, $scope, $mdUtil, $timeout, $r
'aria-haspopup': 'true'
});

$scope.$on('$destroy', this.disableHoverListener);
$scope.$on('$destroy', angular.bind(this, function() {
this.disableHoverListener();
$mdMenu.destroy();
}));

menuContainer.on('$destroy', function() {
$mdMenu.destroy();
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/menu/js/menuServiceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function MenuProvider($$interimElementProvider) {
* and backdrop
*/
function onRemove(scope, element, opts) {
opts.cleanupInteraction();
opts.cleanupInteraction && opts.cleanupInteraction();
opts.cleanupResizing();
opts.hideBackdrop();

Expand Down Expand Up @@ -437,7 +437,7 @@ function MenuProvider($$interimElementProvider) {
}

var rtl = ($mdUtil.bidi() == 'rtl');

switch (positionMode.left) {
case 'target':
position.left = existingOffsets.left + originNodeRect.left - alignTargetRect.left;
Expand Down
11 changes: 11 additions & 0 deletions src/components/menu/menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ describe('material.components.menu', function() {
expect($document.find('md-backdrop').length).toBe(0);
}));

it('should remove the backdrop if the container scope got destroyed', inject(function($document, $rootScope) {
var scope = $rootScope.$new();
var menu = setup(null, null, scope);

openMenu(menu);
expect($document.find('md-backdrop').length).not.toBe(0);

scope.$destroy();
expect($document.find('md-backdrop').length).toBe(0);
}));

it('closes on backdrop click', inject(function($document) {

var menu = setup();
Expand Down