Skip to content
This repository has been archived by the owner on Jan 4, 2018. It is now read-only.

Commit

Permalink
#23 - don't slot empty or whitespace-only text nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
treshugart committed Mar 31, 2016
1 parent 455147c commit 261010c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ function slotNodeIntoSlot (slot, node, insertBefore) {
const assignedNodes = slot.getAssignedNodes();
const slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore);

// Don't slot empty text nodes. This messes up fallback content.
if (node.nodeType === 3 && node.textContent.trim().length === 0) {
return;
}

nodeToSlotMap.set(node, slot);

// If there's currently no assigned nodes, there will be, so remove all fallback content.
Expand Down
7 changes: 7 additions & 0 deletions test/unit/slot/fallback-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ describe('fallback-content', function () {
expect(slot.____isInFallbackMode).to.equal(true);
});

it('should not slot text nodes that are empty or have only whitespace', function () {
host.appendChild(document.createTextNode(''));
host.appendChild(document.createTextNode(' '));
host.appendChild(document.createTextNode('\n'));
expect(slot.getAssignedNodes().length).to.equal(0);
});

describe('when assigned nodes', function () {
let newNode;

Expand Down

0 comments on commit 261010c

Please sign in to comment.