Skip to content

Commit 3ef83ce

Browse files
mikasaywCopilottdesign-bot
authored
fix(ImageViewer): 修复预览图片点击右键后失焦跟随鼠标移动的问题 (#6098)
* fix(ImageViewer): 修复预览图片上右键后失焦跟随鼠标移动的问题 * fix(ImageViewer): update mousedown event logic * Update packages/components/image-viewer/hooks/index.ts 触摸事件没有button属性,会正常处理 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * revert(image-viewer): revert copilot commit revert copilot commit * chore: stash changelog [ci skip] --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent 1a5aa30 commit 3ef83ce

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/components/image-viewer/hooks/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export function useDrag(initTransform: InitTransform) {
1212
const transform = ref(initTransform);
1313

1414
const mouseDownHandler = (e: MouseEvent) => {
15+
// only move by left mouse click
16+
if ('button' in e && e.button !== 0) return;
17+
1518
const { pageX: startX, pageY: startY } = e;
1619
const { translateX, translateY } = transform.value;
1720
const mouseMoveHandler = (e: MouseEvent) => {
@@ -21,13 +24,19 @@ export function useDrag(initTransform: InitTransform) {
2124
translateY: translateY + pageY - startY,
2225
};
2326
};
24-
const mouseUpHandler = () => {
27+
28+
const removeHandler = () => {
2529
document.removeEventListener('mousemove', mouseMoveHandler);
2630
document.removeEventListener('mouseup', mouseUpHandler);
31+
document.removeEventListener('mouseleave', mouseLeaveHandler);
2732
};
2833

34+
const mouseUpHandler = () => removeHandler();
35+
const mouseLeaveHandler = () => removeHandler();
36+
2937
document.addEventListener('mousemove', mouseMoveHandler);
3038
document.addEventListener('mouseup', mouseUpHandler);
39+
document.addEventListener('mouseleave', mouseLeaveHandler);
3140
};
3241

3342
const resetTransform = () => {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 6098
3+
contributor: mikasayw
4+
---
5+
6+
- fix(ImageViewer): 修复预览图片时点击右键后失焦,预览图会跟随鼠标移动的问题 @mikasayw ([#6098](https://github.com/Tencent/tdesign-vue-next/pull/6098))

0 commit comments

Comments
 (0)