Skip to content

Commit 70ad3db

Browse files
committed
Add live Document.forms collection
1 parent 74bb2cc commit 70ad3db

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎.changeset/dom-document-forms.md‎

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 a live, same-object `Document.forms` collection with named lookup of HTML form elements.

‎packages/ui/src/dom.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ export class Document extends Node {
357357
declare readonly ownerDocument: null;
358358

359359
readonly implementation: DOMImplementation;
360+
readonly #forms = new HTMLCollection(() =>
361+
findElements(
362+
Array.from(this.childNodes),
363+
(element) => element.namespaceURI === HTML_NS && element.localName === 'form',
364+
),
365+
);
360366

361367
#factory: (...params: ConstructorParameters<typeof Element>) => Element;
362368

@@ -403,6 +409,10 @@ export class Document extends Node {
403409
return null;
404410
}
405411

412+
get forms(): HTMLCollection {
413+
return this.#forms;
414+
}
415+
406416
querySelector(selector: string): Element | null {
407417
return querySelector(Array.from(this.childNodes), selector);
408418
}

‎packages/ui/wpt.config.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ const config: WPTConfig<Document> = {
229229
// Four other cases require innerHTML or outerHTML mutation.
230230
],
231231
'html/dom/documents/dom-tree-accessors/Document.body.html': ["existing document's body"],
232+
'html/dom/documents/dom-tree-accessors/document.forms.html': [
233+
'document.forms',
234+
'document.forms.item with string arg',
235+
'document.forms with empty string',
236+
'Document.forms should be a live collection',
237+
],
232238
'dom/nodes/Document-getElementsByTagName.html': [
233239
'Caching is allowed',
234240
"Shouldn't be able to set unsigned properties on a HTMLCollection (non-strict mode)",

0 commit comments

Comments
 (0)