mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-26 18:09:40 +08:00
Add closestParent
This commit is contained in:
parent
03eef0485e
commit
a9e5980fea
2 changed files with 8 additions and 6 deletions
|
|
@ -1092,7 +1092,7 @@ qs(".pageAccount")?.onChild(
|
|||
async (event) => {
|
||||
const target = new ElementWithUtils(event.childTarget as HTMLElement);
|
||||
const resultId: string = target
|
||||
.closest("tr")
|
||||
.closestParent("tr")
|
||||
?.getAttribute("data-id") as string;
|
||||
if (target.hasClass("loading")) return;
|
||||
if (target.hasClass("disabled")) return;
|
||||
|
|
|
|||
|
|
@ -553,12 +553,14 @@ export class ElementWithUtils<T extends HTMLElement = HTMLElement> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the first element matching a selector, starting from this.native and going
|
||||
up through its parents
|
||||
* Get the first parent that matches a selector
|
||||
*/
|
||||
closest(selector: string): ElementWithUtils | null {
|
||||
const el = this.native.closest(selector) as HTMLElement;
|
||||
return el !== null ? new ElementWithUtils(el) : null;
|
||||
|
||||
closestParent(selector: string): ElementWithUtils | null {
|
||||
const closestParent = this.native.parentElement?.closest(
|
||||
selector,
|
||||
) as HTMLElement;
|
||||
return closestParent !== null ? new ElementWithUtils(closestParent) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue