Skip to content

Commit

Permalink
Only scroll to index when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored and web-padawan committed Feb 6, 2018
1 parent 7c74bc7 commit 70f7ec6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/vaadin-grid-keyboard-navigation-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,9 @@
}

_ensureScrolledToIndex(index) {
const visibleItemsCount = this._lastVisibleIndex - this._firstVisibleIndex - 1;
if (index <= this._firstVisibleIndex) {
const targetRowInDom = Array.from(this.$.items.children).filter(child => child.index === index)[0];
if (!targetRowInDom) {
this._scrollToIndex(index);
} else if (index >= this._firstVisibleIndex + visibleItemsCount) {
this._scrollToIndex(index - visibleItemsCount);
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/keyboard-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,14 @@
expect(grid.shadowRoot.activeElement).to.equal(getContainerCell(grid.$.header, 0, 0));
});

it('should not scroll if the new focused item in viewport', () => {
focusItem(0);
ctrlEnd();
const scrollTop = grid.$.table.scrollTop;
up();
expect(grid.$.table.scrollTop).to.equal(scrollTop);
});

describe('rotating focus indicator prevention', () => {
it('should hide navigation mode when a focused row goes off screen', () => {
focusItem(0);
Expand Down

0 comments on commit 70f7ec6

Please sign in to comment.