Skip to content

Commit

Permalink
Fix #1043: Keyboard scrolling with sub-rows
Browse files Browse the repository at this point in the history
This adds debounced handling to adjust vertical scroll position if
necessary when keyboard focus changes, in cases where sub-rows or column sets
are used.

Thanks to @allencblee for suggesting an initial fix.
  • Loading branch information
Kenneth G. Franqueiro committed Jan 9, 2015
1 parent 94aeb54 commit 21698ab
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ define([
});
}
enableNavigation(this.contentNode);

this._debouncedEnsureRowScroll = miscUtil.debounce(this._ensureRowScroll, this);
},

removeRow: function (rowElement) {
Expand Down Expand Up @@ -280,6 +282,22 @@ define([
this[isHeader ? 'headerKeyMap' : 'keyMap'], key, callback, true);
},

_ensureRowScroll: function (rowElement) {
// summary:
// Ensures that the entire row is visible within the viewport.
// Called for cell navigation in complex structures.

var scrollY = this.getScrollPosition().y;
if (scrollY > rowElement.offsetTop) {
// Row starts above the viewport
this.scrollTo({ y: rowElement.offsetTop });
}
else if (scrollY + this.contentNode.offsetHeight < rowElement.offsetTop + rowElement.offsetHeight) {
// Row ends below the viewport
this.scrollTo({ y: rowElement.offsetTop - this.contentNode.offsetHeight + rowElement.offsetHeight });
}
},

_focusOnNode: function (element, isHeader, event) {
var focusedNodeProperty = '_focused' + (isHeader ? 'Header' : '') + 'Node',
focusedNode = this[focusedNodeProperty],
Expand Down Expand Up @@ -354,6 +372,10 @@ define([
if (event) {
on.emit(focusedNode, 'dgrid-cellfocusin', event);
}

if (this.cellNavigation && (this.columnSets || this.subRows.length > 1) && !isHeader) {
this._debouncedEnsureRowScroll(cell.row.element);
}
},

focusHeader: function (element) {
Expand Down Expand Up @@ -535,4 +557,4 @@ define([
};

return Keyboard;
});
});

0 comments on commit 21698ab

Please sign in to comment.