I am using Draft.js plugin Resizeable.
I am trying to resize the image with original length-to-width ratio.
However, for the code below, when I use the mouse to resize by the bottom edge of the image, the cursor changed, but it failed to resize. It only works well at the left and right edge.
const resizeablePlugin = createResizeablePlugin({
vertical: 'relative',
horizontal: 'relative'
});
After viewing the source code, I still didn't figure out what causes this.
It does not seem like developers of this plugin had provided this opportunity to change image size with saving ratio when you resize by the top or bottom edges. Configuration option
vertical: 'relative'
means that plugin should setheight
value in relative units (percents). You can check with devtools that when you try to resize your imageheight
value does change. But we should changewidth
value to reach the behaviour when we resize the image with saving ratio.It can be achieved by rewriting the source code a bit. Check this fork of your sandbox.
Check
createDecorator.js
it is the same file that is stored in/node_modules/draft-js-resizeable-plugin/lib/createDecorator.js
. What did I change in it? FinddoDrag
function (I market with// !
all strings that was added or changed):I think you can ask this plugin dev-team for add this feature or fork the project.