Skip to content

Commit 6f5d503

Browse files
committed
fix(cellNav): was processing left and right renderContainers where there is no need
fix(edit): was not focusing back to grid after an edit
1 parent c9ce96a commit 6f5d503

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/features/cellnav/js/cellnav.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -749,17 +749,6 @@
749749
// Needs to run last after all renderContainers are built
750750
uiGridCellNavService.decorateRenderContainers(grid);
751751

752-
////enable tabbing to renderContainer
753-
//$elm.attr("tabindex", -1);
754-
//
755-
//$elm.on('focus', function (evt) {
756-
// var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
757-
// if (!rowCol) {
758-
// rowCol = grid.renderContainers.body.cellNav.initializeSelection();
759-
// uiGridCtrl.cellNav.broadcastCellNav(rowCol);
760-
// }
761-
//});
762-
763752
}
764753
};
765754
}
@@ -768,7 +757,6 @@
768757

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

791776
var containerId = renderContainerCtrl.containerId;
777+
//no need to process for other containers
778+
if (containerId !== 'body') {
779+
return;
780+
}
792781

793782
var grid = uiGridCtrl.grid;
794783

784+
//add an element with no dimensions that can be used to set focus and capture keystrokes
785+
var focuser = $compile('<div class="ui-grid-focuser" tabindex="-1"></div>')($scope);
786+
$elm.append(focuser);
787+
788+
uiGridCtrl.focus = function () {
789+
focuser[0].focus();
790+
};
795791

796-
focuser[0].focus();
792+
uiGridCtrl.focus();
797793

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

846842
grid.api.cellNav.on.navigate($scope, function () {
847843
//focus again because it can be lost
848-
focuser[0].focus();
844+
uiGridCtrl.focus();
849845
});
850846

851847
}

src/features/edit/js/gridEdit.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,18 @@
355355
// Skip attaching if edit and cellNav is not enabled
356356
if (!uiGridCtrl.grid.api.edit || !uiGridCtrl.grid.api.cellNav) { return; }
357357

358+
var containerId = controllers[1].containerId;
359+
//no need to process for other containers
360+
if (containerId !== 'body') {
361+
return;
362+
}
363+
364+
//refocus on the grid
358365
$scope.$on(uiGridEditConstants.events.CANCEL_CELL_EDIT, function () {
359-
$elm[0].focus();
366+
uiGridCtrl.focus();
360367
});
361368
$scope.$on(uiGridEditConstants.events.END_CELL_EDIT, function () {
362-
$elm[0].focus();
369+
uiGridCtrl.focus();
363370
});
364371

365372
}
@@ -1042,7 +1049,7 @@
10421049

10431050
var handleFileSelect = function( event ){
10441051
var target = event.srcElement || event.target;
1045-
1052+
10461053
if (target && target.files && target.files.length > 0) {
10471054
/**
10481055
* @ngdoc property
@@ -1051,25 +1058,25 @@
10511058
* @description A function that should be called when any files have been chosen
10521059
* by the user. You should use this to process the files appropriately for your
10531060
* application.
1054-
*
1055-
* It passes the gridCol, the gridRow (from which you can get gridRow.entity),
1061+
*
1062+
* It passes the gridCol, the gridRow (from which you can get gridRow.entity),
10561063
* and the files. The files are in the format as returned from the file chooser,
10571064
* an array of files, with each having useful information such as:
10581065
* - `files[0].lastModifiedDate`
10591066
* - `files[0].name`
10601067
* - `files[0].size` (appears to be in bytes)
10611068
* - `files[0].type` (MIME type by the looks)
1062-
*
1063-
* Typically you would do something with these files - most commonly you would
1069+
*
1070+
* Typically you would do something with these files - most commonly you would
10641071
* use the filename or read the file itself in. The example function does both.
1065-
*
1072+
*
10661073
* @example
10671074
* <pre>
10681075
* editFileChooserCallBack: function(gridRow, gridCol, files ){
10691076
* // ignore all but the first file, it can only choose one anyway
10701077
* // set the filename into this column
10711078
* gridRow.entity.filename = file[0].name;
1072-
*
1079+
*
10731080
* // read the file and set it into a hidden column, which we may do stuff with later
10741081
* var setFile = function(fileContent){
10751082
* gridRow.entity.file = fileContent.currentTarget.result;
@@ -1085,16 +1092,16 @@
10851092
} else {
10861093
gridUtil.logError('You need to set colDef.editFileChooserCallback to use the file chooser');
10871094
}
1088-
1095+
10891096
target.form.reset();
10901097
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
10911098
} else {
10921099
$scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
10931100
}
10941101
};
1095-
1102+
10961103
$elm[0].addEventListener('change', handleFileSelect, false); // TODO: why the false on the end? Google
1097-
1104+
10981105
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
10991106
$elm[0].focus();
11001107
$elm[0].select();

0 commit comments

Comments
 (0)