diff --git a/src/components/autocomplete/autocomplete.spec.js b/src/components/autocomplete/autocomplete.spec.js index 0d5634f2c6d..e42cb6e2578 100644 --- a/src/components/autocomplete/autocomplete.spec.js +++ b/src/components/autocomplete/autocomplete.spec.js @@ -365,6 +365,49 @@ describe('', function() { element.remove(); })); + it('should remove the md-scroll-mask on cleanup', inject(function($mdUtil, $timeout, $material) { + spyOn($mdUtil, 'enableScrolling'); + + var scope = createScope(); + var template = + '' + + ' {{item.display}}' + + ' Sorry, not found...' + + ''; + var element = compile(template, scope); + var ctrl = element.controller('mdAutocomplete'); + + $material.flushOutstandingAnimations(); + + // Focus our input + ctrl.focus(); + + // Set our search text to a value that we know doesn't exist + scope.searchText = 'somethingthatdoesnotexist'; + + // Run our initial flush + $timeout.flush(); + waitForVirtualRepeat(element); + + // Wait for the next tick when the values will be updated + $timeout.flush(); + + expect(ctrl.hidden).toBeFalsy(); + + // Make sure we wrap up anything and remove the element + $timeout.flush(); + element.remove(); + scope.$destroy(); + + // Should be hidden on once the scope is destroyed to ensure proper cleanup (like md-scroll-mask is removed from the DOM) + expect($mdUtil.enableScrolling).toHaveBeenCalled(); + })); + it('should ensure the parent scope digests along with the current scope', inject(function($timeout, $material) { var scope = createScope(null, {bang: 'boom'}); var template = diff --git a/src/components/autocomplete/js/autocompleteController.js b/src/components/autocomplete/js/autocompleteController.js index 0efaa9d03af..7b86aed5701 100644 --- a/src/components/autocomplete/js/autocompleteController.js +++ b/src/components/autocomplete/js/autocompleteController.js @@ -176,6 +176,10 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming, * Removes any events or leftover elements created by this controller */ function cleanup () { + if(!ctrl.hidden) { + $mdUtil.enableScrolling(); + } + angular.element($window).off('resize', positionDropdown); if ( elements ){ var items = 'ul scroller scrollContainer input'.split(' ');