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

feat: add custom dragstart event and improve drag enter/leave handling #6

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

colecrouter
Copy link
Contributor

Similar issue to #2, the drag-over class doesn't always get removed properly.

For example, if you have two droppable containers very close to each other, dragging a droppable from one to the other causes both containers to get the class. This happens due to the speed/order the events are handled.

What I removed:

  • The global state check ("this element equals target element") as it has proven unreliable

What I added:

  • A simple counter for drag events on droppable
  • A custom event from draggable to droppable (to remove the class from the source droppable since dragleave does not occur there)

@colecrouter colecrouter force-pushed the main branch 2 times, most recently from cf4f62e to 46e9e38 Compare November 26, 2024 16:53
@colecrouter
Copy link
Contributor Author

ezgif-2-94bc0aaa46

For reference, here's what this is about. These two containers are 10px apart, and you can see what happens. At standard refresh rates, the issue is much more apparent.

@Spikeysanju
Copy link
Contributor

This pull request includes changes to enhance the drag-and-drop functionality in the draggable and droppable actions. The key improvements involve adding custom events, managing drag enter/leave state with a counter, and ensuring proper cleanup of event listeners.

Improvements to draggable action:

  • src/lib/actions/draggable.ts: Added a custom event dragstart-on-container that bubbles up to the container to signal the start of a drag operation.

Enhancements to droppable action:

@Spikeysanju
Copy link
Contributor

@colecrouter , thanks for the PR! I've reviewed it. Will merge it to production when I'm back home tomorrow. Have a great day!

@Spikeysanju Spikeysanju merged commit 6e08a96 into thisuxhq:main Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants