Skip to content

Commit

Permalink
fix(cellNav): IE was scrolling the viewPort to the end when the focus…
Browse files Browse the repository at this point in the history
…er div received focus. Solution was to move focuser element to the render Container div
  • Loading branch information
swalters committed May 6, 2015
1 parent efd3798 commit aa56355
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 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', 'uiGridCellNavConstants','$log',
function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log) {
module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', '$compile',
function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, $compile) {
return {
replace: true,
priority: -99999, //this needs to run very last
Expand All @@ -746,9 +746,32 @@

var grid = uiGridCtrl.grid;

// focusser only created for body
if (containerId !== 'body') {
return;
}

// Needs to run last after all renderContainers are built
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);
$elm.append(focuser);

uiGridCtrl.focus = function () {
focuser[0].focus();
};

// Bind to keydown events in the render container
focuser.on('keydown', function (evt) {
evt.uiGridTargetRenderContainerId = containerId;
var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
var result = uiGridCtrl.cellNav.handleKeyDown(evt);
if (result === null) {
uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol);
}
});

}
};
}
Expand Down Expand Up @@ -781,25 +804,11 @@

var grid = uiGridCtrl.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);
$elm.append(focuser);

uiGridCtrl.focus = function () {
focuser[0].focus();
};

uiGridCtrl.focus();

// Bind to keydown events in the render container
focuser.on('keydown', function (evt) {
evt.uiGridTargetRenderContainerId = containerId;
var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
var result = uiGridCtrl.cellNav.handleKeyDown(evt);
if (result === null) {
uiGridCtrl.grid.api.cellNav.raise.viewPortKeyDown(evt, rowCol);
}
});


grid.api.core.on.scrollBegin($scope, function (args) {

Expand Down

1 comment on commit aa56355

@rangoy
Copy link
Contributor

@rangoy rangoy commented on aa56355 Jun 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this introduces a race condition where uiGridCtrl.focus is not always available when it's used in uiGridRenderContainer

Please sign in to comment.