reactjs - Material UI ListItemSecondaryAction 在 ListItem 中垂直对齐

标签 reactjs typescript material-ui

我在使用 Action 创建 ListIem 时遇到了@material-ui/core 问题。当 secondary 文本变长时,我想将 ListItemSecondaryAction 保持在顶部作为 ListItemAvatar,有什么办法可以克服它:

<ListItem alignItems="flex-start">
        <ListItemAvatar>
          <Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" />
        </ListItemAvatar>
        <ListItemText
          primary="Brunch this weekend?"
          secondary={
            <React.Fragment>
              <Typography
                component="span"
                variant="body2"
                className={classes.inline}
                color="textPrimary"
              >
                Ali Connors
              </Typography>
              {
                " — I'll be in your neighborhood doing errands this…I'll be in your neighborhood doing errands this…I'll be in your neighborhood doing errands this…"
              }
            </React.Fragment>
          }
        />
        <ListItemSecondaryAction>
          <IconButton edge="end" aria-label="delete">
            <DeleteIcon />
          </IconButton>
        </ListItemSecondaryAction>
      </ListItem>

enter image description here

正如您在此处看到的那样,当文本变长时,delete 图标会被破坏,因此我希望垂直对齐使其与 ListItemAvatar 保持一致。任何帮助将不胜感激,谢谢!

CodeSandBox to play around

最佳答案

添加此样式将解决您的问题:

    <ListItemSecondaryAction style={{top:"0%", marginTop:"35px"}}>

关于reactjs - Material UI ListItemSecondaryAction 在 ListItem 中垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63047608/

相关文章:

TypeScript:Promise.all 中的类型推断不正确

typescript - 在 TypeScript 中,如何定义返回 promise 的递归函数

reactjs - 如何将 Material UI 文本字段聚焦在按钮单击上?

android - Material Design 3 DialogFragment 的样式与使用 MaterialAlertDialogBu​​ilder 的对话框不同

javascript - SASS 中的动态类名

reactjs - 我想更改脉轮 ui 按钮的默认样式

typescript - 将数组值提取为 Typescript 类型

reactjs - 在用户单击提交按钮之前,如何在react-hook-form中触发yup验证?

javascript - 无法导航到 react-router-dom URL

reactjs - 使用 withRouter 的 React-Router + React Hooks