Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid - Setting the isHighlighted option in the onFocusedCellChanging event handler does not work when the end user uses the Tab key to navigate between data cells (T853599) #11667

Merged
merged 1 commit into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions js/ui/grid_core/ui.grid_core.keyboard_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ const KeyboardNavigationController = core.ViewController.inherit({
}

this._updateFocusedCellPosition($cell);
$cell = this._getNextCellByTabKey($event, direction, elementType);
const nextCellInfo = this._getNextCellByTabKey($event, direction, elementType);
$cell = nextCellInfo.$cell;

if(!$cell || this._handleTabKeyOnMasterDetailCell($cell, direction)) {
return false;
Expand All @@ -483,7 +484,7 @@ const KeyboardNavigationController = core.ViewController.inherit({
this._editingController.closeEditCell();
}

if(this._focusCell($cell)) {
if(this._focusCell($cell, !nextCellInfo.isHighlighted)) {
if(!this._isRowEditMode() && isEditingAllowed) {
this._editingController.editCell(this.getVisibleRowIndex(), this._focusedCellPosition.columnIndex);
} else {
Expand Down Expand Up @@ -517,7 +518,9 @@ const KeyboardNavigationController = core.ViewController.inherit({
}
}

$cell = this._getNextCellByTabKey($event, direction, elementType);
const nextCellInfo = this._getNextCellByTabKey($event, direction, elementType);
$cell = nextCellInfo.$cell;

if(!$cell) {
return false;
}
Expand All @@ -527,7 +530,7 @@ const KeyboardNavigationController = core.ViewController.inherit({
return false;
}

this._focusCell($cell);
this._focusCell($cell, !nextCellInfo.isHighlighted);

if(!isEditorCell(this, $cell)) {
this._focusInteractiveElement($cell, eventArgs.shift);
Expand All @@ -541,13 +544,17 @@ const KeyboardNavigationController = core.ViewController.inherit({
const args = $cell && this._fireFocusedCellChanging($event, $cell, true);

if(!args || args.cancel) {
return;
return {};
}

if(args.$newCellElement) {
$cell = args.$newCellElement;
}
return $cell;

return {
$cell,
isHighlighted: args.isHighlighted
};
},
_checkNewLineTransition: function($event, $cell) {
const rowIndex = this.getVisibleRowIndex();
Expand Down Expand Up @@ -1007,9 +1014,9 @@ const KeyboardNavigationController = core.ViewController.inherit({
}
},

_focusCell: function($cell) {
_focusCell: function($cell, isDisabled) {
if(this._isCellValid($cell)) {
this._focus($cell);
this._focus($cell, isDisabled);
return true;
}
},
Expand Down
32 changes: 32 additions & 0 deletions testing/tests/DevExpress.ui.widgets.dataGrid/dataGrid.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18355,6 +18355,38 @@ QUnit.testInActiveWindow('DataGrid - Master grid should not render it\'s overlay
assert.ok(detailRowsViewWrapper.isFocusOverlayVisible(), 'Detail grid focus overlay is visible');
});

QUnit.testInActiveWindow('Not highlight cell if isHighlighted set false in the onFocusedCellChanging event by Tab key (T853599)', function(assert) {
// arrange
let focusedCellChangingCount = 0;
this.dataGrid.option({
dataSource: [{ name: 'Alex', phone: '111111', room: 6 }],
keyExpr: 'name',
onFocusedCellChanging: function(e) {
++focusedCellChangingCount;
e.isHighlighted = false;
}
});
this.clock.tick();

$(this.dataGrid.getCellElement(0, 0))
.trigger(pointerEvents.up)
.click();
this.clock.tick();

// assert
assert.equal(this.dataGrid.option('focusedRowIndex'), 0, 'focusedRowIndex');
assert.equal(this.dataGrid.option('focusedColumnIndex'), 0, 'focusedColumnIndex');

// act
const navigationController = this.dataGrid.getController('keyboardNavigation');
navigationController._keyDownHandler({ key: 'Tab', keyName: 'tab', originalEvent: $.Event('keydown', { target: $(this.dataGrid.getCellElement(0, 0)) }) });
this.clock.tick();

// assert
assert.equal(focusedCellChangingCount, 2, 'onFocusedCellChanging fires count');
assert.notOk($(this.dataGrid.getCellElement(0, 1)).hasClass('dx-focused'), 'cell is not focused');
});

QUnit.test('Focus row element should support native DOM', function(assert) {
// arrange
let $focusedCell;
Expand Down