Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dom-query-selector-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clack/ui': minor
---

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.
10 changes: 9 additions & 1 deletion packages/ui/src/dom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* oxlint-disable bombshell-dev/no-generic-error -- Web IDL requires TypeError for missing arguments. */
/* oxlint-disable bombshell-dev/exported-function-async -- DOM apis are synchronous. */

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

querySelectorAll(selector: string): Element[] {
if (arguments.length === 0) {
throw new TypeError('querySelectorAll requires a selector');
}
const selectors = `${selector}`;
return querySelectorAll(Array.from(this.childNodes), selectors);
}

getElementsByTagName(qualifiedName: string): HTMLCollection {
if (arguments.length === 0) {
throw new TypeError('getElementsByTagName requires a qualified name');
Expand Down
9 changes: 9 additions & 0 deletions packages/ui/wpt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ const config: WPTConfig<Document> = {
'html/dom/reflection-misc.html': [/^html\.inert:/, /^html\.tabIndex:/],
'html/dom/reflection-forms.html': [/^button\.tabIndex:/],
'html/interaction/focus/sequential-focus-navigation-and-the-tabindex-attribute/focus-tabindex-default-value.html': true,
'dom/nodes/NodeList-Iterable.html': [/^NodeList /],
'dom/nodes/ParentNode-querySelector-All-comma-selector.html': [
'Basic comma-separated selector',
],
'dom/nodes/ParentNode-querySelector-invalid-comment-like.html': [
'querySelectorAll throws SyntaxError for comment-like selector',
],
'dom/nodes/ParentNode-querySelectorAll-case-insensitive-attribute-flag.html': true,
'dom/nodes/ParentNode-querySelectorAll-nested-not-has.html': true,
'dom/nodes/Document-createEvent.https.html': [
/^(?:Event|Events|HTMLEvents|SVGEvents) should be an alias for Event\.$/i,
/^createEvent\('(?:Event|Events|HTMLEvents|SVGEvents)'\) should be initialized correctly\.$/i,
Expand Down
Loading