chore(): add stronger typing to the tapclick utility (#25316)

This commit is contained in:
Liam DeBeasi
2022-05-19 09:31:21 -04:00
committed by GitHub
parent 48a3794c16
commit 51f3179bcc

View File

@ -57,7 +57,7 @@ export const startTapClick = (config: Config) => {
} }
}; };
const pointerDown = (ev: any) => { const pointerDown = (ev: UIEvent) => {
if (activatableEle || isScrolling()) { if (activatableEle || isScrolling()) {
return; return;
} }
@ -165,9 +165,17 @@ export const startTapClick = (config: Config) => {
doc.addEventListener('contextmenu', onContextMenu, true); doc.addEventListener('contextmenu', onContextMenu, true);
}; };
const getActivatableTarget = (ev: any): any => { const getActivatableTarget = (ev: UIEvent): any => {
if (ev.composedPath) { if (ev.composedPath) {
const path = ev.composedPath() as HTMLElement[]; /**
* composedPath returns EventTarget[]. However,
* objects other than Element can be targets too.
* For example, AudioContext can be a target. In this
* case, we know that the event is a UIEvent so we
* can assume that the path will contain either Element
* or ShadowRoot.
*/
const path = ev.composedPath() as Element[] | ShadowRoot[];
for (let i = 0; i < path.length - 2; i++) { for (let i = 0; i < path.length - 2; i++) {
const el = path[i]; const el = path[i];
if (!(el instanceof ShadowRoot) && el.classList.contains('ion-activatable')) { if (!(el instanceof ShadowRoot) && el.classList.contains('ion-activatable')) {
@ -175,7 +183,7 @@ const getActivatableTarget = (ev: any): any => {
} }
} }
} else { } else {
return ev.target.closest('.ion-activatable'); return (ev.target as Element).closest('.ion-activatable');
} }
}; };