Skip to content

Commit

Permalink
Update ensure scroll to handle scrolling to a row properly. Closes #1379
Browse files Browse the repository at this point in the history
  • Loading branch information
maier49 authored and edhager committed Jun 6, 2017
1 parent 13e3ca8 commit b5820d8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
16 changes: 11 additions & 5 deletions Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,22 @@ define([
}
},

_ensureScroll: function (cell, isHeader) {
_ensureScroll: function (rowOrCell, isHeader) {
// summary:
// Corrects scroll based on the position of the newly-focused row/cell
// as necessary based on grid configuration and dimensions.
var isRow = !rowOrCell.column && !rowOrCell.row && rowOrCell.data && rowOrCell.element;

if(this.cellNavigation && (this.columnSets || this.subRows.length > 1) && !isHeader){
this._ensureRowScroll(cell.row.element);
if (isRow) {
this._ensureRowScroll(rowOrCell.element);
}
if(this.bodyNode.clientWidth < this.contentNode.offsetWidth){
this._ensureColumnScroll(cell.element);
else {
if (this.cellNavigation && (this.columnSets || this.subRows.length > 1) && !isHeader) {
this._ensureRowScroll(rowOrCell.row.element);
}
if (this.bodyNode.clientWidth < this.contentNode.offsetWidth) {
this._ensureColumnScroll(rowOrCell.element);
}
}
},

Expand Down
41 changes: 39 additions & 2 deletions test/intern/mixins/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ define([
'dojo/on',
'dojo/query',
'dgrid/test/data/createSyncStore',
'dgrid/test/data/genericData'
'dgrid/test/data/genericData',
'../addCss!'
], function (test, assert, OnDemandList, OnDemandGrid, Keyboard, ColumnSet,
declare, domConstruct, on, query, createSyncStore, genericData) {
var handles = [],
Expand Down Expand Up @@ -59,7 +60,10 @@ define([

function after() {
// Destroy list or grid
grid.destroy();
if (grid) {
grid.destroy();
grid = undefined;
}
}

// Common test functions for grid w/ cellNavigation: false and list
Expand Down Expand Up @@ -559,4 +563,37 @@ define([
'contentNode should be focusable when grid is empty again');
});
});

test.suite('Keyboard _ensureScroll', function () {
function isRowVisible(row) {
return row.element.offsetTop < grid.bodyNode.scrollTop + grid.bodyNode.offsetHeight;
}

test.beforeEach(function () {
var store = createSyncStore({ data: genericData });
grid = new (declare([ OnDemandGrid, Keyboard ]))({
collection: store,
columns: columns
});
document.body.appendChild(grid.domNode);
grid.startup();
});

test.afterEach(after);

test.test('scroll to row', function () {
var row40 = grid.row(40);
assert.isTrue(!isRowVisible(row40), 'Row 40 is visible.');
grid._ensureScroll(row40);
assert.isTrue(isRowVisible(row40), 'Row 40 is not visible.');
});

test.test('scroll to cell', function () {
var cell40col3 = grid.cell(40, 'col3');
assert.isTrue(!isRowVisible(cell40col3.row), 'Row 40 is visible.');
grid._ensureScroll(cell40col3);
// This is how the code works when there are no column sets and only one subrow.
assert.isTrue(!isRowVisible(cell40col3.row), 'Row 40 is visible.');
});
});
});

0 comments on commit b5820d8

Please sign in to comment.