Skip to content

Commit

Permalink
Changed unnatural checkbox behaviour after double click (#10748)
Browse files Browse the repository at this point in the history
  • Loading branch information
wszymanski committed Jan 26, 2024
1 parent 549d023 commit c1ee222
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changelogs/10748.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"issuesOrigin": "private",
"title": "Changed unnatural checkbox behaviour after double click",
"type": "changed",
"issueOrPR": 10748,
"breaking": false,
"framework": "none"
}
9 changes: 5 additions & 4 deletions handsontable/src/editors/checkboxEditor/checkboxEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export class CheckboxEditor extends BaseEditor {
}

beginEditing(initialValue, event) {
// Just some events connected with checkbox editor are delegated here. Some `keydown` events like `enter` and `space` key press
// are handled inside `checkboxRenderer`. Some events come here from `editorManager`. Below `if` statement was created by author
// for purpose of handling only `doubleclick` event which may be done on a cell with checkbox.
// Just some events connected with the checkbox editor are delegated here. Some `keydown` events like `enter` and
// `space` key presses are handled inside `checkboxRenderer`. Some events come here from `editorManager`. The below
// `if` statement was created by the author for the purpose of handling only the `doubleclick` event on the TD
// element with a checkbox.

if (event && event.type === 'mouseup') {
if (event && event.type === 'mouseup' && event.target.nodeName === 'TD') {
const checkbox = this.TD.querySelector('input[type="checkbox"]');

if (!hasClass(checkbox, 'htBadValue')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,27 @@ describe('CheckboxRenderer', () => {
expect(getDataAtCell(0, 0)).toBe(false);
});

it('double click on input[type=checkbox] element inside checkbox cell should not invert the value', () => {
handsontable({
data: [
[true],
[false],
[true]
],
columns: [
{ type: 'checkbox' }
]
});

selectCell(0, 0);

mouseDoubleClick($(getCell(0, 0)).find('input[type=checkbox]'));
expect(getDataAtCell(0, 0)).toBe(true);

mouseDoubleClick($(getCell(1, 0)).find('input[type=checkbox]'));
expect(getDataAtCell(1, 0)).toBe(false);
});

it('should change checkbox state from checked to unchecked after hitting ENTER', () => {
handsontable({
data: [[true], [true], [true]],
Expand Down

0 comments on commit c1ee222

Please sign in to comment.