Git Product home page Git Product logo

react-lines-ellipsis's People

Contributors

danicase avatar dependabot[bot] avatar jm5967a avatar vikas-parashar avatar vuryss avatar xiaody avatar zigcccc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-lines-ellipsis's Issues

Can we use Span instead of div in html.js

Hi, i get this error when i use the htmlellipsis component.. As i understand its because of the usage of

in the html.js component... can we change it to instead to avoid these errors?

Warning: validateDOMNesting(...):

cannot appear as a descendant of

.
in div (created by HTMLEllipsis)
in span (created by HTMLEllipsis)

HTML Experimental support

i'm using your package in production and wanted to know why the inner HTML support is Experimental ?

are there any known issues ?
is there a plan to support it non-experimentally ?

thanks.

Doesn't work with even line number

Hello,

I've come across an interesting bug using this library.

Steps 1 : Add this code
<HTMLEllipsis unsafeHTML='simple html content' maxLine="2" ellipsis="..." basedOn="letters" />

Step 2: Check in a web browser.

Chrome behavior :
For the first time, It trims perfectly and display ... at line number 2. But When you reload the page It shows ... at line number 3.

Firefox and Safari behavior:
It trims at line number 3 instead of line number 2.

Seems like, maxLine attribute doesn't work with even line number value(Ex: 2, 4, 6, 8 so on).

My browser details -

  1. Chrome : Version 94.0.4606.61 (Official Build) (x86_64)
  2. Safari : Version 14.0.3 (16610.4.3.1.4)
  3. Firefox : 92.0.1 (64-bit)

Please have a look into it .

Thank you!

there is a space between the ellipsis and the string

im using HTMLEllipsis module from the library since i want to trim an html element, but afer the trim happens there is a white space between the ellipsis and word, im sorry if im doing something wrong here, screenshot is attached for reference

image

this is the span that causing the extra space between

<span class="LinesEllipsis-unit"> </span>

more/less btn

hi, I want to know how to control more/less button? thank you very much!

你好,请问「查看更多」/「收起」按钮如何设置? 非常感谢!

`winWidth` prop on a DOM element

"react": "^16.4.0",

Warning: React does not recognize the winWidth prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase winwidth instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Trim Punctuation

Setting the LineEllipses to use basedOn: 'words' has this weird issue of include punctuation ([',', '.']) when it trims.

So when the trim happens, we can have ,... or .... which looks a bit weird.
Is there a way to include a hook when we want certain chars trimmed off as well?

A way to exclude an element from being trimmed.

I am using a component that doesn't allow to choose whether to apply this plugin on an element or not.
I wanted to disable this this component for my HTML element. Is there any HTML class that I can use so react-lines-ellipsis would skip this element?

[enhancement] Ability to expand

Hi! First of all, great library!

I think a pretty common use case for this library is showing a brief preview of the text and let the user expand the preview to see the full text. In my case, I'm handling the expanded state on my component and either rendering the text itself of the one wrapper by the library, but it would be cool if the library supported this.

For this, I can think of two approaches:

  • Adding a maxLines value on the onReflow function, so we can dynamically change between a small number and that one.
  • Add a new prop to support this

What do you think? Thanks!

window.getComputedStyle(this.target) wouldn't get correct width in iOS Safari sometimes

OS: iOS 12.3.1
Broswer: Safari
Library: "preact": "8.2.9", "react-lines-ellipsis": "0.14.1"
Code snippet:

componentDidMount() {
    window.setTimeout(() => {
      this.setState({ isMounted: true });
    }, 0)
}

...

render() {
    return (
      ...
      {isMounted && <LinesEllipsis {...props} />}
      ...
    );
}

The component wouldn't initialize properly sometimes.
In Android and PC broswer it works well.

Generally, window.getComputedStyle(this.target)would get an Object with property width width a certain value like 100px. But sometimes Safari would get a auto value of width in getComputedStyle(this.target), that led to no wrap in canvas and calcIndexes() got the wrong result of [0]. Not always, there's a chance that that would happen.

