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

Feature Request: Option to Swap Only Initial and Final Positions #7

Closed
Danivalldo opened this issue Jul 23, 2024 · 7 comments
Closed

Comments

@Danivalldo
Copy link

Hello,

Firstly, I'd like to thank you for developing and maintaining this fantastic library. It has significantly simplified the implementation of drag-to-swap functionality in my projects.

Issue:

Currently, the library moves every element between the initial and final positions when an element is dragged and dropped. However, in my use case, I need an option to swap only the initial and final positions, without affecting the intermediate elements. This feature would provide greater flexibility and control over the layout behavior during drag-and-drop operations.

Example:

Here's an illustration of the current behavior and the desired behavior:

Current Behavior:

Initial: [A, B, C, D, E]
Drag 'A' to position of 'D'
Result: [B, C, D, A, E]
Desired Behavior:

Initial: [A, B, C, D, E]
Drag 'A' to position of 'D'
Result: [D, B, C, A, E]
Proposal:

I propose adding an option or method to enable swapping only the initial and final positions of the dragged element. This could be a configuration setting or a specific method call.

Benefits:

Enhanced flexibility for different use cases.
Greater control over the layout behavior during drag-and-drop.
More intuitive behavior for certain user interfaces.
Additional Context:

If needed, I can assist with testing the new feature or providing further examples of how this functionality could be utilized.

Thank you for considering this feature request. I look forward to your response and am hopeful that this can be incorporated into the library.

Best regards,

Danivalldo

@TahaSh
Copy link
Owner

TahaSh commented Jul 23, 2024

@Danivalldo Thank you! I'm really glad to hear you found it helpful. The library should behave as described in your "Desired Behavior" by only swapping the two elements without affecting others. However, if the cursor hovers over other elements while dragging, it will also swap them, which results in the "Current Behavior." Could you please test and confirm if that's the case? Thanks!

@Danivalldo
Copy link
Author

Hello,

Thank you for the quick response and the clarification. I tested the library again as per your instructions. Here are my observations:

Test Setup:

Initial setup: [A, B, C, D, E]
Drag 'A' to the position of 'D'

Steps Taken:
Dragged 'A' directly to the position of 'D' without hovering over any intermediate elements.
Dragged 'A' to the position of 'D' while intentionally hovering over 'B' and 'C'.

Results:

When dragging directly to 'D', the library swaps only 'A' and 'D' as expected: [D, B, C, A, E].
When dragging and hovering over 'B' and 'C', the library moves 'A' through the intermediate positions, resulting in: [B, C, D, A, E].
It appears that the second behavior is triggered when the cursor hovers over other elements during the drag. This is consistent with what you described.

Feedback:
The current behavior makes sense given the implementation, but it can be challenging to avoid hovering over intermediate elements in some layouts. A possible improvement could be to add an option to disable swapping during hover or to lock the swap behavior strictly to the initial and final positions, regardless of intermediate hover actions.

Please let me know if there's anything specific you would like me to test further or if additional details are needed.

Thank you for your support and the great work on this library!

@TahaSh
Copy link
Owner

TahaSh commented Jul 23, 2024

@Danivalldo Thank you for testing! Two solutions come to mind:

  1. Only swap after the user stops the cursor at a specific slot. I'll detect this based on the cursor's motion.
  2. Allow the developer to specify a drop target within the slot. This way, even if the cursor is on the slot, it won't swap until it's hovering over the target.

I think both options could be useful in different scenarios. I'll need to do some testing to ensure they provide a good user experience. I'll let you know when something is ready! Thanks!

@Danivalldo
Copy link
Author

Thank you for considering these solutions! Both ideas sound great and could be very useful. I appreciate your efforts to improve the library. Looking forward to testing the updates when they are ready!

@TahaSh
Copy link
Owner

TahaSh commented Jul 28, 2024

@Danivalldo I've added a new config option in v0.1.0 called continuousMode. If you disable it, the swapping will only happen if the user stops the cursor. You can disable it like this:

createSwapy(container, { continuousMode: false })

Let me know if you have any questions!

@Danivalldo
Copy link
Author

Hello,

Thank you for the update! I’ve tested the continuousMode option, and it works perfectly in my project. I appreciate your quick implementation of this feature.

Best regards,

@TahaSh
Copy link
Owner

TahaSh commented Jul 31, 2024

@Danivalldo Really glad to hear that! Thanks!

@TahaSh TahaSh closed this as completed Jul 31, 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

No branches or pull requests

2 participants