-
Notifications
You must be signed in to change notification settings - Fork 880
fix: list item in shadow DOM false positive #5029
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
Changes from 1 commit
ae15021
e209038
172687f
dcb4b3c
f8591ea
a803a86
ce50c66
3a1295a
0c28838
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,9 +61,32 @@ function getInvalidSelector( | |
| const role = getExplicitRole(vChild); | ||
| if (role) { | ||
| return validRoles.includes(role) ? false : selector + `[role=${role}]`; | ||
| } else { | ||
| return validNodeNames.includes(nodeName) ? false : selector + nodeName; | ||
| } | ||
|
|
||
| if (validNodeNames.includes(nodeName)) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check if a shadow host's shadow DOM root element is a valid child. | ||
| // This handles web components that wrap a valid element in their shadow DOM | ||
| // (e.g. <my-list-item> whose shadow DOM renders <li><slot></slot></li>). | ||
| if (vChild.actualNode?.shadowRoot) { | ||
| const shadowValid = vChild.children.some(shadowChild => { | ||
| if (shadowChild.actualNode?.nodeType !== 1) { | ||
| return false; | ||
| } | ||
| const shadowRole = getExplicitRole(shadowChild); | ||
| if (shadowRole) { | ||
| return validRoles.includes(shadowRole); | ||
| } | ||
| return validNodeNames.includes(shadowChild.props.nodeName); | ||
| }); | ||
| if (shadowValid) { | ||
| return false; | ||
| } | ||
| } | ||
|
Comment on lines
+73
to
+88
|
||
|
|
||
| return selector + nodeName; | ||
| } | ||
|
|
||
| function isDivGroup(vNode) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,6 +221,27 @@ describe('only-listitems', () => { | |
| }); | ||
|
|
||
| describe('shadow DOM', () => { | ||
| it('should return false when custom elements with shadow DOM <li> are slotted into a list', () => { | ||
| // Simulate <my-list-item> web components whose shadow DOM renders <li> | ||
| const item1 = document.createElement('my-list-item'); | ||
| item1.attachShadow({ mode: 'open' }).innerHTML = '<li><slot></slot></li>'; | ||
| item1.textContent = 'Item 1'; | ||
|
|
||
| const item2 = document.createElement('my-list-item'); | ||
| item2.attachShadow({ mode: 'open' }).innerHTML = '<li><slot></slot></li>'; | ||
| item2.textContent = 'Item 2'; | ||
|
|
||
| // Use a div (in possibleShadowRoots) as the outer shadow host, | ||
| // matching the pattern of the other shadow DOM tests in this suite | ||
| const host = document.createElement('div'); | ||
| host.appendChild(item1); | ||
| host.appendChild(item2); | ||
| host.attachShadow({ mode: 'open' }).innerHTML = '<ul><slot></slot></ul>'; | ||
|
|
||
| const checkArgs = checkSetup(host, 'ul'); | ||
| assert.isFalse(checkEvaluate.apply(checkContext, checkArgs)); | ||
| }); | ||
|
Comment on lines
+224
to
+243
|
||
|
|
||
dylanb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it('should return false in a shadow DOM pass', () => { | ||
| const node = document.createElement('div'); | ||
| node.innerHTML = '<li>My list item </li>'; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.