5

How can I ellipsis a text after two line in material ui?

Here https://material-ui.com/system/display/#text-overflow show for single line

WebMaster
  • 2,218
  • 2
  • 13
  • 48

2 Answers2

12

You could use makeStyles function to create a multiLineEllipsis style.

import { makeStyles } from "@material-ui/core/styles";

const LINES_TO_SHOW = 2;

// src: https://stackoverflow.com/a/13924997/8062659
const useStyles = makeStyles({
  multiLineEllipsis: {
    overflow: "hidden",
    textOverflow: "ellipsis",
    display: "-webkit-box",
    "-webkit-line-clamp": LINES_TO_SHOW,
    "-webkit-box-orient": "vertical"
  }
});

Then you use this style just like as below

function App() {
  const classes = useStyles();

  return (
    <Typography className={classes.multiLineEllipsis}>
      Very long text here.
    </Typography>
  );
}

Edit practical-microservice-0mexz

bertdida
  • 4,125
  • 2
  • 14
  • 22
7

Update using sx:

<Typography
   sx={{
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      display: '-webkit-box',
      WebkitLineClamp: '2',
      WebkitBoxOrient: 'vertical',
   }}
>
</Typography>
samchuang
  • 331
  • 3
  • 10
David
  • 91
  • 1
  • 4
  • 1
    Worked for me! Although IntelliSense was not showing '-webkit-box' as a possible value for display... – slax57 Mar 25 '22 at 14:24