Skip to content

Commit

Permalink
Update items when selectable property changes, test provided, issue P…
Browse files Browse the repository at this point in the history
  • Loading branch information
globits committed Mar 13, 2017
1 parent f894fa4 commit f13fd8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion iron-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@
* This is a CSS selector string. If this is set, only items that match the CSS selector
* are selectable.
*/
selectable: String,
selectable: {
type: String,
observer: '_selectableChanged'
},

/**
* The class to set on elements when selected.
Expand Down Expand Up @@ -268,6 +271,13 @@
this._addListener(eventName);
},

_selectableChanged: function() {
this._updateItems();
if (this._shouldUpdateSelection) {
this._updateSelected();
}
},

_updateItems: function() {
var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*');
nodes = Array.prototype.filter.call(nodes, this._bindFilterItem);
Expand Down
12 changes: 12 additions & 0 deletions test/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@
assert.isTrue(s2.querySelector('#item4').classList.contains('iron-selected'));
});

test('selectable property changed', function() {
s2.selectable = 'hr';
// check items length
assert.equal(s2.$.selector.items.length, 2);
s2.selectable = 'item';
s2.selected = 'item4';
// check items length
assert.equal(s2.$.selector.items.length, 5);
// check selected class
assert.isTrue(s2.querySelector('#item4').classList.contains('iron-selected'));
});

});

suite('content with dom-repeat', function() {
Expand Down

0 comments on commit f13fd8c

Please sign in to comment.