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

Commit

Permalink
fix(buttons): respect disabled attribute
Browse files Browse the repository at this point in the history
- Ensure disabled attribute is respected due to a change in Bootstrap 3.3.5 CSS

Closes #4026
Fixes #4013
  • Loading branch information
wesleycho committed Jul 30, 2015
1 parent 1b04599 commit 42e1af5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/buttons/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ angular.module('ui.bootstrap.buttons', [])

//ui->model
element.bind(buttonsCtrl.toggleEvent, function () {
if ('disabled' in attrs) {
return;
}

var isActive = element.hasClass(buttonsCtrl.activeClass);

if (!isActive || angular.isDefined(attrs.uncheckable)) {
Expand Down Expand Up @@ -64,6 +68,10 @@ angular.module('ui.bootstrap.buttons', [])

//ui->model
element.bind(buttonsCtrl.toggleEvent, function () {
if ('disabled' in attrs) {
return;
}

scope.$apply(function () {
ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
ngModelCtrl.$render();
Expand Down
35 changes: 35 additions & 0 deletions src/buttons/test/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ describe('buttons', function () {
expect($scope.model).toEqual(2);
});

it('should not toggle when disabled - issue 4013', function () {
$scope.model = 1;
$scope.falseVal = 0;
var btn = compileButton('<button disabled ng-model="model" btn-checkbox btn-checkbox-true="falseVal">click</button>', $scope);

expect(btn).not.toHaveClass('active');
expect($scope.model).toEqual(1);

btn.click();

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

$scope.$digest();

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

describe('setting buttonConfig', function () {
var originalActiveClass, originalToggleEvent;

Expand Down Expand Up @@ -177,6 +194,24 @@ describe('buttons', function () {
expect(btns.eq(1)).not.toHaveClass('active');
});

it('should not toggle when disabled - issue 4013', function () {
$scope.model = 1;
var btns = compileButtons('<button ng-model="model" btn-radio="1">click1</button><button disabled ng-model="model" btn-radio="2">click2</button>', $scope);

expect(btns.eq(0)).toHaveClass('active');
expect(btns.eq(1)).not.toHaveClass('active');

btns.eq(1).click();

expect(btns.eq(0)).toHaveClass('active');
expect(btns.eq(1)).not.toHaveClass('active');

$scope.$digest();

expect(btns.eq(0)).toHaveClass('active');
expect(btns.eq(1)).not.toHaveClass('active');
});

describe('uncheckable', function () {
//model -> UI
it('should set active class based on model', function () {
Expand Down

0 comments on commit 42e1af5

Please sign in to comment.