diff --git a/iron-selectable.html b/iron-selectable.html index 25cfe91..69c9602 100644 --- a/iron-selectable.html +++ b/iron-selectable.html @@ -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. @@ -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); diff --git a/test/basic.html b/test/basic.html index 08866bb..30768b5 100644 --- a/test/basic.html +++ b/test/basic.html @@ -167,19 +167,22 @@ }); test('`selectIndex()` selects an item with the given index', function() { - assert.equal(s2.selectedItem, undefined); + Polymer.Base.async(function() { + assert.equal(s2.selected, 'item2'); + assert.equal(s2.selectedItem, s2.items[2]); - s2.selectIndex(1); - assert.equal(s2.selected, 'item1'); - assert.equal(s2.selectedItem, s2.items[1]); + s2.selectIndex(1); + assert.equal(s2.selected, 'item1'); + assert.equal(s2.selectedItem, s2.items[1]); - s2.selectIndex(3); - assert.equal(s2.selected, 'item3'); - assert.equal(s2.selectedItem, s2.items[3]); + s2.selectIndex(3); + assert.equal(s2.selected, 'item3'); + assert.equal(s2.selectedItem, s2.items[3]); - s2.selectIndex(4); - assert.equal(s2.selected, 'item4'); - assert.equal(s2.selectedItem, s2.items[4]); + s2.selectIndex(4); + assert.equal(s2.selected, 'item4'); + assert.equal(s2.selectedItem, s2.items[4]); + }, 1); }); }); diff --git a/test/content.html b/test/content.html index af27cf8..55d1a38 100644 --- a/test/content.html +++ b/test/content.html @@ -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() {