Skip to content

Commit 92477c7

Browse files
committed
fix(cellNav): #3528 handle focus into grid from other controls
1 parent a8ff076 commit 92477c7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/features/cellnav/js/cellnav.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@
726726
};
727727
}]);
728728

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

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

761761
uiGridCtrl.focus = function () {
762762
focuser[0].focus();
763+
//allow for first time grid focus
764+
focuser.on('focus', function (evt) {
765+
evt.uiGridTargetRenderContainerId = containerId;
766+
var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
767+
if (rowCol === null) {
768+
rowCol = uiGridCtrl.grid.renderContainers[containerId].cellNav.getNextRowCol(uiGridCellNavConstants.direction.DOWN, null, null);
769+
if (rowCol.row && rowCol.col) {
770+
uiGridCtrl.cellNav.broadcastCellNav(rowCol);
771+
}
772+
}
773+
});
763774
};
764775

776+
777+
765778
// Bind to keydown events in the render container
766779
focuser.on('keydown', function (evt) {
767780
evt.uiGridTargetRenderContainerId = containerId;

0 commit comments

Comments
 (0)