fix: fix time picker scroll bug (#1227)

* fix: fix time picker scroll bug

* chore: update

* chore: update
This commit is contained in:
zazzaz 2021-01-11 10:33:23 +08:00 committed by GitHub
parent 1efee81cf3
commit f2f66b3e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<Nullable<HTMLElement>> = ref(null)
const listMinutesRef: Ref<Nullable<HTMLElement>> = 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,