fix(dom): detect visible content for slotted slot elements#14269
Closed
fix(dom): detect visible content for slotted slot elements#14269
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes hasVisibleContent for <slot> elements so visibility checks account for slotted/assigned nodes (including nested slots via flatten: true), preventing false “empty” results in nested slot scenarios.
Changes:
- Update
hasVisibleContentto detect visible content fromHTMLSlotElement.assignedNodes({ flatten: true }). - Add a unit test covering the slot-assigned-content path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/components/src/utils/dom.ts |
Adds slot-aware visible-content detection using flattened assigned nodes. |
packages/components/src/utils/dom.browser.spec.ts |
Adds test coverage for hasVisibleContent() when called with a slot element. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue: #14270
Summary
This change fixes a nested slot edge case where visibility checks fail when a slot is assigned into another slot.
Problem
The helper that checks whether an element has visible content only inspected child nodes.
For slot elements, visible content can come from assigned nodes rather than direct children, so nested slot usage could be reported as empty.
Solution
Updated hasVisibleContent to handle slot elements by checking assigned nodes with flatten enabled.
If any assigned node is:
the helper now returns true.
Tests
Added coverage in dom.browser.spec.ts:
Verified with:
EXPERIMENTAL_TESTS=true npx vitest run src/utils/dom.browser.spec.ts
Impact