Could I get react-lines-ellipsis via cdn? I would provide a demo.

Accept `children` prop instead of/besides the `text` prop

I think this would be neater to write:

<LinesEllipsis>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tempus dolor at felis varius euismod. Nulla non augue at est consequat fermentum. Integer id scelerisque ipsum. Vestibulum vitae dui augue. Vivamus diam nulla, ultricies quis lacus in, pretium interdum quam. Donec non commodo orci. Nulla imperdiet scelerisque faucibus. Quisque eget metus at arcu dapibus faucibus nec eget est. Curabitur consectetur posuere ante nec mattis. Cras non posuere orci. Maecenas pellentesque massa efficitur egestas posuere. Proin efficitur urna sed turpis tincidunt, a elementum dui semper. Morbi ultricies dignissim scelerisque. Integer dignissim mauris nec arcu vestibulum, nec rhoncus nisi suscipit. Quisque tincidunt scelerisque metus, in sollicitudin metus malesuada tempor.

  In nec lectus iaculis, tristique felis at, faucibus arcu. Aliquam et euismod arcu, non semper sapien. Maecenas lobortis, mi eget hendrerit ullamcorper, lorem purus fermentum orci, non rhoncus risus mauris in odio. Aenean ut nisl purus. Fusce quis ultricies diam, at ullamcorper libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam eget nibh eros. Aliquam semper porta massa.
</LinesEllipsis> 

than this:

<LinesEllipsis text={`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tempus dolor at felis varius euismod. Nulla non augue at est consequat fermentum. Integer id scelerisque ipsum. Vestibulum vitae dui augue. Vivamus diam nulla, ultricies quis lacus in, pretium interdum quam. Donec non commodo orci. Nulla imperdiet scelerisque faucibus. Quisque eget metus at arcu dapibus faucibus nec eget est. Curabitur consectetur posuere ante nec mattis. Cras non posuere orci. Maecenas pellentesque massa efficitur egestas posuere. Proin efficitur urna sed turpis tincidunt, a elementum dui semper. Morbi ultricies dignissim scelerisque. Integer dignissim mauris nec arcu vestibulum, nec rhoncus nisi suscipit. Quisque tincidunt scelerisque metus, in sollicitudin metus malesuada tempor.

In nec lectus iaculis, tristique felis at, faucibus arcu. Aliquam et euismod arcu, non semper sapien. Maecenas lobortis, mi eget hendrerit ullamcorper, lorem purus fermentum orci, non rhoncus risus mauris in odio. Aenean ut nisl purus. Fusce quis ultricies diam, at ullamcorper libero. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Etiam eget nibh eros. Aliquam semper porta massa.`} />

Issue using ellipsis on one max line

I'm not quite sure if this is an issue:
https://codesandbox.io/s/826jq3n4w9

Problem is, I can't really make react-lines-ellipsis to work on one line texts to make it stay between the wrapper divs without overflowing. Even if I set the maxLine to 1. If this isn't an issue, please have a look and help me find what I'm missing in my implementation.

Thank you!

Add window resize event listener to the component

Feature request

Hi, I've found that in your example app you attached a window resize event listener оn App component

class App extends Component {
  constructor (props) {
    super(props)
    this.state = {
      text: defaultText,
      maxLine: 3,
      useEllipsis: true,
      renderId: 1
    }
    this.onTextClick = this.onTextClick.bind(this)
    this.onTextKey = this.onTextKey.bind(this)
    this.onTextEdit = debounce(this.onTextEdit.bind(this), 100)
    this.onChangeLines = debounce(this.onChangeLines.bind(this))
    this.onResize = debounce(this.onResize.bind(this), 150)
  }

  componentDidMount () {
    window.addEventListener('resize', this.onResize)
  }

