Skip to content

Commit

Permalink
Only blur if at least one item is added or removed
Browse files Browse the repository at this point in the history
  • Loading branch information
keanulee committed May 7, 2018
1 parent 76a33fa commit a796ee5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
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 a796ee5

Please sign in to comment.