Skip to content

Commit

Permalink
fix(cellNav): was processing left and right renderContainers where th…
Browse files Browse the repository at this point in the history
…ere is no need

fix(edit): was not focusing back to grid after an edit
  • Loading branch information
swalters committed Apr 30, 2015
1 parent c9ce96a commit 6f5d503
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
30 changes: 13 additions & 17 deletions src/features/cellnav/js/cellnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,17 +749,6 @@
// Needs to run last after all renderContainers are built
uiGridCellNavService.decorateRenderContainers(grid);

////enable tabbing to renderContainer
//$elm.attr("tabindex", -1);
//
//$elm.on('focus', function (evt) {
// var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
// if (!rowCol) {
// rowCol = grid.renderContainers.body.cellNav.initializeSelection();
// uiGridCtrl.cellNav.broadcastCellNav(rowCol);
// }
//});

}
};
}
Expand All @@ -768,7 +757,6 @@

module.directive('uiGridViewport', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants','$log','$compile',
function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log, $compile) {
var focuser;
return {
replace: true,
priority: -99999, //this needs to run very last
Expand All @@ -777,9 +765,6 @@
compile: function () {
return {
pre: function ($scope, $elm, $attrs, uiGridCtrl) {
//add an element with no dimensions that can be used to set focus and capture keystrokes
focuser = $compile('<div class="ui-grid-focuser" tabindex="-1"></div>')($scope);
$elm.append(focuser);
},
post: function ($scope, $elm, $attrs, controllers) {
var uiGridCtrl = controllers[0],
Expand All @@ -789,11 +774,22 @@
if (!uiGridCtrl.grid.api.cellNav) { return; }

var containerId = renderContainerCtrl.containerId;
//no need to process for other containers
if (containerId !== 'body') {
return;
}

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();
};

focuser[0].focus();
uiGridCtrl.focus();

// Bind to keydown events in the render container
focuser.on('keydown', function (evt) {
Expand Down Expand Up @@ -845,7 +841,7 @@

grid.api.cellNav.on.navigate($scope, function () {
//focus again because it can be lost
focuser[0].focus();
uiGridCtrl.focus();
});

}
Expand Down
31 changes: 19 additions & 12 deletions src/features/edit/js/gridEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,18 @@
// Skip attaching if edit and cellNav is not enabled
if (!uiGridCtrl.grid.api.edit || !uiGridCtrl.grid.api.cellNav) { return; }

var containerId = controllers[1].containerId;
//no need to process for other containers
if (containerId !== 'body') {
return;
}

//refocus on the grid
$scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () {
$elm[0].focus();
uiGridCtrl.focus();
});
$scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () {
$elm[0].focus();
uiGridCtrl.focus();
});

}
Expand Down Expand Up @@ -1042,7 +1049,7 @@

var handleFileSelect = function( event ){
var target = event.srcElement || event.target;

if (target && target.files && target.files.length > 0) {
/**
* @ngdoc property
Expand All @@ -1051,25 +1058,25 @@
* @description A function that should be called when any files have been chosen
* by the user. You should use this to process the files appropriately for your
* application.
*
* It passes the gridCol, the gridRow (from which you can get gridRow.entity),
*
* It passes the gridCol, the gridRow (from which you can get gridRow.entity),
* and the files. The files are in the format as returned from the file chooser,
* an array of files, with each having useful information such as:
* - `files[0].lastModifiedDate`
* - `files[0].name`
* - `files[0].size` (appears to be in bytes)
* - `files[0].type` (MIME type by the looks)
*
* Typically you would do something with these files - most commonly you would
*
* Typically you would do something with these files - most commonly you would
* use the filename or read the file itself in. The example function does both.
*
*
* @example
* <pre>
* editFileChooserCallBack: function(gridRow, gridCol, files ){
* // ignore all but the first file, it can only choose one anyway
* // set the filename into this column
* gridRow.entity.filename = file[0].name;
*
*
* // read the file and set it into a hidden column, which we may do stuff with later
* var setFile = function(fileContent){
* gridRow.entity.file = fileContent.currentTarget.result;
Expand All @@ -1085,16 +1092,16 @@
} else {
gridUtil.logError('You need to set colDef.editFileChooserCallback to use the file chooser');
}

target.form.reset();
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
} else {
$scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
}
};

$elm[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google

$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
$elm[0].focus();
$elm[0].select();
Expand Down

0 comments on commit 6f5d503

Please sign in to comment.