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

Commit 042086f

Browse files
cah-alexsukhodolskyThomasBurleson
authored andcommitted
fix(autocomplete): clean up md-scroll-mask element on destroy
* added test Fixes #7049 Fixes #7128 Closes #7291
1 parent 3d97ede commit 042086f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/components/autocomplete/autocomplete.spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,49 @@ describe('<md-autocomplete>', function() {
365365
element.remove();
366366
}));
367367

368+
it('should remove the md-scroll-mask on cleanup', inject(function($mdUtil, $timeout, $material) {
369+
spyOn($mdUtil, 'enableScrolling');
370+
371+
var scope = createScope();
372+
var template =
373+
'<md-autocomplete' +
374+
' md-selected-item="selectedItem"' +
375+
' md-search-text="searchText"' +
376+
' md-items="item in match(searchText)"' +
377+
' md-item-text="item.display"' +
378+
' placeholder="placeholder">' +
379+
' <md-item-template>{{item.display}}</md-item-template>' +
380+
' <md-not-found>Sorry, not found...</md-not-found>' +
381+
'</md-autocomplete>';
382+
var element = compile(template, scope);
383+
var ctrl = element.controller('mdAutocomplete');
384+
385+
$material.flushOutstandingAnimations();
386+
387+
// Focus our input
388+
ctrl.focus();
389+
390+
// Set our search text to a value that we know doesn't exist
391+
scope.searchText = 'somethingthatdoesnotexist';
392+
393+
// Run our initial flush
394+
$timeout.flush();
395+
waitForVirtualRepeat(element);
396+
397+
// Wait for the next tick when the values will be updated
398+
$timeout.flush();
399+
400+
expect(ctrl.hidden).toBeFalsy();
401+
402+
// Make sure we wrap up anything and remove the element
403+
$timeout.flush();
404+
element.remove();
405+
scope.$destroy();
406+
407+
// Should be hidden on once the scope is destroyed to ensure proper cleanup (like md-scroll-mask is removed from the DOM)
408+
expect($mdUtil.enableScrolling).toHaveBeenCalled();
409+
}));
410+
368411
it('should ensure the parent scope digests along with the current scope', inject(function($timeout, $material) {
369412
var scope = createScope(null, {bang: 'boom'});
370413
var template =

src/components/autocomplete/js/autocompleteController.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
176176
* Removes any events or leftover elements created by this controller
177177
*/
178178
function cleanup () {
179+
if(!ctrl.hidden) {
180+
$mdUtil.enableScrolling();
181+
}
182+
179183
angular.element($window).off('resize', positionDropdown);
180184
if ( elements ){
181185
var items = 'ul scroller scrollContainer input'.split(' ');

0 commit comments

Comments
 (0)