Skip to content

Commit e036473

Browse files
crisbetojelbourn
authored andcommitted
chore(select): switch to OnPush change detection (#5682)
Switches `md-select` to use `OnPush` change detection and adds a few necessary `markForCheck` calls. Relates to #5035.
1 parent c82aca9 commit e036473

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lib/select/select.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
ChangeDetectorRef,
2525
Attribute,
2626
OnInit,
27-
Inject
27+
Inject,
28+
ChangeDetectionStrategy,
2829
} from '@angular/core';
2930
import {MdOption, MdOptionSelectionChange, MdOptgroup} from '../core/option/index';
3031
import {ENTER, SPACE, UP_ARROW, DOWN_ARROW, HOME, END} from '../core/keyboard/keycodes';
@@ -122,6 +123,7 @@ export const _MdSelectMixinBase = mixinColor(mixinDisabled(MdSelectBase), 'prima
122123
styleUrls: ['select.css'],
123124
inputs: ['color', 'disabled'],
124125
encapsulation: ViewEncapsulation.None,
126+
changeDetection: ChangeDetectionStrategy.OnPush,
125127
host: {
126128
'role': 'listbox',
127129
'[attr.tabindex]': 'tabIndex',
@@ -386,6 +388,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
386388
this._calculateOverlayPosition();
387389
this._placeholderState = this._floatPlaceholderState();
388390
this._panelOpen = true;
391+
this._changeDetectorRef.markForCheck();
389392
}
390393

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

403+
this._changeDetectorRef.markForCheck();
400404
this.focus();
401405
}
402406
}
@@ -443,6 +447,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
443447
*/
444448
setDisabledState(isDisabled: boolean): void {
445449
this.disabled = isDisabled;
450+
this._changeDetectorRef.markForCheck();
446451
}
447452

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

487493
/** Handles the keyboard interactions of a closed select. */
@@ -519,6 +525,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
519525
this.onClose.emit();
520526
this._panelDoneAnimating = false;
521527
this.overlayDir.offsetX = 0;
528+
this._changeDetectorRef.markForCheck();
522529
}
523530
}
524531

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

533541
/**
@@ -537,6 +545,7 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On
537545
_onBlur() {
538546
if (!this.disabled && !this.panelOpen) {
539547
this._onTouched();
548+
this._changeDetectorRef.markForCheck();
540549
}
541550
}
542551

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

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

845854
/** Returns the aria-label of the select component. */

0 commit comments

Comments
 (0)