react-truncate icon indicating copy to clipboard operation
react-truncate copied to clipboard

Wrong lines calculation when width specified and having responsive container

Open kis opened this issue 3 years ago • 3 comments

When container is responsive and it's size depends on window size and we specify truncate text with lines and width params we have wrong lines calculation (having more or less actual lines than we specified)

kis avatar Oct 01 '20 10:10 kis

I have also faced this problem for <Truncate /> text inside a responsive element (there should be 3 lines)

Screenshot 2020-10-01 at 14 05 43

lolochka avatar Oct 01 '20 11:10 lolochka

I have faced the same issue, does anybody know any solution or hack maybe?

arturTsal avatar Oct 01 '20 11:10 arturTsal

I'm having a similar problem. As far as I can tell it's due to the different fonts. In my case, I'm usingopen-sans. My guess:

  1. Initially the page is loading with some default font
  2. The component is rendered, so the width of the parent is calculated. For the calculation, the width kind of respects the font which is used.
  3. Fonts are loaded, the content's width is changing, but there's nobody to tell the component to re-render.
  4. I have an extra line of text, as @lolochka screenshot.

Check https://github.com/pablosichert/react-truncate/issues/16 and check @bjcancin solution. It seems to work, although there is an awful re-render.

pawelangelow avatar Oct 06 '20 15:10 pawelangelow