malte-wessel/react-textfit

Issue calculating the font size

santigimeno opened this issue · 4 comments

I'm new to react and just started using this component so maybe my observations are far from correct but there we go.

My issue is that sometimes the font-size calculated is by far too small. By adding some logs I've observed that the issue was that the originalWidth calculated at first wasn't correct (it returned a less width of what it should) so the algorithm resulted in an incorrect font-size. I corrected the issue by making sure that every time the algorithm called assertElementFitsHeight and assertElementFitsWidth the innerWidth and innerHeight was retrieved again from the element. Does this make any sense?

Thanks!

Thank you for details provided in the post. Do you think you could demonstrate an example using something like jsfiddle.net, or a fork or any tooling of your choice?

https://codesandbox.io/s/73AJMQ7jO
Hi, I have created a demo. Font unpredictably enlages by clicking.

@StipJey thanks for the example. That's exactly what I'm observing

Beautiful, thank you, @StipJey! Seems like definitely a bug, indeed.