react-rnd icon indicating copy to clipboard operation
react-rnd copied to clipboard

resize snap to grid relative to dragged edge location

Open oldo opened this issue 8 years ago • 8 comments
trafficstars

I'm using react-rnd version [7.1.4]

First up, thanks so much for maintaining and developing this component. It has been fantastic and really intuitive to work with :-)

I have an issue that I can't seem to resolve though: I am rendering rnd components in various locations on my page and have enabled resizing in left and right directions and set them snap to a resizeGrid: [40, 0]. My desired behaviour is that when resizing I want the resize to snap to 40px to the left or right of the resized edge original location, however I'm finding that resizing is snapping to a global grid starting from the edge of the browser window.

So lets say I have an rnd component located with the right edge at 135px from the edge of browser window. When I drag to the right I want the next snap point to be at 135 + 40 = 175px, but instead I am finding that the first snap point is 160px.

Is there a way for resize grid to be relative to the location of the edge being dragged instead of a global grid?

Thanks :-)

oldo avatar Oct 17 '17 06:10 oldo

@oldo Thanks for your report. I'm gonna do some investigation. could you please wait for a while

bokuweb avatar Oct 18 '17 00:10 bokuweb

Thanks @bokuweb

Let me know if there is anything I can do down my end :-)

oldo avatar Oct 18 '17 00:10 oldo

Hi @bokuweb

Any news on this? :-)

oldo avatar Nov 08 '17 04:11 oldo

@oldo Sorry. I have not started yet...

bokuweb avatar Nov 08 '17 05:11 bokuweb

I have the same issue with the same configuration: left and right resizing and dragging with resize and drag grids.

I set the same configuration from this example.

Could it come from the parent containers CSS attributes ? Or maybe because my component is mapped to Redux ?

gabriel-cardoso avatar Apr 21 '18 17:04 gabriel-cardoso

I think it comes from the fact that my component is connected to Redux.

I manage to have it working by calling this.forceUpdate() on resize.

gabriel-cardoso avatar Apr 21 '18 18:04 gabriel-cardoso

Hi @gabriel-cardoso

Although my components are also connected to Redux, that didn't help me.

If I change the initial width and position in your code sandbox to I get the same snapping error where resize is snapping to a global grid instead of a grid relative to location of component:

constructor() {
  super();
  this.state = {
    width: 220,
    height: 200,
    x: 290,
    y: 10
  };
}

oldo avatar Apr 23 '18 05:04 oldo

Hi, I see this is a pretty old ticket. Is this library still being maintained? If not, do you recommend something else? If so, are you welcome to PRs to address problems and refactor the code? I'm coming from using react-dnd where I developed resizing on top of that, but I'm finding the implementation to be a bit convoluted and this library looks like a good alternative without having to handle synchronizing of drop zones and drag layers.

FullstackJack avatar Apr 09 '23 02:04 FullstackJack