Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(radio): no longer prevents events from nested elements
Browse files Browse the repository at this point in the history
closes #2960
  • Loading branch information
rschmukler committed Nov 23, 2015
1 parent 462da45 commit 7a87dda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/components/radioButton/radio-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,17 @@ function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
*/
function keydownListener(ev) {
var keyCode = ev.which || ev.keyCode;
switch(keyCode) {

// Only listen to events that we originated ourselves
// so that we don't trigger on things like arrow keys in
// inputs.

if (keyCode != $mdConstant.KEY_CODE.ENTER &&
ev.currentTarget != ev.target) {
return;
}

switch (keyCode) {
case $mdConstant.KEY_CODE.LEFT_ARROW:
case $mdConstant.KEY_CODE.UP_ARROW:
ev.preventDefault();
Expand All @@ -117,6 +127,7 @@ function mdRadioGroupDirective($mdUtil, $mdConstant, $mdTheming, $timeout) {
}
break;
}

}
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/radioButton/radio-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ describe('radioButton', function() {
var rbGroupElement = element.eq(0);
rbGroupElement.triggerHandler({
type: 'keydown',
keyCode: $mdConstant.KEY_CODE.RIGHT_ARROW
keyCode: $mdConstant.KEY_CODE.RIGHT_ARROW,
currentTarget: rbGroupElement[0],
target: rbGroupElement[0]
});

expect($rootScope.color).toEqual('green');
Expand Down Expand Up @@ -143,7 +145,9 @@ describe('radioButton', function() {
element.triggerHandler('mousedown');
element.triggerHandler({
type: 'keydown',
keyCode: $mdConstant.KEY_CODE.DOWN_ARROW
keyCode: $mdConstant.KEY_CODE.DOWN_ARROW,
currentTarget: element[0],
target: element[0]
});
expect(element[0]).toHaveClass('md-focused');
}));
Expand Down Expand Up @@ -257,6 +261,8 @@ describe('radioButton', function() {
function rightArrow() {
rbGroupElement.triggerHandler({
type: 'keydown',
target: rbGroupElement[0],
currentTarget: rbGroupElement[0],
keyCode: $mdConstant.KEY_CODE.RIGHT_ARROW
});
}
Expand Down

0 comments on commit 7a87dda

Please sign in to comment.