Skip to content

Feature request: Resize in both the dragged direction and its opposite? #740

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
Nantris opened this issue Sep 13, 2020 · 5 comments
Open

Comments

@Nantris
Copy link

Nantris commented Sep 13, 2020

Overview of the problem

I'm using react-rnd version 10.2.1

My browser is: Chrome 82

I am sure this issue is not a duplicate? Pretty certain, but maybe I missed it

Description

Feature request: When dragging in one direction, is it possible to have the box grow in that direction and its opposite? For example, if you drag the left edge, the box would grow on both the left and right sides simultaneously.

@sujoyduttajad
Copy link

It's possible and I have created it. But it depends on the containers inside which you are creating this draggable component. If you are using position: relative; which should be the same in all the parent containers then the component will resize in both the direction provided there is no bounds. To remove this just add position: absolute;

@Nantris
Copy link
Author

Nantris commented Nov 5, 2021

@sujoyduttajad great tip! Does resizing from the left edge/corners work properly for you though? For us, it instead does a weird hybrid move/grow when we set it to use position: relative;

@sujoyduttajad
Copy link

You need to set the parameters accordingly, I mean for which direction you want the resize to occur. For ex- if you did left: true and other directions as false then resize will happen only on left. For me I haven't faced any corner resize issue.

@Nantris
Copy link
Author

Nantris commented Nov 5, 2021

Unfortunately we have all directions of resize enabled when we're seeing this issue.

Dragging right: The box expands left and right, with the mid-point remaining fixed

Dragging left: The box expands leftward, but the right edge also moves leftward, at maybe half the rate that the left edge does. This results in the mid-point of the box moving leftward.

@noffy-tech
Copy link

noffy-tech commented Mar 26, 2024

Try this will help you. Dont use onResizeStop to set the positions

<Rnd
            bounds="window"
            size={{ width: position.width, height: position.height }}
            position={{ x: position.x, y: position.y }}
            minWidth={minWidthDialog}
            minHeight={minHeightDialog}
            dragHandleClassName="draggable-title"
            enableUserSelectHack={false}
            onDragStop={onDragStop}
            onResize={onResize}
          >

onResize :

const onResize: RndResizeCallback = (_e, _direction, ref) => {
    const { x, y } = ref.getBoundingClientRect();
    const onResizePosition = {
      x,
      y,
      width: ref.clientWidth,
      height: ref.clientHeight,
    };
    setPosition(onResizePosition);
  };

onDragStop :

const onDragStop: RndDragCallback = (_e, d) => {
    setPosition(previous => ({ ...previous, x: d.x, y: d.y }));
  };

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants