diff --git a/src/material-experimental/mdc-chips/chip.ts b/src/material-experimental/mdc-chips/chip.ts index 07fb72b6db80..2866120ad652 100644 --- a/src/material-experimental/mdc-chips/chip.ts +++ b/src/material-experimental/mdc-chips/chip.ts @@ -263,8 +263,15 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte }, notifyTrailingIconInteraction: () => this.removeIconInteraction.emit(this.id), notifyRemoval: () => this.removed.emit({chip: this}), - getComputedStyleValue: propertyName => - window.getComputedStyle(this._elementRef.nativeElement).getPropertyValue(propertyName), + getComputedStyleValue: propertyName => { + // This function is run when a chip is removed so it might be + // invoked during server-side rendering. Add some extra checks just in case. + if (typeof window !== 'undefined' && window) { + const getComputedStyle = window.getComputedStyle(this._elementRef.nativeElement); + return getComputedStyle.getPropertyValue(propertyName); + } + return ''; + }, setStyleProperty: (propertyName: string, value: string) => { this._elementRef.nativeElement.style.setProperty(propertyName, value); }, @@ -339,12 +346,13 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte _listenToRemoveIconInteraction() { this.removeIcon.interaction .pipe(takeUntil(this._destroyed)) - .subscribe((event) => { + .subscribe(event => { // The MDC chip foundation calls stopPropagation() for any trailing icon interaction // event, even ones it doesn't handle, so we want to avoid passing it keyboard events - // for which we have a custom handler. - if (this.disabled || (event instanceof KeyboardEvent && - this.HANDLED_KEYS.indexOf(event.keyCode) !== -1)) { + // for which we have a custom handler. Note that we assert the type of the event using + // the `type`, because `instanceof KeyboardEvent` can throw during server-side rendering. + if (this.disabled || (event.type.startsWith('key') && + this.HANDLED_KEYS.indexOf((event as KeyboardEvent).keyCode) !== -1)) { return; } this._chipFoundation.handleTrailingIconInteraction(event); diff --git a/src/universal-app/kitchen-sink-mdc/kitchen-sink-mdc.html b/src/universal-app/kitchen-sink-mdc/kitchen-sink-mdc.html index 52cdc40c4d57..e3b5f7f95e79 100644 --- a/src/universal-app/kitchen-sink-mdc/kitchen-sink-mdc.html +++ b/src/universal-app/kitchen-sink-mdc/kitchen-sink-mdc.html @@ -27,8 +27,18 @@