Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

css - How to line-break or line-clamp a particular menu item in React Menu Item (Web App)?

I am using React Material UI in my web app and I’ve created a notification dropdown using "Menu" & "Menu Item". When I display the notification message in Menu Item, the content goes under the div and doesn’t break into other line. I've applied "Line Clamp" attribute but the content still doesn't break and goes under the div. Screen shots attached below:

Screenshot for the problem that I'm facing

<div className="MessagesDiv">
    <IconButton
      aria-controls="customized-menu"
      aria-haspopup="true"
      variant="contained"
      color="black"
      onClick={handleClick}
      style={{
        padding: '0',
      }}>
      <NotificationsNoneIcon />
    </IconButton>
    <StyledMenu
      id="customized-dropdown-msgs"
      anchorEl={anchorEl}
      keepMounted
      open={Boolean(anchorEl)}
      onClose={handleClose}
      style={{
        width: '360px',
        boxShadow: 'rgba(119, 119, 119, 0.1) 0.5px 3px 10px',
      }}>
      {notifications.map((item) =>
        <StyledMenuItem key={item.id} onClick={(event) => openNotification(event, item)} className='StyleMenuItem'>
          <ListItemText className="truncate" primary={item.message} />
        </StyledMenuItem>
      )}
    </StyledMenu>
  </div >

and I applied current attributes in css:

'.StyleMenuItem': {
  borderBottom: '1px solid rgb(224, 224, 224)',
  padding: '10px 15px',
},
'.truncate span': {
  display: 'block',
  overflow: 'hidden',
  textOverflow: 'ellipsis',
  display: '-webkit-box',
  lineClamp: '2 !important',
  boxOrient: 'vertical',
  width: '90%',
}
question from:https://stackoverflow.com/questions/65916751/how-to-line-break-or-line-clamp-a-particular-menu-item-in-react-menu-item-web-a

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...