fix(drag-drop): error on IE when customizing root element (#13279)

Fixes an error being thrown on IE when the root element is customized. The error comes from the fact that IE doesn't support `Element.prototype.matches`, but it does support `msMatchesSelector`.
This commit is contained in:
Kristiyan Kostadinov
2018-09-25 16:06:59 +02:00
committed by Jeremy Elbourn
parent 70dd33f143
commit e1071f03fa
+4 -1
View File
@@ -670,10 +670,13 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
/** Gets the root draggable element, based on the `rootElementSelector`. */
private _getRootElement(): HTMLElement {
if (this.rootElementSelector) {
const selector = this.rootElementSelector;
let currentElement = this.element.nativeElement.parentElement as HTMLElement | null;
while (currentElement) {
if (currentElement.matches(this.rootElementSelector)) {
// IE doesn't support `matches` so we have to fall back to `msMatchesSelector`.
if (currentElement.matches ? currentElement.matches(selector) :
currentElement.msMatchesSelector(selector)) {
return currentElement;
}