Skip to content

Commit

Permalink
#2676 Checkbox now correctly prevent default event on keyup not keydown
Browse files Browse the repository at this point in the history
  • Loading branch information
jlukic committed Jul 20, 2015
1 parent e07369a commit 8f6bc3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
**[Reported Bugs](https://github.com/Semantic-Org/Semantic-UI/issues?q=is%3Aissue+milestone%3A2.0.5+is%3Aclosed)**

- **API** - Data replaced in urls, `urlData`, will now be url encoded by default. Additionally checks were added to avoid double encoding already encoded values. #2394
- **Checkbox** - Fix issue with `onChange` not firing when space key is used. Checkbox keyboard shortcuts now occur on `keydown` but cancel events correctly on `keyup` #2676
- **Dropdown** - Fixed regression causing `multiple search dropdown` using [`search` inside menu](http://www.semantic-ui.com/modules/dropdown.html#search-in-menu) to break, caused by JS error using "split"
- **Message** - Fixed issues where icon would overlap in `icon message` when at mobile resolutions due to `flex-collapse` value being incorrect #2665

Expand Down
17 changes: 14 additions & 3 deletions src/definitions/modules/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ $.fn.checkbox = function(parameters) {
$label = $(this).children(selector.label),
$input = $(this).children(selector.input),

shortcutPressed = false,

instance = $module.data(moduleNamespace),

observer,
Expand Down Expand Up @@ -192,11 +194,19 @@ $.fn.checkbox = function(parameters) {
if(key == keyCode.escape) {
module.verbose('Escape key pressed blurring field');
$input.blur();
event.preventDefault();
shortcutPressed = true;
}
if(!event.ctrlKey && (key == keyCode.enter)) {
module.verbose('Enter key pressed, toggling checkbox');
else if(!event.ctrlKey && ( key == keyCode.space || key == keyCode.enter) ) {
module.verbose('Enter/space key pressed, toggling checkbox');
module.toggle();
shortcutPressed = true;
}
else {
shortcutPressed = false;
}
},
keyup: function(event) {
if(shortcutPressed) {
event.preventDefault();
}
}
Expand Down Expand Up @@ -455,6 +465,7 @@ $.fn.checkbox = function(parameters) {
$module
.on('click' + eventNamespace, module.event.click)
.on('keydown' + eventNamespace, selector.input, module.event.keydown)
.on('keyup' + eventNamespace, selector.input, module.event.keyup)
;
}
},
Expand Down

0 comments on commit 8f6bc3d

Please sign in to comment.