Skip to content

Commit

Permalink
fix(cellNav): #3528 handle focus into grid from other controls
Browse files Browse the repository at this point in the history
  • Loading branch information
swalters committed Jun 12, 2015
1 parent a8ff076 commit 92477c7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/features/cellnav/js/cellnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@
};
}]);

module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile',
function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile) {
module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile','uiGridCellNavConstants',
function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile, uiGridCellNavConstants) {
return {
replace: true,
priority: -99999, //this needs to run very last
Expand Down Expand Up @@ -755,13 +755,26 @@
uiGridCellNavService.decorateRenderContainers(grid);

//add an element with no dimensions that can be used to set focus and capture keystrokes
var focuser = $compile('<div class="ui-grid-focuser" tabindex="-1"></div>')($scope);
var focuser = $compile('<div class="ui-grid-focuser" tabindex="0"></div>')($scope);
$elm.append(focuser);

uiGridCtrl.focus = function () {
focuser[0].focus();
//allow for first time grid focus
focuser.on('focus', function (evt) {
evt.uiGridTargetRenderContainerId = containerId;
var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
if (rowCol === null) {
rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null);
if (rowCol.row && rowCol.col) {
uiGridCtrl.cellNav.broadcastCellNav(rowCol);
}
}
});
};



// Bind to keydown events in the render container
focuser.on('keydown', function (evt) {
evt.uiGridTargetRenderContainerId = containerId;
Expand Down

0 comments on commit 92477c7

Please sign in to comment.