From 5ae5f439e11b004218d10ad934ff0ff0795dd978 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 17 Nov 2026 11:56:55 -0600 Subject: [PATCH 1/2] Preserve inert focus handling on the native WPT stack --- .changeset/dom-inert.md | 5 +++++ packages/ui/src/dom.ts | 24 ++++++++++++++++++++++++ packages/ui/wpt.config.ts | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 .changeset/dom-inert.md diff --git a/.changeset/dom-inert.md b/.changeset/dom-inert.md new file mode 100644 index 0000000..c986096 --- /dev/null +++ b/.changeset/dom-inert.md @@ -0,0 +1,5 @@ +--- +'@clack/ui': minor +--- + +Reflect the inert attribute on HTML elements and prevent programmatic focus inside inert subtrees. diff --git a/packages/ui/src/dom.ts b/packages/ui/src/dom.ts index fb49058..b22cfa7 100644 --- a/packages/ui/src/dom.ts +++ b/packages/ui/src/dom.ts @@ -789,10 +789,28 @@ export class HTMLElement extends Element { #onfocus: EventListener | undefined = undefined; #onblur: EventListener | undefined = undefined; + get inert(): boolean { + return this.hasAttributeNS(null, 'inert'); + } + + set inert(value: boolean) { + if (value) { + this.setAttributeNS(null, 'inert', ''); + } else { + this.removeAttributeNS(null, 'inert'); + } + } + focus(): void { if (!this.isConnected) { return; } + // inert nodes don't get focus + for (const node of lineage(this)) { + if (node instanceof HTMLElement && node.inert) { + return; + } + } this.ownerDocument._setActiveElement(this); } @@ -915,3 +933,9 @@ function dispatchEvent( } } } + +function* lineage(node: Node): Iterable { + for (let current: Node | null = node; current; current = current.parentNode) { + yield current; + } +} diff --git a/packages/ui/wpt.config.ts b/packages/ui/wpt.config.ts index 3f63743..6cb4773 100644 --- a/packages/ui/wpt.config.ts +++ b/packages/ui/wpt.config.ts @@ -71,6 +71,8 @@ const config: WPTConfig = { 'html/editing/focus/focus-management/focusing-disconnected-noop.html': true, 'html/editing/focus/focus-management/focusing-focused-noop.html': true, 'html/interaction/focus/focus-management/focus-events.html': true, + 'inert/inert-node-is-unfocusable.html': true, + 'inert/nested-inert-unfocusable.html': true, 'dom/nodes/Document-createTextNode.html': true, 'dom/nodes/Document-createElement.html': [/^createElement\(.*\) in HTML document$/], 'dom/nodes/Document-createElementNS.html': [ From de0f23847848fc83332bc4ad6797d92234c80bf6 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 17 Nov 2026 20:08:17 -0600 Subject: [PATCH 2/2] Scope inert coverage to supported fixture capabilities --- packages/ui/wpt.config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ui/wpt.config.ts b/packages/ui/wpt.config.ts index 6cb4773..e8fe0f4 100644 --- a/packages/ui/wpt.config.ts +++ b/packages/ui/wpt.config.ts @@ -71,8 +71,10 @@ const config: WPTConfig = { 'html/editing/focus/focus-management/focusing-disconnected-noop.html': true, 'html/editing/focus/focus-management/focusing-focused-noop.html': true, 'html/interaction/focus/focus-management/focus-events.html': true, - 'inert/inert-node-is-unfocusable.html': true, + // inert/inert-node-is-unfocusable.html requires testdriver click setup: + // real layout, hit testing, and an input backend are not available yet. 'inert/nested-inert-unfocusable.html': true, + 'html/dom/reflection-misc.html': [/^html\.inert:/], 'dom/nodes/Document-createTextNode.html': true, 'dom/nodes/Document-createElement.html': [/^createElement\(.*\) in HTML document$/], 'dom/nodes/Document-createElementNS.html': [