Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update items when selectable property changes, test provided, issue #126 #149

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior seems to have all of its observers down in the observers array. I think it might be better to put this one there too.

},

/**
* 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of 2.x you don't need to check _shouldUpdateSelection.

this._updateSelected();
}
},

_updateItems: function() {
var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*');
nodes = Array.prototype.filter.call(nodes, this._bindFilterItem);
Expand Down
23 changes: 13 additions & 10 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,22 @@
});

test('`selectIndex()` selects an item with the given index', function() {
assert.equal(s2.selectedItem, undefined);
Polymer.Base.async(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests now wait for iron-items-changed, so I think after rebasing you'll find this async delay isn't necessary.

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);
});
});

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