Skip to content

Commit 2059db9

Browse files
author
Umer Farooq
committed
fix(edit): fix boolean edit issue on Firefox and Safari on macOS
Add mousedown listener to ui.grid.edit.directive:uiGridEditor to disable blur handler if the element is a checkbox, and then re-focus the checkbox and enable the blur handler after a $timeout. This change is to deal with Safari and Firefox behavior in macOS where clicking the checkbox causes a blur event, and the value is not updated. GitHub issues: #1785, #4778, #4782
1 parent 6dfed10 commit 2059db9

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/features/edit/js/gridEdit.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,20 @@
966966
});
967967
}
968968

969-
$elm.on('blur', function (evt) {
970-
$scope.stopEdit(evt);
969+
// macOS will blur the checkbox when clicked in Safari and Firefox,
970+
// to get around this, we disable the blur handler on mousedown,
971+
// and then focus the checkbox and re-enable the blur handler after $timeout
972+
$elm.on('mousedown', function(evt) {
973+
if ($elm[0].type === 'checkbox') {
974+
$elm.off('blur', $scope.stopEdit);
975+
$timeout(function() {
976+
$elm.focus();
977+
$elm.on('blur', $scope.stopEdit);
978+
});
979+
}
971980
});
981+
982+
$elm.on('blur', $scope.stopEdit);
972983
});
973984

974985

@@ -1132,9 +1143,9 @@
11321143
//set focus at start of edit
11331144
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
11341145
$timeout(function(){
1135-
$elm[0].focus();
1146+
$elm[0].focus();
11361147
});
1137-
1148+
11381149
$elm[0].style.width = ($elm[0].parentElement.offsetWidth - 1) + 'px';
11391150
$elm.on('blur', function (evt) {
11401151
$scope.stopEdit(evt);

0 commit comments

Comments
 (0)