reactjs - Material-UI:长文本包裹在网格中
问题描述
在 Material-UI 的文档中,在Grid: white-space: nowrap;部分中 有一个包含在codesandbox中的文本示例。
在这个例子中,我用const message =""
一个没有空格的长文本替换:
const message ="AsuperLongTextWithNoSpaceItIsVeryAnnoyingIWantToWrapThisSentence"
结果:
如您所见,消息超出了网格。我希望消息换行。
我试着style={{'overflowWrap': 'break-word'}}
像这样添加:
<Paper className={classes.paper}>
<Grid container wrap="nowrap" spacing={2}>
<Grid item>
<Avatar>W</Avatar>
</Grid>
<Grid item xs>
<Typography style={{'overflowWrap': 'break-word'}}>{message}</Typography> {/* style added */}
</Grid>
</Grid>
</Paper>
结果:
如您所见,它更好,但文本也超出了网格。
如何在不超过网格的情况下正确执行此操作?
编辑 (1)
我在网格中有一个网格:
<Grid container spacing={2}>
<Grid item>
<Avatar>
<ImageIcon />
</Avatar>
</Grid>
<Grid item xs={12} sm container >
<Grid item xs container direction="column" spacing={2} wrap="nowrap">
<Grid item xs>
<Typography gutterBottom variant="subtitle1">
{`${props.comment.username}`}
</Typography>
</Grid>
<Grid item xs zeroMinWidth>
<Typography gutterBottom variant="subtitle1" style={{'overflowWrap': 'break-word'}}>
{props.comment.comment}
</Typography>
</Grid>
<Grid item container>
<Grid item>
<IconButton onClick={handleMenuClick}>
<ThumbUp />
</IconButton>
</Grid>
</Grid>
</Grid>
</Grid>
<Grid item>
<IconButton onClick={handleMenuClick}>
<MoreVertIcon />
</IconButton>
</Grid>
</Grid>
我的container
有wrap="nowrap"
,我的项目有zeroMinWidth
,但结果是:
而不是这个:
编辑 (2)
我找到了解决方案:
它必须zeroMinWidth
为每个写<Grid item>
!
解决方案
推荐阅读
- python - 使用 pip 的进度条
- laravel - laravel8 未定义变量:错误
- php - 在 WooCommerce 单品页面上仅显示“有货”相关产品
- python - Plotly Dash:无需回调即可访问 dcc.Store 组件
- java - 为什么会出现此崩溃且预期没有挂起的异常:java.lang.NoClassDefFoundError: androidx.core.view.ViewCompat$2
- javascript - react native:如何在进入内部页面时自动显示当前时间?
- java - 不带参数的 Setter Java OOP
- node.js - 从 React 应用程序编辑 JSON 文件 - 页面构建器概念
- android - 在android中启动时flutter release apk崩溃
- html - 如何在ckeditor 5中添加pop?