Skip to content

Commit

Permalink
fix(autocomplete): clean up md-scroll-mask element on destroy
Browse files Browse the repository at this point in the history
* added test

Fixes angular#7049
Fixes angular#7128
  • Loading branch information
cah-alexsukhodolsky committed Feb 25, 2016
1 parent 6c42ac7 commit da5a656
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,49 @@ describe('<md-autocomplete>', 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 =
'<md-autocomplete' +
' md-selected-item="selectedItem"' +
' md-search-text="searchText"' +
' md-items="item in match(searchText)"' +
' md-item-text="item.display"' +
' placeholder="placeholder">' +
' <md-item-template>{{item.display}}</md-item-template>' +
' <md-not-found>Sorry, not found...</md-not-found>' +
'</md-autocomplete>';
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 =
Expand Down
4 changes: 4 additions & 0 deletions src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand Down

0 comments on commit da5a656

Please sign in to comment.