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

fix(buttons): make uib-uncheckable work as expected and documented #5451

Closed
wants to merge 1 commit into from
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
2 changes: 1 addition & 1 deletion 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', [])

if (attrs.uibUncheckable) {
scope.$watch(uncheckableExpr, function(uncheckable) {
attrs.$set('uncheckable', uncheckable ? '' : null);
attrs.$set('uncheckable', uncheckable ? '' : undefined);
});
}
}
Expand Down
28 changes: 27 additions & 1 deletion src/buttons/test/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,38 @@ describe('buttons', function() {
$scope.uncheckable = false;
var btns = compileButtons('<button ng-model="model" uib-btn-radio="1">click1</button><button ng-model="model" uib-btn-radio="2" uib-uncheckable="uncheckable">click2</button>', $scope);
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
expect(btns.eq(1).attr('uncheckable')).toBeUndefined();

expect($scope.model).toBeUndefined();

btns.eq(0).click();
expect($scope.model).toEqual(1);

btns.eq(0).click();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be clicked twice in a row?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is to assert that, with uncheckable not being set, clicking the same button twice is the same as clicking it once. Otherwise, it might just always be uncheckable irrespective of the state of uncheckable.

expect($scope.model).toEqual(1);

btns.eq(1).click();
expect($scope.model).toEqual(2);

btns.eq(1).click();
expect($scope.model).toEqual(2);

$scope.uncheckable = true;
$scope.$digest();
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
expect(btns.eq(1).attr('uncheckable')).toBeDefined();

btns.eq(0).click();
expect($scope.model).toEqual(1);

btns.eq(0).click();
expect($scope.model).toEqual(1);

btns.eq(1).click();
expect($scope.model).toEqual(2);

btns.eq(1).click();
expect($scope.model).toBeNull();
});
});
});
Expand Down