Skip to content

Commit 6932b5d

Browse files
simzarSTRML
authored andcommitted
#105 Fix resize with n/s handles on locked aspect ratio (#106)
* #105 Fix resize with n/s handles on locked aspect ratio * #105 Cleanup code after review
1 parent 6b63592 commit 6932b5d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/Resizable.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,17 @@ export default class Resizable extends React.Component<Props, State> {
136136
const [min, max] = [this.props.minConstraints, this.props.maxConstraints];
137137

138138
if (this.props.lockAspectRatio) {
139-
const ratio = this.state.width / this.state.height;
140-
height = width / ratio;
141-
width = height * ratio;
139+
if (height === this.state.height) {
140+
const ratio = this.state.width / this.state.height;
141+
height = width / ratio;
142+
width = height * ratio;
143+
} else {
144+
// Take into account vertical resize with N/S handles on locked aspect
145+
// ratio. Calculate the change height-first, instead of width-first
146+
const ratio = this.state.height / this.state.width;
147+
width = height / ratio;
148+
height = width * ratio;
149+
}
142150
}
143151

144152
if (!min && !max) return [width, height];

0 commit comments

Comments
 (0)