Skip to content

Commit ae5bca2

Browse files
crisbetommalerba
authored andcommitted
chore(autocomplete): switch to OnPush change detection (#5546)
* Switches `md-autocomplete` to `OnPush` change detection. * Fixes a newly-introduced test failure. Relates to #5035.
1 parent 9ab0c90 commit ae5bca2

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,17 +763,19 @@ describe('MdAutocomplete', () => {
763763
.toEqual(32, `Expected panel to reveal the sixth option.`);
764764
}));
765765

766-
it('should scroll to active options on UP arrow', fakeAsync(() => {
767-
tick();
768-
const scrollContainer =
769-
document.querySelector('.cdk-overlay-pane .mat-autocomplete-panel')!;
766+
it('should scroll to active options on UP arrow', async(() => {
767+
fixture.whenStable().then(() => {
768+
const scrollContainer =
769+
document.querySelector('.cdk-overlay-pane .mat-autocomplete-panel')!;
770770

771-
fixture.componentInstance.trigger._handleKeydown(UP_ARROW_EVENT);
772-
tick();
773-
fixture.detectChanges();
771+
fixture.componentInstance.trigger._handleKeydown(UP_ARROW_EVENT);
772+
fixture.detectChanges();
774773

775-
// Expect option bottom minus the panel height (528 - 256 = 272)
776-
expect(scrollContainer.scrollTop).toEqual(272, `Expected panel to reveal last option.`);
774+
fixture.whenStable().then(() => {
775+
// Expect option bottom minus the panel height (528 - 256 = 272)
776+
expect(scrollContainer.scrollTop).toEqual(272, `Expected panel to reveal last option.`);
777+
});
778+
});
777779
}));
778780

779781
it('should not scroll to active options that are fully in the panel', fakeAsync(() => {

src/lib/autocomplete/autocomplete.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ViewChild,
1818
ViewEncapsulation,
1919
ChangeDetectorRef,
20+
ChangeDetectionStrategy,
2021
} from '@angular/core';
2122
import {MdOption} from '../core';
2223
import {ActiveDescendantKeyManager} from '../core/a11y/activedescendant-key-manager';
@@ -35,6 +36,7 @@ export type AutocompletePositionY = 'above' | 'below';
3536
templateUrl: 'autocomplete.html',
3637
styleUrls: ['autocomplete.css'],
3738
encapsulation: ViewEncapsulation.None,
39+
changeDetection: ChangeDetectionStrategy.OnPush,
3840
exportAs: 'mdAutocomplete',
3941
host: {
4042
'class': 'mat-autocomplete'

0 commit comments

Comments
 (0)