Skip to content

Fix "Get Text" to retrieve the correct value for ShadowRoot using slot. #13218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2024
Merged
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
4 changes: 3 additions & 1 deletion javascript/atoms/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,9 @@ bot.dom.appendVisibleTextLinesFromNodeInComposedDom_ = function(
} else {
shadowChildren = contentElem.assignedNodes();
}
goog.array.forEach(shadowChildren, function(node) {
const childrenToTraverse =
shadowChildren.length > 0 ? shadowChildren : contentElem.childNodes;
goog.array.forEach(childrenToTraverse, function (node) {
bot.dom.appendVisibleTextLinesFromNodeInComposedDom_(
node, lines, shown, whitespace, textTransform);
});
Expand Down
31 changes: 28 additions & 3 deletions javascript/atoms/test/text_shadow_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,31 @@

let customEl = findElement({ tagName: 'open-shadow-element' });
let text = getText(customEl);
assertEquals(text, 'full link text');
assertEquals('full link text', text);
}

function testTextForSlotValueInShadowDOM() {
setCustomElement('<slot><span>full</span></slot>');

let customEl = findElement({ id: 'custom-text' });
let text = getText(customEl);
assertEquals('custom', text);
}

function testTextForSlotAndExtraValueInShadowDOM() {
setCustomElement('<slot><span>full</span></slot> text');

let customEl = findElement({ id: 'custom-text' });
let text = getText(customEl);
assertEquals('custom text', text);
}

function testTextForDefaultSlotValueInShadowDOM() {
setCustomElement('<slot><span>full</span></slot> text');

let customEl = findElement({ tagName: 'open-shadow-element' });
let text = getText(customEl);
assertEquals('full text', text);
}

function testHiddenTextInShadowDOM() {
Expand All @@ -81,21 +105,22 @@

let customEl = findElement({ tagName: 'open-shadow-element' });
let text = getText(customEl);
assertEquals(text, 'full text');
assertEquals('full text', text);
}

function testTextForElementWithinClosedShadowDOM() {
setCustomElement('<a href=# id=linkText>full link text</a>', 'closed');
let customEl = findElement({ tagName: 'closed-shadow-element' });
let innerEl = findElement({ css: 'a' }, customEl._shadowRoot);
let text = getText(innerEl);
assertEquals(text, 'full link text');
assertEquals('full link text', text);
}
</script>
</head>

<body>
<open-shadow-element></open-shadow-element>
<open-shadow-element id="custom-text">custom</open-shadow-element>
<closed-shadow-element></closed-shadow-element>
</body>

Expand Down