Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(onClickOutside): adds ignoreDragging option #3833

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
Loading
from

Conversation

bobbybol
Copy link

@bobbybol bobbybol commented Mar 1, 2024

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

Additional context

…ndler to fire when a user is dragging outside target element
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 1, 2024
@antfu antfu changed the title feat(ignoreDrag): adds ignoreDrag option to prevent onClickOutside handler to fire when a user is dragging outside target element feat(ignoreDrag): adds ignoreDrag option Jul 17, 2024
@antfu antfu changed the title feat(ignoreDrag): adds ignoreDrag option feat(onClickOutside): adds ignoreDraging option Jul 17, 2024
@antfu antfu changed the title feat(onClickOutside): adds ignoreDraging option feat(onClickOutside): adds ignoreDragging option Jul 17, 2024
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 17, 2024
@antfu antfu added size:S This PR changes 10-29 lines, ignoring generated files. needs refactor and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 17, 2024
@brokuka
Copy link

brokuka commented Jul 25, 2024

any news?

@bobbybol
Copy link
Author

@antfu What about this PR?

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Dec 29, 2024
Comment on lines +76 to +78
const startDragListener = ({ x, y }: PointerEvent) => {
stopDragListener = useEventListener(window, 'pointermove', (e) => {
const dX = Math.abs(x - e.x)
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure if we should call useEventListener inside a function.

This might lead to unexpected behaviour.

Copy link
Collaborator

@OrbisK OrbisK left a comment

Choose a reason for hiding this comment

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

@bobbybol can you please dont create the eventlistener inside the function. if we call this function multiple times, it will create a memory leak.

@bobbybol
Copy link
Author

bobbybol commented Feb 6, 2025

@bobbybol can you please dont create the eventlistener inside the function. if we call this function multiple times, it will create a memory leak.

Hi @OrbisK I can go two ways with this:
A. Make absolutely sure the listener is removed before starting another one, while still having the listener inside the function. Something like:

if (stopDragListener) {
  stopDragListener()
  stopDragListener = undefined
}

B. Have a persistent listener (only attached if ignoreDragging isn't false of course) that compares pointermove coordinates to the point where the original pointerdown occurred. This is a little more involved because now you need to store the coordinates of the original pointerdown event in a variable outside of all the handler functions, but can be mutated by three different event handlers (click, pointerdown, and pointermove),

Let me know which route you prefer, and I will make it happen ☺️.

@OrbisK
Copy link
Collaborator

OrbisK commented Feb 6, 2025

@bobbybol can you please dont create the eventlistener inside the function. if we call this function multiple times, it will create a memory leak.

Hi @OrbisK I can go two ways with this: A. Make absolutely sure the listener is removed before starting another one, while still having the listener inside the function. Something like:

if (stopDragListener) {
  stopDragListener()
  stopDragListener = undefined
}

B. Have a persistent listener (only attached if ignoreDragging isn't false of course) that compares pointermove coordinates to the point where the original pointerdown occurred. This is a little more involved because now you need to store the coordinates of the original pointerdown event in a variable outside of all the handler functions, but can be mutated by three different event handlers (click, pointerdown, and pointermove),

Let me know which route you prefer, and I will make it happen ☺️.

Why cant we just have the listener at setup level?

(POC)

useEventListener(window, 'pointermove', (e) => {
 if(!isDragging.value)  return
 //...
}

startDragging = ()=>{isDragging.value = true}

We only have one listener on the window. I think this should work, no?

If we want to only add the listener when dragging i think we can use a reactive target like:

const target = computed((()=>{
  isDragging.value ? window : null
})

useEventListener(target, 'pointermove', (e) => {
 //...
}

with this useEventListener should do all the work for us

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs test size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.