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

Commit b77618e

Browse files
committed
feat(buttons): add uib-uncheckable support
- Add support for `uib-uncheckable` with uib-btn-radio Closes #3604 Closes #4791
1 parent 739b667 commit b77618e

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/buttons/buttons.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ angular.module('ui.bootstrap.buttons', [])
1010
this.toggleEvent = buttonConfig.toggleEvent || 'click';
1111
}])
1212

13-
.directive('uibBtnRadio', function() {
13+
.directive('uibBtnRadio', ['$parse', function($parse) {
1414
return {
1515
require: ['uibBtnRadio', 'ngModel'],
1616
controller: 'UibButtonsController',
1717
controllerAs: 'buttons',
1818
link: function(scope, element, attrs, ctrls) {
1919
var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];
20+
var uncheckableExpr = $parse(attrs.uibUncheckable);
2021

2122
element.find('input').css({display: 'none'});
2223

@@ -40,9 +41,15 @@ angular.module('ui.bootstrap.buttons', [])
4041
});
4142
}
4243
});
44+
45+
if (attrs.uibUncheckable) {
46+
scope.$watch(uncheckableExpr, function(uncheckable) {
47+
attrs.$set('uncheckable', uncheckable ? '' : null);
48+
});
49+
}
4350
}
4451
};
45-
})
52+
}])
4653

4754
.directive('uibBtnCheckbox', function() {
4855
return {

src/buttons/docs/demo.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ <h4>Radio &amp; Uncheckable Radio</h4>
2222
<div class="btn-group">
2323
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Left'" uncheckable>Left</label>
2424
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Middle'" uncheckable>Middle</label>
25-
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Right'" uncheckable>Right</label>
25+
<label class="btn btn-success" ng-model="radioModel" uib-btn-radio="'Right'" uib-uncheckable="uncheckable">Right</label>
26+
</div>
27+
<div>
28+
<button class="btn btn-default" ng-click="uncheckable = !uncheckable">
29+
Toggle uncheckable
30+
</button>
2631
</div>
2732
</div>

src/buttons/docs/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ With the buttons directive, we can make a group of buttons behave like a set of
2424
* `uncheckable`
2525
_(Boolean attribute)_ -
2626
Whether a radio button can be unchecked or not.
27+
28+
* `uib-uncheckable`
29+
_(Default: null)_ -
30+
An expression that evaluates to a truthy or falsy value that determines whether the `uncheckable` attribute is present
2731

2832
### Default settings `uibButtonConfig`
2933

src/buttons/test/buttons.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,19 @@ describe('buttons', function() {
322322
expect(btns.eq(1)).not.toHaveClass('active');
323323
});
324324
});
325+
326+
describe('uibUncheckable', function() {
327+
it('should set uncheckable', function() {
328+
$scope.uncheckable = false;
329+
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);
330+
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
331+
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
332+
333+
$scope.uncheckable = true;
334+
$scope.$digest();
335+
expect(btns.eq(0).attr('uncheckable')).toBeUndefined();
336+
expect(btns.eq(1).attr('uncheckable')).toBeDefined();
337+
});
338+
});
325339
});
326340
});

0 commit comments

Comments
 (0)