Skip to content

Commit 7e5ce60

Browse files
authored
Fixed click event without selection to not run action (#440)
* Fixed click event without selection to not run action * fix tests * fix test
1 parent ae1d269 commit 7e5ce60

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

packages/cheetah-grid/src/js/columns/action/actionBind.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ export function bindCellClickAction<T>(
6363
if (!isTarget(e.col, e.row)) {
6464
return;
6565
}
66+
const sel = grid.selection.select;
67+
if (sel.col !== e.col || sel.row !== e.row) {
68+
// If the user drags from another element in the grid and then clicks,
69+
// this can lead to unexpected behavior because there is no selection event.
70+
// A guard avoids this issue.
71+
return;
72+
}
6673
if (isPromise(grid.getRowRecord(e.row))) {
6774
return;
6875
}

packages/cheetah-grid/src/js/header/action/actionBind.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export function bindCellClickAction<T>(
3131
if (!isTarget(e.col, e.row)) {
3232
return;
3333
}
34+
const sel = grid.selection.select;
35+
if (sel.col !== e.col || sel.row !== e.row) {
36+
// If the user drags from another element in the grid and then clicks,
37+
// this can lead to unexpected behavior because there is no selection event.
38+
// A guard avoids this issue.
39+
return;
40+
}
3441
action({
3542
col: e.col,
3643
row: e.row,

packages/cheetah-grid/src/test/specs/column/style/CheckStyle_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,17 @@
122122
});
123123

124124
it('toggle', function(done) {
125+
grid.selection.select = {col: 0, row: 1};
125126
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 0, row: 1});
127+
grid.selection.select = {col: 1, row: 1};
126128
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 1, row: 1});
129+
grid.selection.select = {col: 2, row: 1};
127130
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 2, row: 1});
131+
grid.selection.select = {col: 3, row: 1};
128132
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 3, row: 1});
133+
grid.selection.select = {col: 4, row: 1};
129134
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 4, row: 1});
135+
grid.selection.select = {col: 0, row: 0};
130136

131137
expect(records[0]).toEqual({bool: true, str: 'true', onoff: 'on', num: 1, numstr: '01'});
132138

@@ -286,11 +292,17 @@
286292
it('checkBgColor', function(done) {
287293
action.readOnly = false;
288294
style.checkBgColor = '#0f0';
295+
grid.selection.select = {col: 0, row: 1};
289296
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 0, row: 1});
297+
grid.selection.select = {col: 1, row: 1};
290298
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 1, row: 1});
299+
grid.selection.select = {col: 2, row: 1};
291300
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 2, row: 1});
301+
grid.selection.select = {col: 3, row: 1};
292302
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 3, row: 1});
303+
grid.selection.select = {col: 4, row: 1};
293304
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 4, row: 1});
305+
grid.selection.select = {col: 0, row: 0};
294306

295307

296308
setTimeout(function() {

packages/cheetah-grid/src/test/specs/column/type/CheckColumn_spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,17 @@
116116
});
117117

118118
it('toggle', function(done) {
119+
grid.selection.select = {col: 0, row: 1};
119120
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 0, row: 1});
121+
grid.selection.select = {col: 1, row: 1};
120122
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 1, row: 1});
123+
grid.selection.select = {col: 2, row: 1};
121124
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 2, row: 1});
125+
grid.selection.select = {col: 3, row: 1};
122126
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 3, row: 1});
127+
grid.selection.select = {col: 4, row: 1};
123128
grid.fireListeners(cheetahGrid.ListGrid.EVENT_TYPE.CLICK_CELL, {col: 4, row: 1});
129+
grid.selection.select = {col: 0, row: 0};
124130

125131
expect(records[0]).toEqual({bool: true, str: 'true', onoff: 'on', num: 1, numstr: '01'});
126132

0 commit comments

Comments
 (0)