fix(chrome): focus descends into the shadow root

document.activeElement names the host, not the node focused inside it, so
a Compose-for-wasm app that mounts its tree in a shadow root reported
focus on div#app forever. confirmFocus could never be satisfied and every
InputText step aborted the run after three tries.

selectAllScript already descends the boundary; the tree builder did not.
This commit is contained in:
pj committed 2026-08-17 23:44:21 +05:30
1 parent 0bfd194332
commit 071f9c7f52
3 files changed
+81 -1

No files matched your search

+8 -1
View File
@@ -642,6 +642,13 @@ func (d *Driver) Hierarchy(ctx context.Context) (string, error) {
', [onclick]'));
const editableSet = new Set(deepQuery(
'input, textarea, [contenteditable]').filter(isEditableElement));
// Descended once for the whole dump, for the reason selectAllScript above
// descends: document.activeElement names the shadow host, so a Compose for
// Web app reported focus on its mount element and never on the field.
let focusedElement = document.activeElement;
while (focusedElement && focusedElement.shadowRoot && focusedElement.shadowRoot.activeElement) {
focusedElement = focusedElement.shadowRoot.activeElement;
}
function buildTree(el, isRoot) {
const rect = el.getBoundingClientRect();
// Every attribute the markup wrote, keyed as written, which is what attrs
@@ -704,7 +711,7 @@ func (d *Driver) Hierarchy(ctx context.Context) (string, error) {
children: children,
clickable: isClickable || null,
enabled: isEnabled(el) || null,
focused: document.activeElement === el || null,
focused: focusedElement === el || null,
// A component keeps what it likes in these two properties, so what is
// emitted is the flag the field declares and not the property's value.
checked: el.checked === true || null,