-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of 2.x you don't need to check |
||
this._updateSelected(); | ||
} | ||
}, | ||
|
||
_updateItems: function() { | ||
var nodes = Polymer.dom(this).queryDistributedElements(this.selectable || '*'); | ||
nodes = Array.prototype.filter.call(nodes, this._bindFilterItem); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,19 +167,22 @@ | |
}); | ||
|
||
test('`selectIndex()` selects an item with the given index', function() { | ||
assert.equal(s2.selectedItem, undefined); | ||
Polymer.Base.async(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests now wait for |
||
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); | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
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.