commit 92b82f64e587 Author: Scott Wu Date: Wed Sep 20 16:45:03 2017 +0800 Bug 1397114 - Disable smooth scrolling when value changes come from input box. r=mconley, a=ritu MozReview-Commit-ID: 9ZLSB2HQvcu --HG-- extra : source : f215f88437f1db1884858be2c78582ab2b11bbb0 --- toolkit/content/widgets/datepicker.js | 11 ++++++----- toolkit/content/widgets/spinner.js | 16 ++-------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git toolkit/content/widgets/datepicker.js toolkit/content/widgets/datepicker.js index 31651dc63665..b125c5103a9a 100644 --- toolkit/content/widgets/datepicker.js +++ toolkit/content/widgets/datepicker.js @@ -133,7 +133,7 @@ function DatePicker(context) { /** * Update date picker and its components. */ - _update() { + _update(options = {}) { const { dateKeeper, isMonthPickerVisible } = this.state; if (isMonthPickerVisible) { @@ -148,7 +148,8 @@ function DatePicker(context) { dateObj: dateKeeper.state.dateObj, months: this.state.months, years: this.state.years, - toggleMonthPicker: this.state.toggleMonthPicker + toggleMonthPicker: this.state.toggleMonthPicker, + noSmoothScroll: options.noSmoothScroll }); this.components.calendar.setProps({ isVisible: !isMonthPickerVisible, @@ -269,7 +270,7 @@ function DatePicker(context) { dateKeeper.setSelection({ year, month, day }); - this._update(); + this._update({ noSmoothScroll: true }); } }; @@ -350,14 +351,14 @@ function DatePicker(context) { items: props.months, isInfiniteScroll: true, isValueSet: this.state.isMonthSet, - smoothScroll: !this.state.firstOpened + smoothScroll: !(this.state.firstOpened || props.noSmoothScroll) }); this.components.year.setState({ value: props.dateObj.getUTCFullYear(), items: props.years, isInfiniteScroll: false, isValueSet: this.state.isYearSet, - smoothScroll: !this.state.firstOpened + smoothScroll: !(this.state.firstOpened || props.noSmoothScroll) }); this.state.firstOpened = false; } else { diff --git toolkit/content/widgets/spinner.js toolkit/content/widgets/spinner.js index 101cb01658a0..0a30766f8d13 100644 --- toolkit/content/widgets/spinner.js +++ toolkit/content/widgets/spinner.js @@ -124,8 +124,6 @@ function Spinner(props, context) { /** * Whenever scroll event is detected: * - Update the index state - * - If a smooth scroll has reached its destination, set [isScrolling] state - * to false * - If the value has changed, update the [value] state and call [setValue] * - If infinite scrolling is on, reset the scrolling position if necessary */ @@ -138,14 +136,8 @@ function Spinner(props, context) { const value = itemsView[this.state.index + viewportTopOffset].value; - // Check if smooth scrolling has reached its destination. - // This prevents input box jump when input box changes values. - if (this.state.value == value && this.state.isScrolling) { - this.state.isScrolling = false; - } - - // Call setValue if value has changed, and is not smooth scrolling - if (this.state.value != value && !this.state.isScrolling) { + // Call setValue if value has changed + if (this.state.value != value) { this.state.value = value; this.props.setValue(value); } @@ -444,10 +436,6 @@ function Spinner(props, context) { _smoothScrollToIndex(index) { const element = this.elements.spinner.children[index]; if (element) { - // Set the isScrolling flag before smooth scrolling begins - // and remove it when it has reached the destination. - // This prevents input box jump when input box changes values - this.state.isScrolling = true; element.scrollIntoView({ behavior: "smooth", block: "start" });