Skip to content

Commit b32d8d1

Browse files
kseamonandrewseguin
authored andcommitted
perf(multiple): Remove IE 11 cruft from table, column-resize, and popover-edit. (#23900)
(cherry picked from commit c46ece0)
1 parent d7fe423 commit b32d8d1

File tree

3 files changed

+5
-33
lines changed

3 files changed

+5
-33
lines changed

src/cdk-experimental/column-resize/column-resize.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {AfterViewInit, Directive, ElementRef, NgZone, OnDestroy} from '@angular/
1010
import {fromEvent, merge, Subject} from 'rxjs';
1111
import {filter, map, mapTo, pairwise, startWith, take, takeUntil} from 'rxjs/operators';
1212

13-
import {_closest, _matches} from '@angular/cdk-experimental/popover-edit';
13+
import {_closest} from '@angular/cdk-experimental/popover-edit';
1414

1515
import {ColumnResizeNotifier, ColumnResizeNotifierSource} from './column-resize-notifier';
1616
import {HEADER_CELL_SELECTOR, RESIZE_OVERLAY_SELECTOR} from './selectors';
@@ -80,11 +80,7 @@ export abstract class ColumnResize implements AfterViewInit, OnDestroy {
8080
.subscribe(this.eventDispatcher.headerCellHovered);
8181
fromEvent<MouseEvent>(element, 'mouseleave')
8282
.pipe(
83-
filter(
84-
event =>
85-
!!event.relatedTarget &&
86-
!_matches(event.relatedTarget as Element, RESIZE_OVERLAY_SELECTOR),
87-
),
83+
filter(event => !!(event.relatedTarget as Element)?.matches(RESIZE_OVERLAY_SELECTOR)),
8884
mapTo(null),
8985
takeUntil(this.destroyed),
9086
)

src/cdk-experimental/popover-edit/polyfill.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
/** IE 11 compatible matches implementation. */
10-
export function matches(element: Element, selector: string): boolean {
11-
return element.matches
12-
? element.matches(selector)
13-
: (element as any)['msMatchesSelector'](selector);
14-
}
15-
16-
/** IE 11 compatible closest implementation that is able to start from non-Element Nodes. */
9+
/** closest implementation that is able to start from non-Element Nodes. */
1710
export function closest(
1811
element: EventTarget | Element | null | undefined,
1912
selector: string,
@@ -27,22 +20,5 @@ export function closest(
2720
curr = curr.parentNode;
2821
}
2922

30-
return (
31-
curr &&
32-
((hasNativeClosest
33-
? curr.closest(selector)
34-
: polyfillClosest(curr, selector)) as Element | null)
35-
);
23+
return curr?.closest(selector) ?? null;
3624
}
37-
38-
/** Polyfill for browsers without Element.closest. */
39-
function polyfillClosest(element: Element, selector: string): Element | null {
40-
let curr: Node | null = element;
41-
while (curr != null && !(curr instanceof Element && matches(curr, selector))) {
42-
curr = curr.parentNode;
43-
}
44-
45-
return (curr || null) as Element | null;
46-
}
47-
48-
const hasNativeClosest = !!Element.prototype.closest;

src/cdk-experimental/popover-edit/public-api.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ export * from './table-directives';
1717

1818
// Private to Angular Components
1919
export {CELL_SELECTOR as _CELL_SELECTOR} from './constants';
20-
export {closest as _closest, matches as _matches} from './polyfill';
20+
export {closest as _closest} from './polyfill';

0 commit comments

Comments
 (0)