Skip to content

Commit 44e8dcf

Browse files
fix glitch when dragAxis is enabled and component is being resized (#780)
* fix glitch when dragAxis is enabled and component is being resized * Added new axisGrid story
1 parent 6b4d71b commit 44e8dcf

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ export class Rnd extends React.PureComponent<Props, State> {
616616
}
617617
// INFO: Make uncontorolled component when resizing to control position by setPostion.
618618
const pos = this.resizing ? undefined : draggablePosition;
619+
const dragAxisOrUndefined = this.resizing ? "both" : dragAxis;
619620

620621
return (
621622
<Draggable
@@ -627,7 +628,7 @@ export class Rnd extends React.PureComponent<Props, State> {
627628
onStart={this.onDragStart}
628629
onDrag={this.onDrag}
629630
onStop={this.onDragStop}
630-
axis={dragAxis}
631+
axis={dragAxisOrUndefined}
631632
disabled={disableDragging}
632633
grid={dragGrid}
633634
bounds={bounds ? this.state.bounds : undefined}

stories/dragAxis/dragAxis.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from "react";
2+
import { Rnd } from "../../src";
3+
import { style } from "../styles";
4+
5+
type State = {
6+
x: number;
7+
y: number;
8+
width: number | string;
9+
height: number | string;
10+
};
11+
12+
export default class dragAxis extends React.Component<{}, State> {
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
width: 100,
17+
height: 100,
18+
x: 0,
19+
y: 0,
20+
};
21+
}
22+
23+
render() {
24+
return (
25+
<Rnd
26+
style={style}
27+
size={{ width: this.state.width, height: this.state.height }}
28+
position={{ x: this.state.x, y: this.state.y }}
29+
onDragStop={(e, d) => {
30+
this.setState({ ...this.state, ...d });
31+
}}
32+
onResizeStop={(e, direction, ref, delta, position) => {
33+
this.setState({
34+
...this.state,
35+
width: ref.style.width,
36+
height: ref.style.height,
37+
...position,
38+
});
39+
}}
40+
dragAxis="x"
41+
>
42+
001
43+
</Rnd>
44+
);
45+
}
46+
}

stories/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import Cancel from "./cancel/cancel";
3535

3636
import ResizeHandleComponent from "./customization/resizeHandleComponent";
3737

38+
import DragAxis from "./dragAxis/dragAxis";
39+
3840
import GridResize from "./grid/resize";
3941
import GridDrag from "./grid/drag";
4042
import GridBoth from "./grid/both";
@@ -80,6 +82,8 @@ storiesOf("cancel", module).add("cancel", () => <Cancel />);
8082

8183
storiesOf("customization", module).add("resizeHandleComponent", () => <ResizeHandleComponent />);
8284

85+
storiesOf("dragAxis", module).add("dragAxis", () => <DragAxis />);
86+
8387
storiesOf("grid", module)
8488
.add("resize", () => <GridResize />)
8589
.add("drag", () => <GridDrag />)

0 commit comments

Comments
 (0)