Skip to content

Commit e5103c5

Browse files
committed
fix(core): slotController isEmpty respects text nodes
1 parent fe349ea commit e5103c5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.changeset/olive-rivers-stick.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/pfe-core": patch
3+
---
4+
`SlotController`: `hasContent`/`isEmpty` now respects text nodes

core/pfe-core/controllers/slot-controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ export class SlotController implements ReactiveController {
193193
?? this.#getChildrenForSlot(name);
194194
const selector = slotName ? `slot[name="${slotName}"]` : 'slot:not([name])';
195195
const slot = this.host.shadowRoot?.querySelector?.<HTMLSlotElement>(selector) ?? null;
196-
const hasContent = !!elements.length;
196+
const nodes = slot?.assignedNodes?.();
197+
const hasContent = !!elements.length || !!nodes?.filter(x => x.textContent?.trim()).length;
197198
this.#nodes.set(name, { elements, name: slotName ?? '', hasContent, slot });
198199
this.#logger.debug(slotName, hasContent);
199200
};

0 commit comments

Comments
 (0)