Skip to content

Commit

Permalink
Fix #494: make Keyboard more resilient against structure resets
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth G. Franqueiro committed Mar 15, 2013
1 parent aea7de2 commit cbf15b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ This document outlines changes since 0.3.0. For older changelogs, see the
appropriately if the footer node is present. (#463)
* The `CellSelection` mixin now properly deselects if an unselected cell within
the same row as a selected cell is right-clicked.
* Fixed issues with the `Keyboard` mixin pertaining to resetting columns, or
not setting them initially. (#494)
* The `Keyboard` mixin now ensures that if the header area is scrolled due to a
focus shift, the body scrolls with it. (#474)

Expand Down
11 changes: 9 additions & 2 deletions Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@ var Keyboard = declare(null, {
isHeader = areaNode === grid.headerNode,
initialNode = areaNode;

if(isHeader){
function initHeader(){
grid._focusedHeaderNode = initialNode =
cellNavigation ? grid.headerNode.getElementsByTagName("th")[0] : grid.headerNode;
initialNode.tabIndex = grid.tabIndex;
if(initialNode){ initialNode.tabIndex = grid.tabIndex; }
}

if(isHeader){
// Initialize header now (since it's already been rendered),
// and aspect after future renderHeader calls to reset focus.
initHeader();
aspect.after(grid, "renderHeader", initHeader, true);
}else{
aspect.after(grid, "renderArray", function(ret){
// summary:
Expand Down
2 changes: 2 additions & 0 deletions test/Keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ <h3>Buttons to test programmatic focus</h3>
</div>
<div>Focus header (no argument):
<button onclick="grid.focusHeader();">Cell-navigation Grid</button>
<button onclick="grid.set('columns', grid.columns); grid.focusHeader();">
Reset columns, then focus</button>
</div>
</div>
</body>
Expand Down

0 comments on commit cbf15b2

Please sign in to comment.