Skip to content
Closed
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
6 changes: 5 additions & 1 deletion packages/ui/src/dom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* oxlint-disable bombshell-dev/no-generic-error -- Web IDL requires TypeError for missing arguments. */

import { querySelector } from './css-select.ts';
import { compile, querySelector } 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 @@ -633,6 +633,10 @@ export class Element extends Node {
return this.#attributes.toggleAttribute(name, force);
}

matches(selector: string): boolean {
return compile(selector)(this);
}

get id(): string {
return this.#attributes.getNamedItemNS(null, 'id')?.value ?? '';
}
Expand Down
16 changes: 16 additions & 0 deletions packages/ui/wpt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ const config: WPTConfig = {
'dom/nodes/CharacterData-data.html': true,
'dom/nodes/CharacterData-remove.html': true,
'dom/nodes/Element-remove.html': true,
'dom/nodes/Element-matches-namespaced-elements.html': [
'empty string namespace, matches',
'has a namespace, matches',
],
'dom/nodes/Element-matches-active-pseudo-class.html': [
'Regular div should not match :active by default',
'Button should not match :active by default',
'Link should not match :active by default',
],
'dom/nodes/ParentNode-querySelector-invalid-comment-like.html': [
'matches throws SyntaxError for comment-like selector',
],
'css/selectors/child-indexed-pseudo-class.html': [
// Defer the four detached :nth-*(n) cases until https://github.com/fb55/css-select/issues/1945 is fixed.
/^Expected DIV element to (?!.*\(n\)).* with matches$/,
],
'dom/nodes/Element-setAttribute.html': true,
'dom/nodes/Element-setAttributeNodeNS.html': true,
'dom/nodes/Element-removeAttribute.html': true,
Expand Down
Loading