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

draggable with snapGrid moves incomplete steps to respect restriction #208

Closed
razvanphp opened this issue Jun 15, 2015 · 5 comments
Closed

Comments

@razvanphp
Copy link
Contributor

I edited this jsfiddle to reflect my problem.

Normally in my case restriction: 'parent' should be fine, because the snap option would not permit the object to move an incomplete step (container size is not divisible by grid size).

To overcome this issue I have to build a custom hacky restriction:

restriction: {
    x: parent.offset().left,
    y: parent.offset().top + 1,
    width: parent.width(),
    height: parent.height()
}

In my opinion, this last move should not be allowed, since the grid AND the restriction should be respected, but at least should be a configurable option.

@taye
Copy link
Owner

taye commented Jun 20, 2015

In my opinion, this last move should not be allowed, since the grid AND the restriction should be respected

I agree. I haven't thought of a good way to implement this yet. I'll keep it in mind and will try come back to it if I or anyone else comes up with something good.

@taye taye closed this as completed in d549672 Nov 20, 2015
@razvanphp
Copy link
Contributor Author

Thank you for this, but I don't understand how this helps, I already have the limit set manually in restriction, my understand was that this is a bug...

@taye
Copy link
Owner

taye commented Nov 20, 2015

It's not a bug. The snap and restrict modifiers are independent and unaware of each other so there's no way for grid snapping to automatically consider restriction unless that separation is broken (which I think is a bad idea). Also, it's not always possible to ensure that both restriction and snapping are respected – what should be done if all points on the grid are outside the restriction? It's an unlikely configuration but I think it's worth considering. The grid.limits option provides a more convenient way to ensure that the snapped coordinates aren't beyond the restriction that you've set.

Technically, it's not that snapping is applied incompletely/wrongly to respect restriction, but rather that restriction is applied after snapping and that changes the coordinates from the previous modified values. If you want to maintain a custom build, you can change the order of the modifiers in the src/index.js file or write a module that adds "snap" to the modifiers.names array a second time after "restrict" so that snapping is done both first and last.

With these solutions, I consider the issue resolved. I'm open to any suggestions you have.

@razvanphp
Copy link
Contributor Author

Makes total sense. Just swapping the order would not help? Then it can maybe be the default.

I understand the technical separation and I agree it should stay like it is. But when somebody uses both of them, one expects that both modifiers are respected, and that is not the case here.

@taye
Copy link
Owner

taye commented Nov 22, 2015

Makes total sense. Just swapping the order would not help? Then it can maybe be the default.

Actually, in the demo that you gave, swapping the order doesn't really help. It would just mean that the restriction wouldn't be respected instead of snapping. With different restriction and grid dimensions it could be beneficial.

I understand the technical separation and I agree it should stay like it is. But when somebody uses both of them, one expects that both modifiers are respected, and that is not the case here.

I don't see any good way to make sure that all modifiers are always respected. With the possibility of new modifiers being added, I don't want to try to maintain such a guarantee.

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