Skip to content

Commit 74096b2

Browse files
committed
fix: 优化 touch mouse 事件同时绑定及navigator a 标签阻止默认事件
1 parent adb326c commit 74096b2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/uni-components/src/helpers/useHover.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ export function useHover(props: UseHoverOptions) {
4545
if (evt.touches.length > 1) {
4646
return
4747
}
48-
handleHover(evt)
48+
handleHoverStart(evt)
4949
}
5050

5151
function onMousedown(evt: MouseEvent) {
52-
evt.preventDefault()
53-
handleHover(evt)
52+
if (hoverTouch) {
53+
return
54+
}
55+
56+
handleHoverStart(evt)
5457
window.addEventListener('mouseup', handlePCHoverEnd)
5558
}
5659

57-
function handleHover(evt: TouchEvent | MouseEvent) {
60+
function handleHoverStart(evt: TouchEvent | MouseEvent) {
5861
// TODO detect scrolling
5962
if ((evt as any)._hoverPropagationStopped) {
6063
return
@@ -80,6 +83,10 @@ export function useHover(props: UseHoverOptions) {
8083
}
8184

8285
function onMouseup() {
86+
if (!hoverTouch) {
87+
return
88+
}
89+
8390
handlePCHoverEnd()
8491
}
8592

packages/uni-components/src/vue/navigator/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export default /*#__PURE__*/ defineBuiltInComponent({
2727
const hasHoverClass = props.hoverClass && props.hoverClass !== 'none'
2828

2929
return (
30-
<a class="navigator-wrap" href={url} onClick={onEventPrevent}>
30+
<a
31+
class="navigator-wrap"
32+
href={url}
33+
onClick={onEventPrevent}
34+
onMousedown={onEventPrevent}
35+
>
3136
<uni-navigator
3237
class={hasHoverClass && hovering.value ? hoverClass : ''}
3338
{...(hasHoverClass && binding)}

0 commit comments

Comments
 (0)