Skip to content

Commit 74bb2cc

Browse files
committed
Add Document.querySelectorAll
1 parent d028ab4 commit 74bb2cc

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clack/ui': minor
3+
---
4+
5+
Add [Document.querySelectorAll()](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll) using the existing CSS selector engine. Queries return a snapshot array of matching elements in document order.

‎packages/ui/src/dom.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* oxlint-disable bombshell-dev/no-generic-error -- Web IDL requires TypeError for missing arguments. */
22
/* oxlint-disable bombshell-dev/exported-function-async -- DOM apis are synchronous. */
33

4-
import { findElement, findElements, querySelector } from './css-select.ts';
4+
import { findElement, findElements, querySelector, querySelectorAll } from './css-select.ts';
55
import { asciiUppercase, asciiLowercase } from './ascii.ts';
66
import { NamedNodeMap } from './named-node-map.ts';
77
import { HTMLCollection } from './html-collection.ts';
@@ -407,6 +407,14 @@ export class Document extends Node {
407407
return querySelector(Array.from(this.childNodes), selector);
408408
}
409409

410+
querySelectorAll(selector: string): Element[] {
411+
if (arguments.length === 0) {
412+
throw new TypeError('querySelectorAll requires a selector');
413+
}
414+
const selectors = `${selector}`;
415+
return querySelectorAll(Array.from(this.childNodes), selectors);
416+
}
417+
410418
getElementsByTagName(qualifiedName: string): HTMLCollection {
411419
if (arguments.length === 0) {
412420
throw new TypeError('getElementsByTagName requires a qualified name');

‎packages/ui/wpt.config.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ const config: WPTConfig<Document> = {
265265
'html/dom/reflection-misc.html': [/^html\.inert:/, /^html\.tabIndex:/],
266266
'html/dom/reflection-forms.html': [/^button\.tabIndex:/],
267267
'html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html': true,
268+
'dom/nodes/NodeList-Iterable.html': [/^NodeList /],
269+
'dom/nodes/ParentNode-querySelector-All-comma-selector.html': [
270+
'Basic comma-separated selector',
271+
],
272+
'dom/nodes/ParentNode-querySelector-invalid-comment-like.html': [
273+
'querySelectorAll throws SyntaxError for comment-like selector',
274+
],
275+
'dom/nodes/ParentNode-querySelectorAll-case-insensitive-attribute-flag.html': true,
276+
'dom/nodes/ParentNode-querySelectorAll-nested-not-has.html': true,
268277
'dom/nodes/Document-createEvent.https.html': [
269278
/^(?:Event|Events|HTMLEvents|SVGEvents) should be an alias for Event\.$/i,
270279
/^createEvent\('(?:Event|Events|HTMLEvents|SVGEvents)'\) should be initialized correctly\.$/i,

0 commit comments

Comments
 (0)