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

fix(buttons): double toggle on spacebar #4630

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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