  componentWillUnmount () {
    window.removeEventListener('resize', this.onResize)
  }

But it's not very convenient way when writing an app.
Could you attach listeners to LinesEllipsis and HTMLEllipsis components itself, so one can use this functionality just out of the box?

Packages like react-text-truncate, shiitake, react-truncate, react-dotdotdot use such an approach and it's very convinient (but unfortunately non of the above can handle HTML 😉).

Thanks in advance.

warning.js:33 Warning: React does not recognize the `winWidth` prop on a DOM element.

I have used react-lines-ellipsis in my project its working fine but its showing following warning in console. Because of its added winWidth property to dom element at run time . Please let me know how to over come on this
Warning: React does not recognize the winWidth prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase winwidth instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Determine if text was truncated or not?

This would be a feature request, a property that would return a boolean value on whether or not the text was truncated or not, which would aid in adding a "More/Less" button/link based on if it's needed.

Crash when double-clicking on Chrome 76+

Hello !
I've come across an interesting bug using this library: when double-clicking outside of text on the last line, apparently Chrome simply crashes (the current tab).

That's happening on Chrome 76 and 77, I tried on Windows & Mac. I couldn't reproduce this on Firefox, Edge, Safari or Chrome 75 🤔.

You can try it there:
https://codesandbox.io/s/quirky-river-86m1v (try double-clicking on the "blank" near "multine text")

Export ResponsiveEllipsis component

The documentation describes how to create a responsive ellipsis component, but it would be useful to instead export that component so that it doesn't need to be re-defined everywhere it is used.

Is it possible to add title property when text is clamped

My workaround was to wrap is with a div with title, but it would be great to have an option to this.

import LinesEllipsis from 'react-lines-ellipsis'

<div title="long long text">
  <LinesEllipsis
    text='long long text'
    maxLine='3'
    ellipsis='...'
    trimRight
    basedOn='letters'
  />
</div>

Like this:

import LinesEllipsis from 'react-lines-ellipsis'

<LinesEllipsis
  text='long long text'
  maxLine='3'
  ellipsis='...'
  trimRight
  basedOn='letters'
  insertTitle
/>

I must be doing something wrong? Puts component at body level?

I'm using a pretty simple version inside a Card component. The card is rendered for however many are in the array. for example 10.

<div className={'Cards-cardText'}>
   <LinesEllipsis
       text='hello'
       maxLine={3}
       basedOn='letters'
   />
</div

And at the body, level, I'm getting 10 of these.

<div class="LinesEllipsis-canvas " aria-hidden="true" style="box-sizing: content-box; width: 615px; font-size: 12px; font-weight: 400; font-family: &quot;Helvetica Neue&quot;, Arial, Helvetica, Verdana, sans-serif; font-style: normal; letter-spacing: normal; text-indent: 0px; white-space: normal; word-break: normal; overflow-wrap: normal; padding: 0px; position: absolute; bottom: 0px; left: 0px; height: 0px; overflow: hidden; border: none;">
    <span class="LinesEllipsis-unit">h</span>
    <span class="LinesEllipsis-unit">e</span>
    <span class="LinesEllipsis-unit">l</span>
    <span class="LinesEllipsis-unit">l</span>
    <span class="LinesEllipsis-unit">o</span>
</div>

What the heck am I doing wrong?

Single-line single word not clamping and overflowing it's container.

with reference to #45 i think width clamping would be useful at least as a property that can be passed to the component. I understand if that wasn't the original usecase for the component, but multiple people have asked for it and it would be nice to not have to use a different package because of this one usecase

i have tried using the 'word-break': 'break-all' approach outlined in in the above link, which just causes the entire line to clamp and show the ellipsis, which is also not ideal. You have solved a difficult problem here by having an easy to integrate with react-component package that solves the multi-line ellipsis text problem well, except for this one case.

BasedOn prop is ignored

BasedOn option is ignored. When I set basedOn to 'letters' it doesn't work. Ir still selects a 'words'.
Here is snipped from code.

