diff --git a/packages/mdc-linear-progress/foundation.js b/packages/mdc-linear-progress/foundation.js index 0c28e88ba35..4161076db0f 100644 --- a/packages/mdc-linear-progress/foundation.js +++ b/packages/mdc-linear-progress/foundation.js @@ -46,12 +46,14 @@ export default class MDCLinearProgressFoundation extends MDCFoundation { init() { this.determinate_ = !this.adapter_.hasClass(cssClasses.INDETERMINATE_CLASS); this.reverse_ = this.adapter_.hasClass(cssClasses.REVERSED_CLASS); + this.progress_ = 0; } setDeterminate(isDeterminate) { this.determinate_ = isDeterminate; if (this.determinate_) { this.adapter_.removeClass(cssClasses.INDETERMINATE_CLASS); + this.setScale_(this.adapter_.getPrimaryBar(), this.progress_); } else { this.adapter_.addClass(cssClasses.INDETERMINATE_CLASS); this.setScale_(this.adapter_.getPrimaryBar(), 1); @@ -60,6 +62,7 @@ export default class MDCLinearProgressFoundation extends MDCFoundation { } setProgress(value) { + this.progress_ = value; if (this.determinate_) { this.setScale_(this.adapter_.getPrimaryBar(), value); } diff --git a/test/unit/mdc-linear-progress/foundation.test.js b/test/unit/mdc-linear-progress/foundation.test.js index 42bae9a58af..d136dc638b4 100644 --- a/test/unit/mdc-linear-progress/foundation.test.js +++ b/test/unit/mdc-linear-progress/foundation.test.js @@ -63,6 +63,28 @@ test('#setDeterminate removes class', () => { td.verify(mockAdapter.removeClass(cssClasses.INDETERMINATE_CLASS)); }); +test('#setDeterminate restores previous progress value after toggled from false to true', () => { + const {foundation, mockAdapter} = setupTest(); + const primaryBar = {}; + td.when(mockAdapter.getPrimaryBar()).thenReturn(primaryBar); + foundation.init(); + foundation.setProgress(0.123); + foundation.setDeterminate(false); + foundation.setDeterminate(true); + td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)'), {times: 2}); +}); + +test('#setDeterminate updates progress value set while determinate is false after determinate is true', () => { + const {foundation, mockAdapter} = setupTest(); + const primaryBar = {}; + td.when(mockAdapter.getPrimaryBar()).thenReturn(primaryBar); + foundation.init(); + foundation.setDeterminate(false); + foundation.setProgress(0.123); + foundation.setDeterminate(true); + td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)')); +}); + test('#setProgress sets transform', () => { const {foundation, mockAdapter} = setupTest(); td.when(mockAdapter.hasClass(cssClasses.INDETERMINATE_CLASS)).thenReturn(false);