From ae5bca261abe5a5dfc2e9fc79df7e2558bfcfa16 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Sun, 9 Jul 2017 03:57:45 +0200 Subject: [PATCH] chore(autocomplete): switch to OnPush change detection (#5546) * 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 6ad3319b624..dbc981d60a9 100644 --- a/src/lib/autocomplete/autocomplete.spec.ts +++ b/src/lib/autocomplete/autocomplete.spec.ts @@ -763,17 +763,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 03939f6b7b5..0937d1ee2f9 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'