Can’t select texts on a rectangle 【fabric js】

I have been developing software which enable my colleagues to finish their tasks more effectively. In order to make it, it is necessary to use a library, fabric js. Since there was a problem it took much time to solve, I’ ll introduce it.

Library => http://fabricjs.com/

can’t select texts on a rectangle

There is texts on a rectangle in canvas like below.

However, when a cursor is on the texts, they aren’t selected after moving the objects. Instead of that, the rectangle is selected.

Solution

That problem can be resolved by executing setCoords

https://github.com/fabricjs/fabric.js/wiki/When-to-call-setCoords

Fabric js has to recalculate objects’ control position after moving objects.

target.text.left = target.left // target is rectangle objecttarget.text.top = target.toptarget.setCoords()target.text.setCoords()

Texts can be selected!

My LinkedIn account is below! Please contact me!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi

Senior Software Engineer Senior Software Engineer at an industry-leading startup( Ruby | JavaScript | Go | Rails | React | Redux | Gin)