Skip to content

Commit 406c058

Browse files
authored
feat: allow using an array of selectors for selection functions (#69)
2 parents 8994eb1 + af55998 commit 406c058

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export class Component<T extends HTMLElement = HTMLElement> extends ElementCompo
6060
* @param selectors
6161
* @typeParam T Component element type
6262
*/
63-
public select<T extends HTMLElement = HTMLElement>(selectors: string): Component<T> | null {
64-
const element = this.node.querySelector<T>(selectors);
63+
public select<T extends HTMLElement = HTMLElement>(...selectors: string[]): Component<T> | null {
64+
const element = this.node.querySelector<T>(selectors.join(","));
6565
if (element == null) return null;
6666
return new Component<T>(element);
6767
}
@@ -73,8 +73,8 @@ export class Component<T extends HTMLElement = HTMLElement> extends ElementCompo
7373
* @param selectors
7474
* @typeParam T Component element type
7575
*/
76-
public selectAll<T extends HTMLElement = HTMLElement>(selectors: string): Component<T>[] {
77-
return [...this.node.querySelectorAll<T>(selectors)].map(e => new Component<T>(e));
76+
public selectAll<T extends HTMLElement = HTMLElement>(...selectors: string[]): Component<T>[] {
77+
return [...this.node.querySelectorAll<T>(selectors.join(","))].map(e => new Component<T>(e));
7878
}
7979

8080
/**
@@ -83,8 +83,8 @@ export class Component<T extends HTMLElement = HTMLElement> extends ElementCompo
8383
* @param selectors
8484
* @typeParam T Component element type
8585
*/
86-
public closest<T extends HTMLElement = HTMLElement>(selectors: string): Component<T> | null {
87-
const element = this.node.closest<T>(selectors);
86+
public closest<T extends HTMLElement = HTMLElement>(...selectors: string[]): Component<T> | null {
87+
const element = this.node.closest<T>(selectors.join(","));
8888
if (element == null) return null;
8989
return new Component<T>(element);
9090
}
@@ -94,8 +94,8 @@ export class Component<T extends HTMLElement = HTMLElement> extends ElementCompo
9494
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_selectors CSS selector}, or group of CSS selectors.
9595
* @param selectors
9696
*/
97-
public is(selectors: string): boolean {
98-
return this.node.matches(selectors);
97+
public is(...selectors: string[]): boolean {
98+
return this.node.matches(selectors.join(","));
9999
}
100100

101101
/**

0 commit comments

Comments
 (0)