Skip to content

Commit 4ae1b05

Browse files
committed
resume scroll on non firefox browsers only if clicking scrollbar
1 parent 433c374 commit 4ae1b05

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/useActive.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import {
1414
ref,
1515
getEdges,
1616
useMediaRef,
17+
isScrollbarClick,
1718
isSSR,
18-
FIXED_OFFSET,
1919
defaultOptions as def,
20+
FIXED_OFFSET,
2021
} from './utils'
2122
import type { UseActiveOptions, ShortRef, Targets } from './types'
2223

@@ -134,13 +135,19 @@ export function useActive(userTargets: Targets, options: UseActiveOptions = def)
134135
* Utils - Scroll
135136
* ==================================================================================== */
136137

137-
function setActive({ prevY, isCancel = false }: { prevY: number; isCancel?: boolean }) {
138+
function setActive({
139+
prevY,
140+
isScrollCancel = false,
141+
}: {
142+
prevY: number
143+
isScrollCancel?: boolean
144+
}) {
138145
const nextY = getCurrentY()
139146

140147
if (nextY < prevY) {
141148
onScrollUp()
142149
} else {
143-
onScrollDown({ isCancel })
150+
onScrollDown({ isScrollCancel })
144151
}
145152

146153
return nextY
@@ -163,7 +170,7 @@ export function useActive(userTargets: Targets, options: UseActiveOptions = def)
163170
}
164171

165172
// Sets first target-top that LEFT the root
166-
function onScrollDown({ isCancel } = { isCancel: false }) {
173+
function onScrollDown({ isScrollCancel } = { isScrollCancel: false }) {
167174
let firstOutEl = jumpToFirst ? targets.els[0] : null
168175

169176
const sentinel = getSentinel()
@@ -196,7 +203,7 @@ export function useActive(userTargets: Targets, options: UseActiveOptions = def)
196203
if (isNext || (firstOutEl && !activeEl.v)) return (activeEl.v = firstOutEl)
197204

198205
// ...but not on scroll cancel
199-
if (isCancel) activeEl.v = firstOutEl
206+
if (isScrollCancel) activeEl.v = firstOutEl
200207
}
201208

202209
// Sets first target-bottom that ENTERED the root
@@ -345,13 +352,15 @@ export function useActive(userTargets: Targets, options: UseActiveOptions = def)
345352

346353
function onScrollCancel(event: PointerEvent) {
347354
const isAnchor = (event.target as HTMLElement).tagName === 'A'
355+
const isFireFox = window.CSS.supports('-moz-appearance', 'none')
356+
const isScrollbar = isScrollbarClick(event)
348357

349-
if (!isAnchor) {
358+
if ((isFireFox || isScrollbar) && !isAnchor) {
350359
const { isBottom, isTop } = getEdges(root.v)
351360

352361
if (!isTop && !isBottom) {
353362
restoreHighlight()
354-
setActive({ prevY: clickStartY.v, isCancel: true })
363+
setActive({ prevY: clickStartY.v, isScrollCancel: true })
355364
}
356365
}
357366
}

src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ export function getEdges(root: HTMLElement) {
6969
}
7070
}
7171

72+
export function isScrollbarClick(event: PointerEvent) {
73+
console.log('isScrollbarClick', event.clientX >= window.innerWidth - 17)
74+
75+
return event.clientX >= window.innerWidth - 17
76+
}
77+
7278
export const defaultOptions = {
7379
jumpToFirst: true,
7480
jumpToLast: true,

0 commit comments

Comments
 (0)