Skip to content

Commit

Permalink
Merge pull request #522 from PolymerElements/item-added-removed
Browse files Browse the repository at this point in the history
Item added removed
  • Loading branch information
keanulee authored May 10, 2018
2 parents 76a33fa + 8177b92 commit 959cb2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
hfx3KW2ope3tAmYSVtyO1shcaU9yIlKoTH/S8RbK4e2h+qOCvedwho8ezwO9eQzak0WcAuqJgQpkbOuBne7p0uXFZacGxewTAX0MAL7/RYOmF9ILrwnvLOcanAXjtkg4nom7/bwW9MhMjavyeD1T/7dZz9+CVexZkf/lDAkFsrgwd57iNq+/nSrA3IPY/T4LH9a9FWV0lRpSW9QIXGVWsVfn4tk8UOBWAEaNjVGWhKw+/ip9dB6AmrH9eaz6Gk4s5JzVa0IsKapS6gZfT49sdFmW+J/9RfQ0JdU7aiyaz74KJFVRUViPf1FOZcZ64PU8GTCARvF2ZrinpDDvjv7/jXHRTvGerzbJTkAmsm5x5ygbc3luqIOKM76b4ov0wf+pZ1d6z9fgSyYTogv+Xxx/84jr0Ed0R816Bzyt9tqorADhdcVm6+WYIyflkFFO0WCdWOjf4xVEZV4dzyNg/WFdi6P8BvOqXC3EC73eGydNpJvM3bP63lhjQwRWTiTnjjloZl+vQaQtm7JdLQK7ZJXfFQsJaijH2OhcbS0rMSLppMa3zJ7rtcRTO8yKDj74neZe77DLA9hRzbuNfLEl6bv9ZZOO8XEvC8A02umMIwPYK8lykcp5x4FBnN5BjsDX0MuT1EEkUN3CAHnvAEFK6m/Saa7wVl6g7HvK9drjYDX2/88=
- secure: >-
w3Lv07602Y19QSqIEUSW1MH/LuSmWWgmZWCKXB8ZnS+V+hNtOSodmXGBT7gpDK0eFOECMZyuvlJNmNX3c7+SBVAtBKEgrw8Zmwb7vB4AE0o6UE3dh3Cm9hUXUQtaymhoewkzstuMiqao6GrZ4FmaRVed0f0DXJBFUxL8A1LMraN9c05usEtOtkN5Ghfjh5EeFMrI4yM1MrwPgHjHf8sEnSvrmXtCd5aWT6aDWay5HY2mPG2tdHHtkQg2n2HS2loxT5EbS7e1L5XDPYW/Pp1OXa3DFvqVQqZpK0H7xidXNDYCOwdlrIa5Q54UXqqRDyzsTip87pQzVwG7sDJ5Zjtp/icF71xDlcv9WU/CM9MLEqN8A+zpBYeCKapCygQGh899IzJCMeBoahkRxmqL5BUxUiQKcwe0uYCF9aBbkkmMjBABz5rH+QAw0BfGlpJ6dOyoON45WWmPwpOW8HlbcdpbQSeuNRuX9hsYmjNjvqVoaHqrCPBJWrDI3rctIvtbuWj5SDy4YVf2YHv+hJ3p+eF3bmCnErCLmBgSTmJi6oCSEefB/DPVypJGj8K+Izo2wVV6TY9mHgA0wbV7O77ecvyBXDOGt4xFb0lZN4WUMX74Gl7G/5uuj90qqN9bTdCMVRTvjpNy/2DsoprBAwPDh9EDrNSdYELTKxYhlnOeHic3OS0=
node_js: stable
node_js: '9'
addons:
firefox: latest
apt:
Expand Down
14 changes: 11 additions & 3 deletions iron-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,17 @@
} else if (change.path === 'items.splices') {
this._adjustVirtualIndex(change.value.indexSplices);
this._virtualCount = this.items ? this.items.length : 0;
// Only blur activeElement if it is a descendant of the list (#505, #507).
var activeElement = this._getActiveElement();
if (this.contains(activeElement)) activeElement.blur();
// Only blur if at least one item is added or removed.
var itemAddedOrRemoved = change.value.indexSplices.some(function(splice) {
return splice.addedCount > 0 || splice.removed.length > 0;
});
if (itemAddedOrRemoved) {
// Only blur activeElement if it is a descendant of the list (#505, #507).
var activeElement = this._getActiveElement();
if (this.contains(activeElement)) {
activeElement.blur();
}
}
// Render only if the affected index is rendered.
var affectedIndexRendered = change.value.indexSplices.some(function(splice) {
return splice.index + splice.addedCount >= this._virtualStart &&
Expand Down
22 changes: 22 additions & 0 deletions test/focus.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@
});
});

test('don\'t blur if no items are added or removed', function(done) {
list.items = buildDataSet(100);

flush(function() {
getFirstItemFromList(list).focus();

assert.notEqual(document.activeElement, document.body);

list.items[0]['foo'] = 'bar';
list.notifySplices('items', [{
index: 0,
addedCount: 0,
object: list.items,
type: 'splice',
removed: []
}]);

assert.notEqual(document.activeElement, document.body);
done();
});
});

test('don\'t blur when items changed (#449)', function(done) {
list.items = buildDataSet(100);

Expand Down

0 comments on commit 959cb2a

Please sign in to comment.