chore(autocomplete): switch to OnPush change detection (#5546)

* Switches `md-autocomplete` to `OnPush` change detection.
* Fixes a newly-introduced test failure.

Relates to #5035.
This commit is contained in:
Kristiyan Kostadinov
2017-07-09 03:57:45 +02:00
committed by mmalerba
parent 9ab0c90493
commit ae5bca261a
2 changed files with 13 additions and 9 deletions
+11 -9
View File
@@ -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(() => {
+2
View File
@@ -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'