Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(buttons): double toggle on spacebar
Browse files Browse the repository at this point in the history
Fixes #4474
Closes #4630
  • Loading branch information
Foxandxss committed Oct 15, 2015
1 parent 02425b8 commit e8808d3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 49 deletions.
16 changes: 2 additions & 14 deletions src/buttons/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ angular.module('ui.bootstrap.buttons', [])
};
})

.directive('uibBtnCheckbox', ['$document', function($document) {
.directive('uibBtnCheckbox', function() {
return {
require: ['uibBtnCheckbox', 'ngModel'],
controller: 'UibButtonsController',
Expand Down Expand Up @@ -82,21 +82,9 @@ angular.module('ui.bootstrap.buttons', [])
ngModelCtrl.$render();
});
});

//accessibility
element.on('keypress', function(e) {
if (attrs.disabled || e.which !== 32 || $document[0].activeElement !== element[0]) {
return;
}

scope.$apply(function() {
ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
ngModelCtrl.$render();
});
});
}
};
}]);
});

/* Deprecated buttons below */

Expand Down
35 changes: 0 additions & 35 deletions src/buttons/test/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,6 @@ describe('buttons', function() {
expect(btn).not.toHaveClass('active');
});

it('should toggle custom model values on spacebar if focused', function() {
$scope.model = 0;
var btn = compileButton('<button ng-model="model" uib-btn-checkbox btn-checkbox-true="1" btn-checkbox-false="0">click</button>', $scope);
$('body').append(btn);
var e = $.Event('keypress');
e.which = 32;

btn[0].focus();
btn.trigger(e);
$scope.$digest();
expect($scope.model).toEqual(1);
expect(btn).toHaveClass('active');

btn.trigger(e);
$scope.$digest();
expect($scope.model).toEqual(0);
expect(btn).not.toHaveClass('active');

btn.remove();
});

it('should monitor true / false value changes - issue 666', function() {

$scope.model = 1;
Expand All @@ -116,7 +95,6 @@ describe('buttons', function() {
$scope.model = 1;
$scope.falseVal = 0;
var btn = compileButton('<button disabled ng-model="model" uib-btn-checkbox btn-checkbox-true="falseVal">click</button>', $scope);
$('body').append(btn);

expect(btn).not.toHaveClass('active');
expect($scope.model).toEqual(1);
Expand All @@ -128,19 +106,6 @@ describe('buttons', function() {
$scope.$digest();

expect(btn).not.toHaveClass('active');

btn[0].focus();
var e = $.Event('keypress');
e.which = 32;
btn.trigger(e);

expect(btn).not.toHaveClass('active');

$scope.$digest();

expect(btn).not.toHaveClass('active');

btn.remove();
});

describe('setting buttonConfig', function() {
Expand Down

0 comments on commit e8808d3

Please sign in to comment.