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

Commit 2e9177e

Browse files
SteffanLongwesleycho
authored andcommitted
fix(progressbar): allow max width of 100%
- When stacking bars, ensure that the max width possible is 100% Closes #4027 Fixes #4018
1 parent a028d2a commit 2e9177e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: src/progressbar/progressbar.js

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ angular.module('ui.bootstrap.progressbar', [])
2727

2828
bar.recalculatePercentage = function() {
2929
bar.percent = +(100 * bar.value / bar.max).toFixed(2);
30+
31+
var totalPercentage = 0;
32+
self.bars.forEach(function (bar) {
33+
totalPercentage += bar.percent;
34+
});
35+
36+
if (totalPercentage > 100) {
37+
bar.percent -= totalPercentage - 100;
38+
}
3039
};
3140

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

Diff for: src/progressbar/test/progressbar.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,21 @@ describe('progressbar directive', function () {
258258
$rootScope.$digest();
259259
expect(getBar(0).attr('aria-valuemax')).toBe('300');
260260
});
261+
262+
it('should not have a total width over 100%', function() {
263+
$rootScope.objects = [
264+
{ value: 60, type: 'warning' },
265+
{ value: 103 },
266+
{ value: 270, type: 'info' }
267+
];
268+
$rootScope.max = 433;
269+
$rootScope.$digest();
270+
var totalWidth = 0;
271+
for (var i = 0; i < 3; i++) {
272+
totalWidth += parseFloat(getBar(i).css('width'));
273+
}
274+
expect(totalWidth.toFixed(2)).toBe('100.00');
275+
});
261276
});
262277
});
263278
});

0 commit comments

Comments
 (0)