fitty icon indicating copy to clipboard operation
fitty copied to clipboard

Event when text doesn't fit

Open mightym opened this issue 7 months ago • 2 comments

Hey guys, awesome library. Works really great and solved a big issue I had!

One question, when using multiLine: false is there maybe a way to get an event or check somehow when the text doesn't fit anymore? My usecase for fitty is a dynamic text, entered by the user. And as soon that text would be too long to fit I would like to notify the user about it/block the ui that he is only able to type X characters.

mightym avatar Apr 09 '25 19:04 mightym

Hey, glad to hear it's a good fit (no pun intended). I don't think this is currently possible, perhaps you can use a MutationObserver to check the current styles set in the style attribute, if the font size is the minimum font size the max characters has been reached?

rikschennink avatar Apr 10 '25 06:04 rikschennink

@rikschennink thanks a lot for your quick reply, really appreciate that! Yeah I already tried that. The issue is that I don't have a max character count. As using 10x a "W" would be different than using 10x a "I". But I think I will measure on my own if the text container will overlap (with a threshold) the outer element. And then block the input. Will see who that works :)

mightym avatar Apr 10 '25 08:04 mightym