Skip to content

Commit

Permalink
Support default slot semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Sep 21, 2016
1 parent 41e5dc0 commit d458dd3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
13 changes: 7 additions & 6 deletions src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,13 @@
var attrs = slot.attributes;
for (var i=0; i<attrs.length; i++) {
var attr = attrs[i];
if (attr.name == 'name') {
content.setAttribute('select', '[slot=\'' + attr.value + '\']');
}
if (attr.name !== 'select') {
content.setAttribute(attr.name, attr.value);
}
content.setAttribute(attr.name, attr.value);
}
var name = slot.getAttribute('name');
if (name) {
content.setAttribute('select', '[slot=\'' + attr.value + '\']');
} else {
content.setAttribute('select', ':not([slot])');
}
slot.parentNode.replaceChild(content, slot);
return content;
Expand Down
41 changes: 26 additions & 15 deletions test/unit/polymer-dom-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<dom-module id="x-dist-slot">
<template>
x-dist
<div id="distWrapper"><slot id="content" name="foo"></slot></div>
<div id="default"><slot id="defaultIP"></slot></div>
<div id="foo"><slot id="fooIP" name="foo"></slot></div>
</template>
<script>
HTMLImports.whenReady(function() {
Expand Down Expand Up @@ -352,27 +353,37 @@
test('append div to distributing element (auto <slot> to <content>)', function() {
var dist = document.createElement('x-dist-slot');
document.body.appendChild(dist);
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])');
// Distribute div
var div = document.createElement('div');
div.setAttribute('slot', 'foo');
Polymer.dom(dist).appendChild(div);
Polymer.dom.flush();
if (usingShady) {
assert.equal(dist.$.distWrapper.firstElementChild, div);
}
// Append to distributed div
var div2 = document.createElement('div');
Polymer.dom(div).appendChild(div2);
var frag = document.createDocumentFragment();
var foo1 = frag.appendChild(document.createElement('div'));
var default1 = frag.appendChild(document.createElement('div'));
var foo2 = frag.appendChild(document.createElement('div'));
var default2 = frag.appendChild(document.createElement('div'));
foo1.setAttribute('slot', 'foo');
foo2.setAttribute('slot', 'foo');
Polymer.dom(dist).appendChild(frag);
Polymer.dom.flush();
if (usingShady) {
assert.equal(dist.$.distWrapper.firstElementChild, div);
assert.equal(div.firstElementChild, div2);
assert.equal(dist.$.foo.children[0], foo1);
assert.equal(dist.$.foo.children[1], foo2);
assert.equal(dist.$.default.children[0], default1);
assert.equal(dist.$.default.children[1], default2);
}
// Remove
Polymer.dom(dist).removeChild(div);
Polymer.dom(dist).removeChild(foo1);
Polymer.dom(dist).removeChild(foo2);
Polymer.dom(dist).removeChild(default1);
Polymer.dom(dist).removeChild(default2);
Polymer.dom.flush();
if (usingShady) {
assert.equal(dist.$.distWrapper.firstElementChild, null);
assert.equal(dist.$.foo.children[0], null);
assert.equal(dist.$.foo.children[1], null);
assert.equal(dist.$.default.children[0], null);
assert.equal(dist.$.default.children[1], null);
}
document.body.removeChild(dist);
});
Expand Down

0 comments on commit d458dd3

Please sign in to comment.