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

Commit 0daa7a7

Browse files
tjgrathwellbekos
authored andcommittedFeb 8, 2014
fix(progressbar): allow fractional values for bar width
* Fractions are limited to two decimals, and are not included in aria values. Closes #1761
1 parent 101c43a commit 0daa7a7

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
 

‎src/progressbar/progressbar.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ angular.module('ui.bootstrap.progressbar', [])
2020
this.bars.push(bar);
2121

2222
bar.$watch('value', function( value ) {
23-
bar.percent = Math.round(100 * value / $scope.max);
23+
bar.percent = +(100 * value / $scope.max).toFixed(2);
2424
});
2525

2626
bar.$on('$destroy', function() {

‎src/progressbar/test/progressbar.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ describe('progressbar directive', function () {
6565
expect(bar.attr('aria-valuetext')).toBe('60%');
6666
});
6767

68+
it('allows fractional "bar" width values, rounded to two places', function () {
69+
$rootScope.value = 5.625;
70+
$rootScope.$digest();
71+
expect(getBar(0).css('width')).toBe('5.63%');
72+
73+
$rootScope.value = 1.3;
74+
$rootScope.$digest();
75+
expect(getBar(0).css('width')).toBe('1.3%');
76+
});
77+
78+
it('does not include decimals in aria values', function () {
79+
$rootScope.value = 50.34;
80+
$rootScope.$digest();
81+
82+
var bar = getBar(0);
83+
expect(bar.css('width')).toBe('50.34%');
84+
85+
expect(bar.attr('aria-valuenow')).toBe('50');
86+
expect(bar.attr('aria-valuetext')).toBe('50%');
87+
});
88+
6889
describe('"max" attribute', function () {
6990
beforeEach(inject(function() {
7091
$rootScope.max = 200;

‎template/progressbar/progressbar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="progress">
2-
<div class="progress-bar" ng-class="type && 'progress-bar-' + type" role="progressbar" aria-valuenow="{{value}}" aria-valuemin="0" aria-valuemax="{{max}}" ng-style="{width: percent + '%'}" aria-valuetext="{{percent}}%" ng-transclude></div>
2+
<div class="progress-bar" ng-class="type && 'progress-bar-' + type" role="progressbar" aria-valuenow="{{value | number:0}}" aria-valuemin="0" aria-valuemax="{{max}}" ng-style="{width: percent + '%'}" aria-valuetext="{{percent | number:0}}%" ng-transclude></div>
33
</div>

0 commit comments

Comments
 (0)