Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useDraggable): use clientX instead of pageX, close #2053 #2054

Merged
merged 2 commits into from Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/useDraggable/index.ts
Expand Up @@ -104,8 +104,8 @@ export function useDraggable(target: MaybeComputedRef<HTMLElement | SVGElement |
return
const rect = resolveUnref(target)!.getBoundingClientRect()
const pos = {
x: e.pageX - rect.left,
y: e.pageY - rect.top,
x: e.clientX - rect.left,
y: e.clientY - rect.top,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One interesting tidbit is that this pretty much assumes "position: fixed". That's also the only thing that can be implemented in a sane manner, as far as I can tell.

}
if (options.onStart?.(pos, e) === false)
return
Expand All @@ -118,8 +118,8 @@ export function useDraggable(target: MaybeComputedRef<HTMLElement | SVGElement |
if (!pressedDelta.value)
return
position.value = {
x: e.pageX - pressedDelta.value.x,
y: e.pageY - pressedDelta.value.y,
x: e.clientX - pressedDelta.value.x,
y: e.clientY - pressedDelta.value.y,
}
options.onMove?.(position.value, e)
handleEvent(e)
Expand Down