Skip to content

Commit

Permalink
Checkbox Example (Mixed-State): Only toggle checkbox on keyup
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakusayan committed Nov 15, 2022
1 parent 79ad38e commit 1212370
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions examples/checkbox/js/checkbox-mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CheckboxMixed {
this.checkboxNodes = domNode.querySelectorAll('input[type="checkbox"]');

this.mixedNode.addEventListener('keydown', this.onMixedKeydown.bind(this));
this.mixedNode.addEventListener('keyup', this.onMixedKeyup.bind(this));
this.mixedNode.addEventListener('click', this.onMixedClick.bind(this));
this.mixedNode.addEventListener('focus', this.onMixedFocus.bind(this));
this.mixedNode.addEventListener('blur', this.onMixedBlur.bind(this));
Expand Down Expand Up @@ -116,23 +117,23 @@ class CheckboxMixed {

/* EVENT HANDLERS */

// Prevent page scrolling on space down
onMixedKeydown(event) {
var flag = false;
if (event.key === ' ') {
event.preventDefault();
}
}

onMixedKeyup(event) {
switch (event.key) {
case ' ':
this.toggleMixed();
flag = true;
event.stopPropagation();
break;

default:
break;
}

if (flag) {
event.stopPropagation();
event.preventDefault();
}
}

onMixedClick() {
Expand Down

0 comments on commit 1212370

Please sign in to comment.