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

Bug: onResize does not respect resizeGrid #901

Closed
jonocodes opened this issue Jan 6, 2023 · 4 comments
Closed

Bug: onResize does not respect resizeGrid #901

jonocodes opened this issue Jan 6, 2023 · 4 comments

Comments

@jonocodes
Copy link

jonocodes commented Jan 6, 2023

Description

If I set a dragGrid, then onDrag callbacks fire only when the mouse takes a step in the grid. This is expected.
If I set a resizeGrid, then onResize callbacks fire every time the mouse moves one pixel - ignoring the grid. This is not expected.

Overview of the problem

I'm using react-rnd version 10.3.3

My browser is: Firefox and Chrome

Reproduced project

https://codesandbox.io/s/modest-wood-ys66zi?file=/src/index.js

Also pasted below.

import React from "react";
import { render } from "react-dom";
import { Rnd } from "react-rnd";

const style = {
  display: "flex",
  alignItems: "center",
  justifyContent: "center",
  border: "solid 1px #ddd",
  background: "#f0f0f0"
};

class App extends React.Component {
  constructor() {
    super();
    this.state = {
      width: 200,
      height: 200,
      x: 10,
      y: 10
    };
  }

  render() {
    return (
      <Rnd
        style={style}
        size={{ width: this.state.width, height: this.state.height }}
        position={{ x: this.state.x, y: this.state.y }}
        dragGrid={[50, 50]}
        resizeGrid={[50, 50]}
        onDrag={(e, data) => {
          // logs every 50 pixels. expected
          console.log('onDrag', data)
        }}
        onResize={(e, dir, ref, delta, pos) => {
          // logs every 1 pixel. not expected
          console.log('onResize', dir, delta, pos)
        }}
      >
        Rnd
      </Rnd>
    );
  }
}

render(<App />, document.getElementById("root"));
@jonocodes jonocodes changed the title onResize does not respect resizeGrid Bug: onResize does not respect resizeGrid Jan 6, 2023
@quyle92
Copy link

quyle92 commented Feb 15, 2023

I've just tested your sample code and noticed that it did respect the resizeGrid but there is another problem which is when I resized it and then released the cursor, it immediately went back to original state.

@bokuweb
Copy link
Owner

bokuweb commented Apr 21, 2024

Ah, ok, it is re-resizable issue i'll fix it.

@bokuweb
Copy link
Owner

bokuweb commented Apr 21, 2024

bokuweb/re-resizable#783

@bokuweb
Copy link
Owner

bokuweb commented Apr 21, 2024

@jonocodes Fixed by 10.4.10

https://codesandbox.io/p/sandbox/youthful-tamas-5h3q2z?file=%2Fpackage.json

@bokuweb bokuweb closed this as completed Apr 21, 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

3 participants