Skip to content

Commit 5fccd24

Browse files
crisbetommalerba
authored andcommitted
fix(material-experimental/mdc-chips): error on IE and Edge due… (#18074)
Fixes an error that was being thrown on click for the MDC-based chips, because we were trying to interact with the `classList` of a ripple. It seems like Edge doesn't support `classList` on elements outside the DOM.
1 parent 7b7e633 commit 5fccd24

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/material-experimental/mdc-chips/chip-set.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
294294
let currentElement = event.target as HTMLElement | null;
295295

296296
while (currentElement && currentElement !== this._elementRef.nativeElement) {
297-
if (currentElement.classList.contains('mdc-chip')) {
297+
// Null check the classList, because IE and Edge don't support it on all elements.
298+
if (currentElement.classList && currentElement.classList.contains('mdc-chip')) {
298299
return true;
299300
}
300301

src/material-experimental/mdc-chips/chip.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
251251
addClassToLeadingIcon: (className) => this.leadingIcon.setClass(className, true),
252252
removeClassFromLeadingIcon: (className) => this.leadingIcon.setClass(className, false),
253253
eventTargetHasClass: (target: EventTarget | null, className: string) => {
254-
return target ? (target as Element).classList.contains(className) : false;
254+
// We need to null check the `classList`, because IE and Edge don't support it on SVG elements
255+
// and Edge seems to throw for ripple elements, because they're outside the DOM.
256+
return (target && (target as Element).classList) ?
257+
(target as Element).classList.contains(className) : false;
255258
},
256259
notifyInteraction: () => this.interaction.emit(this.id),
257260
notifySelection: () => {

0 commit comments

Comments
 (0)