From fcd84b529b479afb9439629f7af74071f47e8827 Mon Sep 17 00:00:00 2001 From: Peter Vogel Date: Wed, 8 Aug 2018 15:59:49 +0200 Subject: [PATCH 1/2] Pay attention to the order of assignment of min max via attribtues If min value is greater than default max value assigment of custom range fails. --- packages/mdc-slider/index.js | 13 +++++++++++-- test/unit/mdc-slider/mdc-slider.test.js | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/mdc-slider/index.js b/packages/mdc-slider/index.js index 2b4f45d056c..a98c8424df7 100644 --- a/packages/mdc-slider/index.js +++ b/packages/mdc-slider/index.js @@ -177,8 +177,17 @@ class MDCSlider extends MDCComponent { initialSyncWithDOM() { const origValueNow = parseFloat(this.root_.getAttribute(strings.ARIA_VALUENOW)); - this.min = parseFloat(this.root_.getAttribute(strings.ARIA_VALUEMIN)) || this.min; - this.max = parseFloat(this.root_.getAttribute(strings.ARIA_VALUEMAX)) || this.max; + const min = parseFloat(this.root_.getAttribute(strings.ARIA_VALUEMIN)) || this.min; + const max = parseFloat(this.root_.getAttribute(strings.ARIA_VALUEMAX)) || this.max; + + if (min >= this.max) { + this.max = max; + this.min = min; + } else { + this.min = min; + this.max = max; + } + this.step = parseFloat(this.root_.getAttribute(strings.STEP_DATA_ATTR)) || this.step; this.value = origValueNow || this.value; this.disabled = ( diff --git a/test/unit/mdc-slider/mdc-slider.test.js b/test/unit/mdc-slider/mdc-slider.test.js index 92f27c77a4a..fa7639013d2 100644 --- a/test/unit/mdc-slider/mdc-slider.test.js +++ b/test/unit/mdc-slider/mdc-slider.test.js @@ -149,6 +149,16 @@ test('#initialSyncWithDOM adds an aria-valuemax attribute if not present', () => assert.equal(root.getAttribute('aria-valuemax'), String(component.max)); }); +test('#initialSyncWithDOM syncs a custom range with aria-valuemin and aria-valuemax', () => { + const root = getFixture(); + root.setAttribute('aria-valuemin', '2001'); + root.setAttribute('aria-valuemax', '2017'); + + const component = new MDCSlider(root); + assert.equal(component.min, 2001); + assert.equal(component.max, 2017); +}); + test('#initialSyncWithDOM syncs the value property with aria-valuenow for continuous slider', () => { const root = getFixture(); root.setAttribute('aria-valuenow', '30'); From 8af2201034aa75f3949b30242d69e5242bd662c8 Mon Sep 17 00:00:00 2001 From: "Andrew C. Dvorak" Date: Thu, 13 Dec 2018 12:41:47 -0800 Subject: [PATCH 2/2] WIP: Add comment --- packages/mdc-slider/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/mdc-slider/index.js b/packages/mdc-slider/index.js index a98c8424df7..1af5c9a9284 100644 --- a/packages/mdc-slider/index.js +++ b/packages/mdc-slider/index.js @@ -180,6 +180,8 @@ class MDCSlider extends MDCComponent { const min = parseFloat(this.root_.getAttribute(strings.ARIA_VALUEMIN)) || this.min; const max = parseFloat(this.root_.getAttribute(strings.ARIA_VALUEMAX)) || this.max; + // min and max need to be set in the right order to avoid throwing an error + // when the new min is greater than the default max. if (min >= this.max) { this.max = max; this.min = min;