mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
refactor(components): [scrollbar] Simplifying updateTriggerStatus (#21485)
* refactor(components): [scrollbar] Simplifying updateTriggerStatus * Update packages/components/scrollbar/src/scrollbar.vue Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> --------- Co-authored-by: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com>
This commit is contained in:
@@ -71,7 +71,6 @@ const distanceScrollState = {
|
||||
right: false,
|
||||
left: false,
|
||||
}
|
||||
type distanceScrollStateKey = keyof typeof distanceScrollState
|
||||
|
||||
const scrollbarRef = ref<HTMLDivElement>()
|
||||
const wrapRef = ref<HTMLDivElement>()
|
||||
@@ -101,31 +100,25 @@ const shouldSkipDirection = (direction: ScrollbarDirection) => {
|
||||
return distanceScrollState[direction] ?? false
|
||||
}
|
||||
|
||||
const DIRECTION_PAIRS: Record<ScrollbarDirection, ScrollbarDirection> = {
|
||||
top: 'bottom',
|
||||
bottom: 'top',
|
||||
left: 'right',
|
||||
right: 'left',
|
||||
}
|
||||
const updateTriggerStatus = (arrivedStates: Record<string, boolean>) => {
|
||||
const _updateTriggerState = (to: string, from: string) => {
|
||||
const arrived = arrivedStates[to]
|
||||
const oppositeArrived = arrivedStates[from]
|
||||
const triggerKey = to as distanceScrollStateKey
|
||||
const oppositeTriggerKey = from as distanceScrollStateKey
|
||||
if (arrived && !distanceScrollState[triggerKey]) {
|
||||
distanceScrollState[triggerKey] = true
|
||||
}
|
||||
if (!oppositeArrived && distanceScrollState[oppositeTriggerKey]) {
|
||||
distanceScrollState[oppositeTriggerKey] = false
|
||||
}
|
||||
const oppositeDirection = DIRECTION_PAIRS[direction]
|
||||
if (!oppositeDirection) return
|
||||
|
||||
const arrived = arrivedStates[direction]
|
||||
const oppositeArrived = arrivedStates[oppositeDirection]
|
||||
|
||||
if (arrived && !distanceScrollState[direction]) {
|
||||
distanceScrollState[direction] = true
|
||||
}
|
||||
// scroll bottom to top
|
||||
if (direction === 'top') {
|
||||
_updateTriggerState('top', 'bottom')
|
||||
}
|
||||
if (direction === 'bottom') {
|
||||
_updateTriggerState('bottom', 'top')
|
||||
}
|
||||
if (direction === 'left') {
|
||||
_updateTriggerState('left', 'right')
|
||||
}
|
||||
if (direction === 'right') {
|
||||
_updateTriggerState('right', 'left')
|
||||
|
||||
if (!oppositeArrived && distanceScrollState[oppositeDirection]) {
|
||||
distanceScrollState[oppositeDirection] = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user