Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong with lines calculation when page load and window resize #94

Open
chjiyun opened this issue Jul 26, 2018 · 6 comments
Open

wrong with lines calculation when page load and window resize #94

chjiyun opened this issue Jul 26, 2018 · 6 comments

Comments

@chjiyun
Copy link

chjiyun commented Jul 26, 2018

I set 'lines' to 3, but get 2 lines instead. Does this bug exist all the time?

<ReadMore
  lines={3}
  more="更多"
  less="收起"
>
  {text}
</ReadMore>

ReadMore is a Component package base on Truncate

@moubi
Copy link
Contributor

moubi commented Aug 10, 2018

@chjiyun can you provide more info for the case to test?
For example what props are passed to Truncate or at least what is the text you want to truncate.

@chjiyun
Copy link
Author

chjiyun commented Sep 6, 2018

@moubi emmm, For example, i set lines of attribute to 3 or 4, but only get 2 lines of text all the time, as if this property is invalid, can you solve it?

  static propTypes = {
    children: PropTypes.node.isRequired,
    more: PropTypes.string,
    less: PropTypes.string,
    text: PropTypes.node,
    lines: PropTypes.number,
  };
  
  static defaultProps = {
    lines: 3,
    more: '更多',
    less: '收起',
  };
  constructor(...args) {
    super(...args);

    this.state = {
      expanded: false,
      truncated: false,
    };

    this.handleTruncate = this.handleTruncate.bind(this);
    this.toggleLines = this.toggleLines.bind(this);
  }

  handleTruncate(truncated) {
    if (this.state.truncated !== truncated) {
      this.setState({
        truncated,
      });
    }
  }

  toggleLines(event) {
    event.preventDefault();

    this.setState({
      expanded: !this.state.expanded,
    });
  }
<Fragment>
   <Truncate
       lines={!expanded && lines}
       ellipsis={(
          <span>... <a href='#' onClick={this.toggleLines}>{more}</a></span>
       )}
       onTruncate={this.handleTruncate}
   >
       {children}
   </Truncate>
   {!truncated && expanded && (
      <span> <a href='#' onClick={this.toggleLines}>{less}</a></span>
   )}
</Fragment>

@pablosichert
Copy link
Owner

I have created a sandbox with your example (https://codesandbox.io/s/6yj42pmlww) but can't reproduce what you are describing.

Please clarify if I misunderstood your problem.

Could you edit the sandbox and send the link that exactly reproduces your bug?

@chjiyun
Copy link
Author

chjiyun commented Jan 4, 2019

@pablosichert i apply it in Row and Col (a percent Component) Component, text spreads in three columns, and my version of react-truncate is 2.3.0

@chjiyun
Copy link
Author

chjiyun commented Jan 4, 2019

@pablosichert i try to copy chinese text to your example on codesandbox, but i exactly get wrong result of lines, you can have a try.

@Ktchan825
Copy link

Ktchan825 commented Jul 11, 2019

@chjiyun From my experience, Chinese is not supported well. this library uses " " as separator and split the line which is fine for English but not working for Chinese or other languages that don't separator word by space.

#107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants