Skip to content

Commit

Permalink
Add fallback support/test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Sep 22, 2016
1 parent 6fd0e1f commit 037abdd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@
_replaceSlotWithContent: function(slot) {
var content = slot.ownerDocument.createElement('content');
var attrs = slot.attributes;
var childNodes = slot.childNodes;
while (slot.firstChild) {
content.appendChild(slot.firstChild);
}
for (var i=0; i<attrs.length; i++) {
var attr = attrs[i];
content.setAttribute(attr.name, attr.value);
Expand Down
12 changes: 8 additions & 4 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"></slot></div>
<div id="foo"><slot id="fooIP" name="foo"></slot></div>
<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>
</template>
<script>
HTMLImports.whenReady(function() {
Expand Down Expand Up @@ -357,6 +357,10 @@
assert.equal(dist.$.fooIP.getAttribute('select'), '[slot=\'foo\']');
assert.equal(dist.$.defaultIP.localName, 'content');
assert.equal(dist.$.defaultIP.getAttribute('select'), ':not([slot])');
if (usingShady) {
assert.equal(dist.$.foo.firstElementChild.textContent, 'fallback for foo');
assert.equal(dist.$.default.firstElementChild.textContent, 'fallback for default');
}
// Distribute div
var frag = document.createDocumentFragment();
var foo1 = frag.appendChild(document.createElement('div'));
Expand All @@ -380,9 +384,9 @@
Polymer.dom(dist).removeChild(default2);
Polymer.dom.flush();
if (usingShady) {
assert.equal(dist.$.foo.children[0], null);
assert.equal(dist.$.foo.children[0].textContent, 'fallback for foo');
assert.equal(dist.$.foo.children[1], null);
assert.equal(dist.$.default.children[0], null);
assert.equal(dist.$.default.children[0].textContent, 'fallback for default');
assert.equal(dist.$.default.children[1], null);
}
document.body.removeChild(dist);
Expand Down

0 comments on commit 037abdd

Please sign in to comment.