Skip to content

Commit

Permalink
Make sure text nodes are distributed when translating slot to content
Browse files Browse the repository at this point in the history
Fixes #4109
  • Loading branch information
dfreedm committed Nov 15, 2016
1 parent 37eef0e commit 87e312f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@
content.setAttribute(attr.name, attr.value);
}
var name = slot.getAttribute('name');
var select = name ? '[slot=\'' + name + '\']' : ':not([slot])';
content.setAttribute('select', select);
if (name) {
content.setAttribute('select', '[slot=\'' + name + '\']');
}
slot.parentNode.replaceChild(content, slot);
return content;
},
Expand Down
7 changes: 5 additions & 2 deletions test/unit/polymer-dom-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<dom-module id="x-dist-slot">
<template>
x-dist
<div id="default"><slot id="defaultIP"><div>fallback for default</div></slot></div>
<div id="foo"><slot id="fooIP" name="foo"><div>fallback for foo</div></slot></div>
<div id="default"><slot id="defaultIP"><div>fallback for default</div></slot></div>
</template>
<script>
HTMLImports.whenReady(function() {
Expand Down Expand Up @@ -356,7 +356,7 @@
assert.equal(dist.$.fooIP.localName, 'content');
assert.equal(dist.$.fooIP.getAttribute('select'), '[slot=\'foo\']');
assert.equal(dist.$.defaultIP.localName, 'content');
assert.equal(dist.$.defaultIP.getAttribute('select'), ':not([slot])');
assert.equal(dist.$.defaultIP.getAttribute('select'), null);
assert.equal(Polymer.dom(dist.$.fooIP).getDistributedNodes()[0].textContent, 'fallback for foo');
assert.equal(Polymer.dom(dist.$.defaultIP).getDistributedNodes()[0].textContent, 'fallback for default');
// Distribute div
Expand All @@ -365,6 +365,7 @@
var default1 = frag.appendChild(document.createElement('div'));
var foo2 = frag.appendChild(document.createElement('div'));
var default2 = frag.appendChild(document.createElement('div'));
var defaultText = frag.appendChild(document.createTextNode('distributed text'));
foo1.setAttribute('slot', 'foo');
foo2.setAttribute('slot', 'foo');
Polymer.dom(dist).appendChild(frag);
Expand All @@ -373,11 +374,13 @@
assert.equal(Polymer.dom(dist.$.fooIP).getDistributedNodes()[1], foo2);
assert.equal(Polymer.dom(dist.$.defaultIP).getDistributedNodes()[0], default1);
assert.equal(Polymer.dom(dist.$.defaultIP).getDistributedNodes()[1], default2);
assert.equal(Polymer.dom(dist.$.defaultIP).getDistributedNodes()[2], defaultText);
// Remove
Polymer.dom(dist).removeChild(foo1);
Polymer.dom(dist).removeChild(foo2);
Polymer.dom(dist).removeChild(default1);
Polymer.dom(dist).removeChild(default2);
Polymer.dom(dist).removeChild(defaultText);
Polymer.dom.flush();
assert.equal(Polymer.dom(dist.$.fooIP).getDistributedNodes()[0].textContent, 'fallback for foo');
assert.equal(Polymer.dom(dist.$.fooIP).getDistributedNodes()[1], null);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/styling-scoped-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,10 @@
border: 8px solid green;
}
</style>
<slot></slot>
<div id="container">
<slot name="container"></slot>
</div>
<slot></slot>
</template>
<script>
Polymer({is: 'x-slotted'});
Expand Down

0 comments on commit 87e312f

Please sign in to comment.