Skip to content

Commit

Permalink
Merge pull request #375 from admwx7/master
Browse files Browse the repository at this point in the history
Fixes #373 allowing support for parents to use <content> or <slot>
  • Loading branch information
Emmanuel Garcia authored Jan 17, 2017
2 parents aab8bae + 2386035 commit 0bc889b
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 7 deletions.
18 changes: 13 additions & 5 deletions iron-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@
return size - this._viewportHeight;
},

/**
* The parent node for the _userTemplate.
*/
get _itemsParent() {
return Polymer.dom(Polymer.dom(this._userTemplate).parentNode);
},

/**
* The maximum scroll top value.
*/
Expand Down Expand Up @@ -919,7 +926,7 @@
// First element child is item; Safari doesn't support children[0]
// on a doc fragment.
physicalItems[i] = inst.root.querySelector('*');
Polymer.dom(this).appendChild(inst.root);
this._itemsParent.appendChild(inst.root);
}
return physicalItems;
},
Expand Down Expand Up @@ -1028,7 +1035,7 @@
props[this.selectedAs] = true;
props.tabIndex = true;
this._instanceProps = props;
this._userTemplate = Polymer.dom(this).querySelector('template');
this._userTemplate = this.queryEffectiveChildren('template');

if (this._userTemplate) {
this.templatize(this._userTemplate);
Expand Down Expand Up @@ -1619,7 +1626,8 @@
}
var modelTabIndex, activeElTabIndex;
var target = Polymer.dom(e).path[0];
var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).activeElement;
var itemsHost = this._itemsParent.node.domHost;
var activeEl = Polymer.dom(itemsHost ? itemsHost.root : document).activeElement;
var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.indexAs])];
// Safari does not focus certain form controls via mouse
// https://bugs.webkit.org/show_bug.cgi?id=118043
Expand Down Expand Up @@ -1732,7 +1740,7 @@

_removeFocusedItem: function() {
if (this._offscreenFocusedItem) {
Polymer.dom(this).removeChild(this._offscreenFocusedItem);
this._itemsParent.removeChild(this._offscreenFocusedItem);
}
this._offscreenFocusedItem = null;
this._focusBackfillItem = null;
Expand All @@ -1751,7 +1759,7 @@
// Create a physical item.
var stampedTemplate = this.stamp(null);
this._focusBackfillItem = stampedTemplate.root.querySelector('*');
Polymer.dom(this).appendChild(stampedTemplate.root);
this._itemsParent.appendChild(stampedTemplate.root);
}
// Set the offcreen focused physical item.
this._offscreenFocusedItem = this._physicalItems[pidx];
Expand Down
3 changes: 2 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
'different-heights.html',
'grid.html',
'grid-rtl.html',
'bindings-host-to-item.html'
'bindings-host-to-item.html',
'template-overload.html'
]);
</script>
</body>
Expand Down
30 changes: 30 additions & 0 deletions test/o-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->

<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../iron-list.html">

<dom-module id="o-list">
<template>
<iron-list id="list" items="{{items}}">
<content>
<template>
<div class="default-template">
[[item.index]]
</div>
</template>
</content>
</iron-list>
</template>
</dom-module>

<script>
Polymer({is: 'o-list'});
</script>
2 changes: 1 addition & 1 deletion test/physical-count.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
test('pool should not increase if the list has no size', function(done) {
container.style.display = 'none';
list.fire('iron-resize');

flush(function() {
assert.equal(list._physicalCount, 0);
done();
Expand Down
84 changes: 84 additions & 0 deletions test/template-overload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
The complete set of authors may be found at http://polymer.github.io/AUTHORS
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
-->
<html>
<head>
<meta charset="UTF-8">
<title>iron-list test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>

<link rel="import" href="helpers.html">
<link rel="import" href="o-list.html">

</head>
<body>

<test-fixture id="defaultTemplateList">
<template>
<o-list></o-list>
</template>
</test-fixture>

<test-fixture id="templateOverloadList">
<template>
<o-list>
<template>
<div class="overloaded-template">[[item.index]]</div>
</template>
</o-list>
</template>
</test-fixture>

<script>

suite('template overloading', function() {
var list;

setup(function() {
list = fixture('templateOverloadList');
});

test('check physical item size', function(done) {
var setSize = 10;
list.items = buildDataSet(setSize);

flush(function() {
assert.equal(list.items.length, setSize);
done();
});
});

test('check item template', function(done) {
list.items = buildDataSet(1);

flush(function() {
assert.equal(list.$.list.$.items.querySelectorAll('.overloaded-template').length, 1);
done();
});
});

test('check count of physical items', function(done) {
var setSize = 1;
list.items = buildDataSet(setSize);

flush(function() {
assert.equal(Polymer.dom(list).querySelectorAll('*').length - 1, setSize);
done();
});
});
});

</script>

</body>
</html>

0 comments on commit 0bc889b

Please sign in to comment.