From 92477c7ad97f439582039b574baa2286f724d0ef Mon Sep 17 00:00:00 2001 From: swalters Date: Fri, 12 Jun 2015 09:40:17 -0500 Subject: [PATCH] fix(cellNav): #3528 handle focus into grid from other controls --- src/features/cellnav/js/cellnav.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/features/cellnav/js/cellnav.js b/src/features/cellnav/js/cellnav.js index 36066e18de..9f709d3ae6 100644 --- a/src/features/cellnav/js/cellnav.js +++ b/src/features/cellnav/js/cellnav.js @@ -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 @@ -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('
')($scope); + var focuser = $compile('
')($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;