React truncate text by line

16,233

Solution 1

You can install react-text-truncate and use below code to do it

<TextTruncate
  line={1}
  text="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
  }
/>

Or you can visit the demo page

Solution 2

I don't know if you want that issue to get resolved or asking for other options as well.

But I usually use react-lines-ellipsis for ellipsis. If you can go with other alternatives then you can check demo in other broswers as well.

Share:
16,233
Aleksey Makas
Author by

Aleksey Makas

Professional Summary Software developer with experience in web programming front-end application layers using JavaScript, TypeScript, has excellent knowledge HTML/CSS and experience in responsive web development, valid and tableless markup, cross-browser compatibility, ability to work with Adobe Photoshop and also familiar with back end development based on PHP/Java. Key Expertise Developed web-applications, web-components and plugins using JavaScript and TypeScript Experience with WebExtensions for external web-forms. Experience with Javascript Google Api / Yandex Api Experience with PHP framework – Yii, laravel Experience with CMS based on PHP – Bitrix, WP. Wrote components for Bitrix Convert psd to responsive HTML/CSS with css frameworks and without Education Belarusian State University Informatics and Electronics. Qualification - Engineer, economist programmer. Major - information technology in the economy. Belarusian State University Informatics and Electronics. Qualification - Postgraduate studies. Major - Psychology of work and ergonomics.

Updated on June 08, 2022

Comments

  • Aleksey Makas
    Aleksey Makas about 2 years

    I need to truncate card title (text) with react.

    enter image description here

    I try to use dotdotdot component https://www.npmjs.com/package/react-dotdotdot but it doesn't work with simple component.

    const content = ({title}) => <Dotdotdot clamp={2}><p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Est rem magni totam quos sapiente aliquid praesentium quae sint illo quas dicta cum illum dolorum quis eveniet, corrupti porro placeat, consequatur reprehenderit aliquam distinctio voluptates voluptate, temporibus omnis. Cum quis tenetur laborum minus accusantium provident eveniet, corrupti, reiciendis aliquam suscipit hic?</p></Dotdotdot>
    

    It doesn't work in ie11 and mozilla. In -web-kit i have -webkit-line-clamp but in mozilla and ie it doesn't work.

    Do anybody know decision for this task?

  • user988544
    user988544 over 6 years
    Hey does this library also support a 'collapse' functionality? What If I want user to be able to collpase content back?
  • achyut pokhrel
    achyut pokhrel over 6 years
    I don't think it has
  • Aleksey Makas
    Aleksey Makas almost 6 years
    There is a problem with ie11. It doesn't work in ie11
  • Jim Edelstein
    Jim Edelstein about 4 years
    Shiny the demo link doesn't work and the demo linked from github is broken.
  • Anna Ira Hurnaus
    Anna Ira Hurnaus about 4 years
    This is the correct link to the dema page: shinychang.github.io/React-Text-Truncate