Skip to content

Clear existing focus when an HTML subtree becomes inert - #158

Draft
cowboyd wants to merge 1 commit into
mainfrom
codex/inert-focus-cleanup
Draft

cowboyd wants to merge 1 commit into
mainfrom
codex/inert-focus-cleanup

Conversation

@cowboyd

@cowboyd cowboyd commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Clears existing focus when the focused HTML element or one of its ancestors becomes inert. Previously, #119 prevented new focus inside inert subtrees but left document.activeElement pointing at an element that became inert after receiving focus.

The shared attribute-change handler now uses the internally stored focused element and the existing focus transition to clear focus. This covers .inert = true, setAttribute('inert', ''), and the other attribute mutation APIs. Namespaced attributes, non-HTML elements, and attribute removal do not trigger cleanup.

Draft notes:

  • Cleanup runs synchronously in the attribute handler. The HTML rendering update performs focus fixup during rendering. Consequently, toggling inert on and off before a frame can still blur in this draft; matching that timing needs rendering integration.
  • The cited upstream inert/dynamic-inert-on-focused-element.html remains blocked by missing Element.querySelector() and requestAnimationFrame support. Its six cases are not enabled or claimed as passing here.
  • This uses the existing focus transition and retains its handler-driven focus limitation, addressed separately in Add HTML focusability and preserve handler-driven focus changes #124.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@pkg-pr-new

pkg-pr-new Bot commented Dec 6, 2026

Copy link
Copy Markdown

commit: bc14c8b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant