malte-wessel / react-textfit

React component to fit headlines and paragraphs into elements
http://malte-wessel.github.io/react-textfit/
MIT License
470 stars 143 forks source link

Issue calculating the font size #25

Open santigimeno opened 7 years ago

santigimeno commented 7 years ago

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!

denis-sokolov commented 7 years ago

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?

StipJey commented 7 years ago

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

santigimeno commented 7 years ago

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

denis-sokolov commented 7 years ago

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