Skip to content

Commit 436a2e8

Browse files
tarusinvalorkin
authored andcommitted
fix(progressbar): toggle striped and animate states (#4581)
fixes #3864
1 parent 6e32261 commit 436a2e8

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

src/progressbar/progressbar.component.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,23 @@ import { BarComponent } from './bar.component';
1616
]
1717
})
1818
export class ProgressbarComponent {
19-
/** if `true` changing value of progress bar will be animated*/
20-
@Input() animate: boolean;
19+
/** if `true` changing value of progress bar will be animated */
20+
@Input()
21+
set animate(value: boolean) {
22+
this._animate = value;
23+
this.bars.forEach((b: BarComponent) => {
24+
b.animate = value;
25+
});
26+
}
2127
/** If `true`, striped classes are applied */
22-
@Input() striped: boolean;
28+
@Input()
29+
set striped(value: boolean) {
30+
this._striped = value;
31+
this.bars.forEach((b: BarComponent) => {
32+
b.striped = value;
33+
});
34+
}
35+
2336
/** provide one of the four supported contextual classes: `success`, `info`, `warning`, `danger` */
2437
@Input() type: string;
2538
/** current value of progress bar. Could be a number or array of objects
@@ -31,6 +44,8 @@ export class ProgressbarComponent {
3144
this._value = value;
3245
}
3346
isStacked = false;
47+
_striped: boolean;
48+
_animate: boolean;
3449
_value: number | any[];
3550
get isBs3(): boolean {
3651
return isBs3();
@@ -60,8 +75,8 @@ export class ProgressbarComponent {
6075
Object.assign(this, config);
6176
}
6277
addBar(bar: BarComponent): void {
63-
bar.animate = this.animate;
64-
bar.striped = this.striped;
78+
bar.animate = this._animate;
79+
bar.striped = this._striped;
6580

6681
this.bars.push(bar);
6782
}

src/spec/progressbar.component.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,37 @@ class TestProgressbarComponent extends ProgressbarComponent {}
1313
describe('Component: Progress Bar', () => {
1414
let fixture: ComponentFixture<TestProgressbarComponent>;
1515
let element: any;
16+
let component: ProgressbarComponent;
17+
18+
it('check animate setter when _animate is equal to setter\'s argument', () => {
19+
TestBed.configureTestingModule({
20+
declarations: [TestProgressbarComponent],
21+
imports: [ProgressbarModule.forRoot()]
22+
});
23+
fixture = TestBed.createComponent(TestProgressbarComponent);
24+
component = fixture.componentInstance;
25+
component._animate = false;
26+
component.bars = [{}];
27+
28+
component.animate = true;
29+
30+
expect(component._animate).toBeTruthy();
31+
});
32+
33+
it('check striped setter when _striped is equal to setter\'s argument', () => {
34+
TestBed.configureTestingModule({
35+
declarations: [TestProgressbarComponent],
36+
imports: [ProgressbarModule.forRoot()]
37+
});
38+
fixture = TestBed.createComponent(TestProgressbarComponent);
39+
component = fixture.componentInstance;
40+
component._striped = false;
41+
component.bars = [{}];
42+
43+
component.striped = true;
44+
45+
expect(component._striped).toBeTruthy();
46+
});
1647

1748
it('should work correctly with default values', () => {
1849
const tpl = `<progressbar></progressbar>`;

0 commit comments

Comments
 (0)