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

Commit 8f8ad78

Browse files
leibalehansl
authored andcommitted
fix(autocomplete): don't use $mdUtils.nextTick in handleHiddenChange (#9319)
to fix bug that disable the scroll when md-autocomplete removed from DOM immediately after choosing an option fix #9318
1 parent 660826b commit 8f8ad78

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

src/components/autocomplete/autocomplete.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,42 @@ describe('<md-autocomplete>', function() {
930930
expect($mdUtil.enableScrolling).toHaveBeenCalled();
931931
}));
932932

933+
it('removes the md-scroll-mask when md-autocomplete removed on change', inject(function($mdUtil, $timeout, $material) {
934+
spyOn($mdUtil, 'enableScrolling');
935+
936+
var scope = createScope();
937+
var template =
938+
'<div>' +
939+
' <md-autocomplete' +
940+
' ng-if="!removeAutocomplete"' +
941+
' md-selected-item="selectedItem"' +
942+
' md-search-text="searchText"' +
943+
' md-items="item in match(searchText)"' +
944+
' md-item-text="item.display"' +
945+
' placeholder="placeholder">' +
946+
' <md-item-template>{{item.display}}</md-item-template>' +
947+
' <md-not-found>Sorry, not found...</md-not-found>' +
948+
' </md-autocomplete>' +
949+
'</div>';
950+
var element = compile(template, scope);
951+
var ctrl = element.children().controller('mdAutocomplete');
952+
953+
$material.flushOutstandingAnimations();
954+
955+
// Focus our input
956+
ctrl.focus();
957+
958+
// Set our search text to a value to make md-scroll-mask added to DOM
959+
scope.searchText = 'searchText';
960+
961+
$timeout.flush();
962+
963+
// Set removeAutocomplete to false to remove the md-autocomplete
964+
scope.$apply('removeAutocomplete = true');
965+
966+
expect($mdUtil.enableScrolling).toHaveBeenCalled();
967+
}));
968+
933969
it('should initialize the search text with an empty string', inject(function($mdUtil, $timeout, $material) {
934970
var scope = createScope();
935971

src/components/autocomplete/js/autocompleteController.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,16 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
262262
positionDropdown();
263263

264264
if (elements) {
265-
$mdUtil.nextTick(function () {
266-
$mdUtil.disableScrollAround(elements.ul);
267-
enableWrapScroll = disableElementScrollEvents(angular.element(elements.wrap));
268-
}, false, $scope);
265+
$mdUtil.disableScrollAround(elements.ul);
266+
enableWrapScroll = disableElementScrollEvents(angular.element(elements.wrap));
269267
}
270268
} else if (hidden && !oldHidden) {
271-
$mdUtil.nextTick(function () {
272-
$mdUtil.enableScrolling();
269+
$mdUtil.enableScrolling();
273270

274-
if (enableWrapScroll) {
275-
enableWrapScroll();
276-
enableWrapScroll = null;
277-
}
278-
}, false, $scope);
271+
if (enableWrapScroll) {
272+
enableWrapScroll();
273+
enableWrapScroll = null;
274+
}
279275
}
280276
}
281277

0 commit comments

Comments
 (0)