Skip to content

Commit db84ffe

Browse files
committed
Add Document.querySelectorAll
1 parent 99d3573 commit db84ffe

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,6 +1,6 @@
11
/* oxlint-disable bombshell-dev/no-generic-error -- Web IDL requires TypeError for missing arguments. */
22

3-
import { getElementById, querySelector } from './css-select.ts';
3+
import { getElementById, querySelector, querySelectorAll } from './css-select.ts';
44
import { asciiUppercase, asciiLowercase } from './ascii.ts';
55
import { NamedNodeMap } from './named-node-map.ts';
66
import {
@@ -335,6 +335,14 @@ export class Document extends Node {
335335
return querySelector(Array.from(this.childNodes), selector);
336336
}
337337

338+
querySelectorAll(selector: string): Element[] {
339+
if (arguments.length === 0) {
340+
throw new TypeError('querySelectorAll requires a selector');
341+
}
342+
const selectors = `${selector}`;
343+
return querySelectorAll(Array.from(this.childNodes), selectors);
344+
}
345+
338346
getElementById(id: string): Element | null {
339347
if (arguments.length === 0) {
340348
throw new TypeError('getElementById requires an ID');

‎packages/ui/wpt.config.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ const config: WPTConfig = {
7777
'html/dom/reflection-misc.html': [/^html\.inert:/, /^html\.tabIndex:/],
7878
'html/dom/reflection-forms.html': [/^button\.tabIndex:/],
7979
'html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html': true,
80+
'dom/nodes/NodeList-Iterable.html': [/^NodeList /],
81+
'dom/nodes/ParentNode-querySelector-All-comma-selector.html': [
82+
'Basic comma-separated selector',
83+
],
84+
'dom/nodes/ParentNode-querySelector-invalid-comment-like.html': [
85+
'querySelectorAll throws SyntaxError for comment-like selector',
86+
],
87+
'dom/nodes/ParentNode-querySelectorAll-case-insensitive-attribute-flag.html': true,
88+
'dom/nodes/ParentNode-querySelectorAll-nested-not-has.html': true,
8089
'dom/nodes/Document-createTextNode.html': true,
8190
'dom/nodes/Document-createElement.html': [/^createElement\(.*\) in HTML document$/],
8291
'dom/nodes/Document-createElementNS.html': [

0 commit comments

Comments
 (0)