Skip to content

perf(material-experimental/mdc-chips): avoid checking the DOM on each change detection #18929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/material-experimental/mdc-chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ const _MatChipMixinBase:
'[class.mat-mdc-chip-highlighted]': 'highlighted',
'[class.mat-mdc-chip-with-avatar]': 'leadingIcon',
'[class.mat-mdc-chip-with-trailing-icon]': 'trailingIcon || removeIcon',
'[class.mat-mdc-basic-chip]': '_isBasicChip()',
'[class.mat-mdc-standard-chip]': '!_isBasicChip()',
'[class.mat-mdc-basic-chip]': '_isBasicChip',
'[class.mat-mdc-standard-chip]': '!_isBasicChip',
'[class._mat-animation-noopable]': '_animationsDisabled',
'[id]': 'id',
'[attr.disabled]': 'disabled || null',
Expand All @@ -133,6 +133,9 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte

readonly HANDLED_KEYS: number[] = [];

/** Whether this chip is a basic (unstyled) chip. */
readonly _isBasicChip: boolean;

/** Whether the chip has focus. */
protected _hasFocusInternal = false;

Expand Down Expand Up @@ -316,6 +319,9 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
super(_elementRef);
this._chipFoundation = new MDCChipFoundation(this._chipAdapter);
this._animationsDisabled = animationMode === 'NoopAnimations';
this._isBasicChip = _elementRef.nativeElement.hasAttribute(this.basicChipAttrName) ||
_elementRef.nativeElement.tagName.toLowerCase() === this.basicChipAttrName;

}

ngAfterContentInit() {
Expand Down Expand Up @@ -382,13 +388,6 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
}
}

/** Whether this chip is a basic (unstyled) chip. */
_isBasicChip() {
const element = this._elementRef.nativeElement as HTMLElement;
return element.hasAttribute(this.basicChipAttrName) ||
element.tagName.toLowerCase() === this.basicChipAttrName;
}

/** Sets whether the given CSS class should be applied to the MDC chip. */
private _setMdcClass(cssClass: string, active: boolean) {
const classes = this._elementRef.nativeElement.classList;
Expand All @@ -405,7 +404,7 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte

/** Whether or not the ripple should be disabled. */
_isRippleDisabled(): boolean {
return this.disabled || this.disableRipple || this._isBasicChip();
return this.disabled || this.disableRipple || this._isBasicChip;
}

static ngAcceptInputType_disabled: BooleanInput;
Expand Down