Skip to content

Commit

Permalink
Update selection of multi-selectable on dom change
Browse files Browse the repository at this point in the history
Fixes #69
  • Loading branch information
Chris Joel committed Oct 16, 2015
1 parent 88658f2 commit 9333486
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions iron-multi-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
this._selection.multi = multi;
},

get _shouldUpdateSelection() {
return this.selected != null ||
(this.selectedValues != null && && this.selectedValues.length);
},

_updateSelected: function() {
if (this.multi) {
this._selectMulti(this.selectedValues);
Expand Down
8 changes: 6 additions & 2 deletions iron-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
this.selected = this._indexToValue(index);
},

get _shouldUpdateSelection() {
return this.selected != null;
},

_addListener: function(eventName) {
this.listen(this, eventName, '_activateHandler');
},
Expand Down Expand Up @@ -289,10 +293,10 @@

this._updateItems();

if (this.selected != null) {
if (this._shouldUpdateSelection) {
this._updateSelected();
}
}.bind(this));
});
},

_activateHandler: function(e) {
Expand Down
24 changes: 24 additions & 0 deletions test/multi.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

setup(function () {
s = fixture('test');
t = Polymer.dom(s).querySelector('[is="dom-repeat"]');
});

test('honors the multi attribute', function() {
Expand Down Expand Up @@ -163,6 +164,29 @@
});
});

test('updates selection when dom changes', function(done) {
var selectEventCounter = 0;

s = document.querySelector('#repeatedItems');

Polymer.Base.async(function() {
var firstChild = Polymer.dom(s).querySelector(':first-child');
var lastChild = Polymer.dom(s).querySelector(':last-child');

MockInteractions.tap(firstChild);
MockInteractions.tap(lastChild);

expect(s.selectedItems.length).to.be.equal(2);

t.pop('items');

Polymer.Base.async(function() {
expect(s.selectedItems.length).to.be.equal(1);
}, 1);
});

});

/* test('toggle multi from true to false', function() {
// set selected
s.selected = [0, 2];
Expand Down

2 comments on commit 9333486

@sklobovskaya
Copy link

Choose a reason for hiding this comment

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

@cdata Should _shouldUpdateSelection() also be used here?

if (!this.selectedItem && this.selected) {

@cdata
Copy link
Contributor

@cdata cdata commented on 9333486 Oct 21, 2015 via email

Choose a reason for hiding this comment

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

Please sign in to comment.