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

Show more/less text #115

Open
jeromecauchon opened this issue Apr 4, 2024 · 1 comment
Open

Show more/less text #115

jeromecauchon opened this issue Apr 4, 2024 · 1 comment

Comments

@jeromecauchon
Copy link

I found a way to show more text but i cannot figured out how to show less text. Once expanded, the textTruncateChild disappear.

const [expanded, setExpanded] = useState(false);
  return (
      <TextTruncate
          line={expanded ? 2000 : props.lines}
          element="span"
          truncateText="…"
          text={props.text}
          textTruncateChild={<a onClick={() => {setExpanded(!expanded)}}>{expanded?'less': 'more'}</a>}
      />
  );
@jeromecauchon
Copy link
Author

jeromecauchon commented Apr 4, 2024

This is how i make it work.

const [expanded, setExpanded] = useState(false);
return (
    {expanded ? (
      <Typography>
        {props.text}
        <a
          href='#'
          style={{ color: 'red' }}
          onClick={() => {
            setExpanded(!expanded);
          }}>
          {props.readLessText}
        </a>
      </Typography>
    ) : (
      <TextTruncate
        line={props.lines}
        truncateText='…'
        text={props.text}
        textTruncateChild={
          <a
            href='#'
            style={{ color: 'red' }}
            onClick={() => {
              setExpanded(!expanded);
            }}>
            {props.readMoreText}
          </a>
        }
      />
    )});

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

1 participant