Skip to content

Commit 5f2f8d9

Browse files
committed
improve pointerdown smoothscroll cancelation
1 parent 008438a commit 5f2f8d9

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/useScroll.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { watch, onMounted, ref, computed, type Ref, type ComputedRef } from 'vue';
2-
import { isChromium, isSSR, useMediaRef } from './utils';
2+
import { isFirefox, useMediaRef } from './utils';
33

44
type UseScrollOptions = {
55
isWindow: ComputedRef<boolean>;
@@ -86,9 +86,8 @@ export function useScroll({
8686

8787
function onPointerDown(event: PointerEvent) {
8888
const isLink = (event.target as HTMLElement).tagName === 'A';
89-
const hasLink = (event.target as HTMLElement).closest('a');
9089

91-
if (!isChromium && !isLink && !hasLink) {
90+
if (!isLink && isFirefox()) {
9291
reScroll();
9392
// ...and force set if canceling scroll
9493
setActive({ prevY: clickY.value, isCancel: true });
@@ -113,10 +112,6 @@ export function useScroll({
113112
watch(
114113
[isIdle, matchMedia, root],
115114
([_isIdle, _matchMedia, _root], _, onCleanup) => {
116-
if (isSSR) {
117-
return;
118-
}
119-
120115
const rootEl = isWindow.value ? document : _root;
121116
const isActive = rootEl && _isIdle && _matchMedia;
122117

src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export const isSSR = typeof window === 'undefined';
55
export const FIXED_TO_TOP_OFFSET = 10;
66
export const FIXED_OFFSET = 5;
77

8-
export const isChromium = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
8+
export function isFirefox() {
9+
return CSS.supports('-moz-appearance', 'none');
10+
}
911

1012
// When users set refs, if no media match, set default value
1113
export function useMediaRef<T>(matchMedia: Ref<boolean>, defaultValue: T): Ref<T> {

0 commit comments

Comments
 (0)