Skip to content

Commit

Permalink
fix(core): slotController isEmpty respects text nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Nov 20, 2024
1 parent fe349ea commit e5103c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changeset/olive-rivers-stick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": patch
---
`SlotController`: `hasContent`/`isEmpty` now respects text nodes
3 changes: 2 additions & 1 deletion core/pfe-core/controllers/slot-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export class SlotController implements ReactiveController {
?? this.#getChildrenForSlot(name);
const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';
const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;
const hasContent = !!elements.length;
const nodes = slot?.assignedNodes?.();
const hasContent = !!elements.length || !!nodes?.filter(x => x.textContent?.trim()).length;
this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });
this.#logger.debug(slotName, hasContent);
};
Expand Down

0 comments on commit e5103c5

Please sign in to comment.