From af0fab0bb69e049171d63a04a67a583bd0de9eaa Mon Sep 17 00:00:00 2001 From: crisbeto Date: Thu, 6 Jul 2017 20:19:59 +0200 Subject: [PATCH] chore(autocomplete): switch to OnPush change detection * Switches `md-autocomplete` to `OnPush` change detection. * Fixes a newly-introduced test failure. Relates to #5035. --- src/lib/autocomplete/autocomplete.spec.ts | 20 +++++++++++--------- src/lib/autocomplete/autocomplete.ts | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/autocomplete/autocomplete.spec.ts b/src/lib/autocomplete/autocomplete.spec.ts index 1ec919562190..8a856c2340fe 100644 --- a/src/lib/autocomplete/autocomplete.spec.ts +++ b/src/lib/autocomplete/autocomplete.spec.ts @@ -765,17 +765,19 @@ describe('MdAutocomplete', () => { .toEqual(32, `Expected panel to reveal the sixth option.`); })); - it('should scroll to active options on UP arrow', fakeAsync(() => { - tick(); - const scrollContainer = - document.querySelector('.cdk-overlay-pane .mat-autocomplete-panel')!; + it('should scroll to active options on UP arrow', async(() => { + fixture.whenStable().then(() => { + const scrollContainer = + document.querySelector('.cdk-overlay-pane .mat-autocomplete-panel')!; - fixture.componentInstance.trigger._handleKeydown(UP_ARROW_EVENT); - tick(); - fixture.detectChanges(); + fixture.componentInstance.trigger._handleKeydown(UP_ARROW_EVENT); + fixture.detectChanges(); - // Expect option bottom minus the panel height (528 - 256 = 272) - expect(scrollContainer.scrollTop).toEqual(272, `Expected panel to reveal last option.`); + fixture.whenStable().then(() => { + // Expect option bottom minus the panel height (528 - 256 = 272) + expect(scrollContainer.scrollTop).toEqual(272, `Expected panel to reveal last option.`); + }); + }); })); it('should not scroll to active options that are fully in the panel', fakeAsync(() => { diff --git a/src/lib/autocomplete/autocomplete.ts b/src/lib/autocomplete/autocomplete.ts index 03939f6b7b53..0937d1ee2f99 100644 --- a/src/lib/autocomplete/autocomplete.ts +++ b/src/lib/autocomplete/autocomplete.ts @@ -17,6 +17,7 @@ import { ViewChild, ViewEncapsulation, ChangeDetectorRef, + ChangeDetectionStrategy, } from '@angular/core'; import {MdOption} from '../core'; import {ActiveDescendantKeyManager} from '../core/a11y/activedescendant-key-manager'; @@ -35,6 +36,7 @@ export type AutocompletePositionY = 'above' | 'below'; templateUrl: 'autocomplete.html', styleUrls: ['autocomplete.css'], encapsulation: ViewEncapsulation.None, + changeDetection: ChangeDetectionStrategy.OnPush, exportAs: 'mdAutocomplete', host: { 'class': 'mat-autocomplete'