Describe the bug
I want to assert a given element inside a custom element has the focus. But calling await expect.element(...).toHaveFocus() on the focused descendant fails, telling the received element with focus is the custom element, not the descendant.
Looking at the codebase, the check appears to be htmlElement.ownerDocument.activeElement === htmlElement but maybe should be something like htmlElement.getRootNode().activeElement === htmlElement instead.
Reproduction
https://github.com/PolariTOON/no-focus-in-shadow-root-in-vitest (beware there is an "install" script to install a browser first)
System Info
Binaries:
Node: 26.9.0
npm: 11.19.1
Browsers:
Chrome for Testing 153.0.8010.12 (playwright chromium v1243)
npmPackages:
@vitest/browser-playwright: ^5.0.1 => 5.0.1
playwright: ^1.63.0 => 1.63.0
vitest: ^5.0.1 => 5.0.1
Used Package Manager
npm
Validations
Describe the bug
I want to assert a given element inside a custom element has the focus. But calling
await expect.element(...).toHaveFocus()on the focused descendant fails, telling the received element with focus is the custom element, not the descendant.Looking at the codebase, the check appears to be
htmlElement.ownerDocument.activeElement === htmlElementbut maybe should be something likehtmlElement.getRootNode().activeElement === htmlElementinstead.Reproduction
https://github.com/PolariTOON/no-focus-in-shadow-root-in-vitest (beware there is an
"install"script to install a browser first)System Info
Binaries: Node: 26.9.0 npm: 11.19.1 Browsers: Chrome for Testing 153.0.8010.12 (playwright chromium v1243) npmPackages: @vitest/browser-playwright: ^5.0.1 => 5.0.1 playwright: ^1.63.0 => 1.63.0 vitest: ^5.0.1 => 5.0.1Used Package Manager
npm
Validations