Skip to content

fix(material-experimental/mdc-chips): error on IE and Edge due to unsupported classList #18074

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
Jan 8, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/material-experimental/mdc-chips/chip-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
let currentElement = event.target as HTMLElement | null;

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

Expand Down
5 changes: 4 additions & 1 deletion src/material-experimental/mdc-chips/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ export class MatChip extends _MatChipMixinBase implements AfterContentInit, Afte
addClassToLeadingIcon: (className) => this.leadingIcon.setClass(className, true),
removeClassFromLeadingIcon: (className) => this.leadingIcon.setClass(className, false),
eventTargetHasClass: (target: EventTarget | null, className: string) => {
return target ? (target as Element).classList.contains(className) : false;
// We need to null check the `classList`, because IE and Edge don't support it on SVG elements
// and Edge seems to throw for ripple elements, because they're outside the DOM.
return (target && (target as Element).classList) ?
(target as Element).classList.contains(className) : false;
},
notifyInteraction: () => this.interaction.emit(this.id),
notifySelection: () => {
Expand Down