From f2f66b3e6453eadfb620900a6a47c896c24772f3 Mon Sep 17 00:00:00 2001 From: zazzaz Date: Mon, 11 Jan 2021 10:33:23 +0800 Subject: [PATCH] fix: fix time picker scroll bug (#1227) * fix: fix time picker scroll bug * chore: update * chore: update --- .../src/time-picker-com/basic-time-spinner.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/time-picker/src/time-picker-com/basic-time-spinner.vue b/packages/time-picker/src/time-picker-com/basic-time-spinner.vue index 9abad475a6..63e533182e 100644 --- a/packages/time-picker/src/time-picker-com/basic-time-spinner.vue +++ b/packages/time-picker/src/time-picker-com/basic-time-spinner.vue @@ -64,6 +64,7 @@ import { PropType, } from 'vue' import { Dayjs } from 'dayjs' +import debounce from 'lodash/debounce' import { RepeatClick } from '@element-plus/directives' import ElScrollbar from '@element-plus/scrollbar' import { getTimeLists } from './useTimePicker' @@ -111,6 +112,11 @@ export default defineComponent({ setup(props, ctx) { // data + let isScrolling = false + const debouncedResetScroll = debounce(type => { + isScrolling = false + adjustCurrentSpinner(type) + }, 200) const currentScrollbar = ref(null) const listHoursRef: Ref> = ref(null) const listMinutesRef: Ref> = ref(null) @@ -284,6 +290,8 @@ export default defineComponent({ } const handleScroll = type => { + isScrolling = true + debouncedResetScroll(type) const value = Math.min(Math.round((listRefsMap[type].value.$el.querySelector('.el-scrollbar__wrap').scrollTop - (scrollBarHeight(type) * 0.5 - 10) / typeItemHeight(type) + 3) / typeItemHeight(type)), (type === 'hours' ? 23 : 59)) modifyDateField(type, value) } @@ -333,7 +341,10 @@ export default defineComponent({ props.disabledSeconds, ) - watch(() => props.spinnerDate, adjustSpinners) + watch(() => props.spinnerDate, () => { + if (isScrolling) return + adjustSpinners() + }) return { getRefId,