Skip to content

Commit

Permalink
Selector: fix dojo#731 double selection
Browse files Browse the repository at this point in the history
  • Loading branch information
msssk committed Nov 26, 2015
1 parent deb5f9f commit 4f9d912
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ define([
},

_handleSelectorClick: function (event) {
// Prevent this handler from running twice for a single event.
// In some cases pressing SPACE or ENTER will also trigger a 'click' event. When a 'click' event originates
// from an actual mouse click, the 'event.detail' property contains the number of mouse clicks, which is 1
// or more. When a 'click' event originates from a keyboard event, 'event.detail' is 0 since there were no
// actual mouse clicks involved.
if (event.type === 'click' && event.detail === 0) {
// If the input (checkbox/radio) is the focused element (as opposed to the '.dgrid-selector' table cell)
// then the default event action is to change its selection state, which we want to prevent.
// (Otherwise you end up in the state where the input element's checked state is the opposite of the
// row's selected state.)
event.preventDefault();
return;
}

var cell = this.cell(event);
var row = cell.row;

Expand Down Expand Up @@ -216,4 +230,4 @@ define([
}
}
});
});
});
37 changes: 36 additions & 1 deletion test/intern/functional/Selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,40 @@ define([
createRowSelectionTest('gridToggle', true, selectAll));
test.test('select all; selectionMode: none',
createRowSelectionTest('gridNone', true, selectAll));

test.test('keyboard selection on input element', function () {
function getSelectionState (id) {
return gridExtended.selection[id];
}

return this.get('remote')
.findByCssSelector('#gridExtended-row-0 input')
.click()
.execute(getSelectionState, ['0'])
.then(function (selectionState) {
assert.isTrue(selectionState, 'Clicked row should be selected');
})
.type(keys.ENTER)
.execute(getSelectionState, ['0'])
.then(function (selectionState) {
assert.notOk(selectionState, 'Press Enter: row should not be selected');
})
.type(keys.ENTER)
.execute(getSelectionState, ['0'])
.then(function (selectionState) {
assert.isTrue(selectionState, 'Press Enter: row should be selected');
})
.type(keys.SPACE)
.execute(getSelectionState, ['0'])
.then(function (selectionState) {
assert.notOk(selectionState, 'Press Space: row should not be selected');
})
.type(keys.SPACE)
.execute(getSelectionState, ['0'])
.then(function (selectionState) {
assert.isTrue(selectionState, 'Press Space: row should be selected');
})
.end();
});
});
});
});

0 comments on commit 4f9d912

Please sign in to comment.