 key: 'reflow',
    value: function reflow(props) {
      /* eslint-disable no-control-regex */
      var basedOn = props.basedOn || /^[\x00-\x7F]+$/.test(props.text) ? 'words' : 'letters';
      switch (basedOn) {
        case 'words':
          this.units = props.text.split(/\b|(?=\W)/);
          break;
        case 'letters':
          this.units = Array.from(props.text);
          break;
        default:
          throw new Error('Unsupported options basedOn: ' + basedOn);
      }

If prop basedOn exists then 'words' will be selected. And it doesn't metter what value basedOn will have.
Could you please fix this issue.

Remove browserify references from package.json

Wondering, why are these lines needed? I'm getting this error in my env:

Error: Cannot find module 'aliasify' from '/Users/damassi/Sites/artsy/reaction  /node_modules/react-lines-ellipsis'

Error: Cannot find module 'babelify' from '/Users/damassi/Sites/artsy/reaction  /node_modules/react-lines-ellipsis'

As background, I'm using this lib in another lib which is then imported by a third app. The third app, when executing the code, runs into issues with Browserify. Since the package is compiled by babel, why force these additional steps on the consumer?

[Proposal] Limitations update

not clamps text on the server side or with JavaScript disabled

I would recommend highlighting this point and move to the top. I develop the project using Next.js and it was so confusing why the trimming works incorrectly... I even removed the package and then installed it again, reviewed all props few times before I found that this component should be rendered on the client-side only

I really think it might save time for many developers :)

Make text/HTML to accept children instead

It would be a lot better if this component could accept children instead of having 2 versions, one for text and another for HTML (with unsafe stuff).

This should be possible:

<Ellipsis
  maxLine='3'
  ellipsis='...'
  trimRight
  basedOn='letters'
>
  <span>Foo</span> bar!
</Ellipsis>

Letter spacing

Looks like after you add more than .5px of letter spacing that it breaks the ... to a new line. Does the code handle scenarios like this?

Weird behaviour without width set - no text, ellipsis only

I've found that without parent width set explicitly component shows quite strange behaviour:
once text has second word (after first space) it desappears completely and is being replaced by ellipsis only.

Code is simple, nothing special:

<div style={{display: flex, fontSize: '0.7em', fontWeight: 'bold', textAlign: 'left'}}>
              <LinesEllipsis
                text={adv.title}
                maxLine='1'
                trimRight
                ellipsis='...'
                basedOn='letters'
                style={{fontSize: '0.8em', fontWeight: 'bold', textAlign: 'left'}}
              />
            </div>

Adding width to parent div resolves issue.

My environment:
"react": "16.4.0",
"react-lines-ellipsis": "0.13.2",

Probably this should be documented in readme somehow - I spent half a day trying to make it work under react-native-web first, then under pure react - behaviour is totally same.

Support a width prop

Hello,
I wish to support a width prop, when a text is shorter than width, it just show like text, and when text is longer than width, the text should be cut down and show with an ellipsis. Now i set the style={{width: xxx}} to the component, when text is shorter than width, the component width is not fit-content, it is longer than text's width. Like this:
image

一个页面组件使用过多的问题

一个页面使用很多组件会导致创建了很多div,感觉有点耗费内存。本身多行判断是个同步过程,公用一个div就可以实现。判断完了感觉也可以this.canvas.innerHTML = ''处理下

HTML Ellipsis

We are trying to try out your new HTML Ellipsis and we are not seeing it work. We tried your example as well but no luck. Do you have a working example we can see in Codepen ?

Module is not supporting style animation.

I had tried to apply style animation with react-line-ellipsis module but can't get any working solution. Transition element is not supporting with this module, Please let me know anyone who faced this issue and resolved.

Here is my code:

**index.tsx**
<div>
  <h6>{title}</h6>
  <LinesEllipsis
    text={description}
    maxLine={this.state.maxLine}
    ellipsis='...'
    basedOn='letters'
    />  
  <a onClick={this.handleClick}>{this.state.toggle ? "less" : "more" }</a>
</div>


**styles.css**

.LinesEllipsis--clamped {
    transition: all ease-out .2s;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.