Skip to content

Commit

Permalink
chore(select): switch to OnPush change detection
Browse files Browse the repository at this point in the history
Switches `md-select` to use `OnPush` change detection and adds a few necessary `markForCheck` calls.

Relates to #5035.
  • Loading branch information
crisbeto authored and jelbourn committed Jul 13, 2017
1 parent a34787d commit 3b29353
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
ChangeDetectorRef,
Attribute,
OnInit,
Inject
Inject,
ChangeDetectionStrategy,
} from '@angular/core';
import {MdOption, MdOptionSelectionChange, MdOptgroup} from '../core/option/index';
import {ENTER, SPACE, UP_ARROW, DOWN_ARROW, HOME, END} from '../core/keyboard/keycodes';
Expand Down Expand Up @@ -122,6 +123,7 @@ export const _MdSelectMixinBase = mixinColor(mixinDisabled(MdSelectBase), 'prima
styleUrls: ['select.css'],
inputs: ['color', 'disabled'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: {
'role': 'listbox',
'[attr.tabindex]': 'tabIndex',
Expand Down Expand Up @@ -386,6 +388,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
this._calculateOverlayPosition();
this._placeholderState = this._floatPlaceholderState();
this._panelOpen = true;
this._changeDetectorRef.markForCheck();
}

/** Closes the overlay panel and focuses the host element. */
Expand All @@ -397,6 +400,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
this._placeholderState = '';
}

this._changeDetectorRef.markForCheck();
this.focus();
}
}
Expand Down Expand Up @@ -443,6 +447,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
*/
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
this._changeDetectorRef.markForCheck();
}

/** Whether or not the overlay panel is open. */
Expand Down Expand Up @@ -482,6 +487,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
*/
private _setTriggerWidth(): void {
this._triggerWidth = this._getTriggerRect().width;
this._changeDetectorRef.markForCheck();
}

/** Handles the keyboard interactions of a closed select. */
Expand Down Expand Up @@ -519,6 +525,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
this.onClose.emit();
this._panelDoneAnimating = false;
this.overlayDir.offsetX = 0;
this._changeDetectorRef.markForCheck();
}
}

Expand All @@ -528,6 +535,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
*/
_onFadeInDone(): void {
this._panelDoneAnimating = this.panelOpen;
this._changeDetectorRef.markForCheck();
}

/**
Expand All @@ -537,6 +545,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
_onBlur() {
if (!this.disabled && !this.panelOpen) {
this._onTouched();
this._changeDetectorRef.markForCheck();
}
}

Expand Down Expand Up @@ -741,7 +750,8 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
* overflow. The selection arrow is 9px wide, add 4px of padding = 13
*/
private _setValueWidth() {
this._selectedValueWidth = this._triggerWidth - 13;
this._selectedValueWidth = this._triggerWidth - 13;
this._changeDetectorRef.markForCheck();
}

/**
Expand Down Expand Up @@ -838,8 +848,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
* Determines the CSS `opacity` of the placeholder element.
*/
_getPlaceholderOpacity(): string {
return (this.floatPlaceholder !== 'never' || this._selectionModel.isEmpty()) ?
'1' : '0';
return (this.floatPlaceholder !== 'never' || this._selectionModel.isEmpty()) ? '1' : '0';
}

/** Returns the aria-label of the select component. */
Expand Down

0 comments on commit 3b29353

Please sign in to comment.