Skip to content

fix(dom): detect visible content for slotted slot elements#14269

Closed
driskull wants to merge 3 commits intodevfrom
dris0000/dom-util-fix
Closed

fix(dom): detect visible content for slotted slot elements#14269
driskull wants to merge 3 commits intodevfrom
dris0000/dom-util-fix

Conversation

@driskull
Copy link
Copy Markdown
Member

@driskull driskull commented Apr 15, 2026

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:

  • non-whitespace text, or
  • an element node

the helper now returns true.

Tests

Added coverage in dom.browser.spec.ts:

  • should return true if slot element has assigned visible content

Verified with:
EXPERIMENTAL_TESTS=true npx vitest run src/utils/dom.browser.spec.ts

Impact

  • Fixes visibility detection for nested slot scenarios
  • Unblocks components relying on hasVisibleContent for slot-change state updates (including panel heading/description behavior)
  • No API changes

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Apr 15, 2026
@driskull driskull requested a review from Copilot April 15, 2026 23:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hasVisibleContent to detect visible content from HTMLSlotElement.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.

Comment thread packages/components/src/utils/dom.ts Outdated
Comment thread packages/components/src/utils/dom.browser.spec.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@driskull driskull marked this pull request as ready for review April 15, 2026 23:56
@driskull driskull requested a review from jcfranco April 15, 2026 23:56
@driskull driskull closed this Apr 16, 2026
@driskull driskull deleted the dris0000/dom-util-fix branch April 16, 2026 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug reports for broken functionality. Issues should include a reproduction of the bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants