javascript - Unable to align ListItem text - Stack Overflow

I have this material-ui list:<List dense>{this.state.issues.map((item, i) => {return <Link

I have this material-ui list:

<List dense>
  {this.state.issues.map((item, i) => {
    return <Link target="_blank" to={item.issue_url} key={i}>
      <ListItem button>
        <ListItemText primary={item.issue_state}/>
        <ListItemSecondaryAction>
          <IconButton>
            <ArrowForward/>
          </IconButton>
        </ListItemSecondaryAction>
      </ListItem>
    </Link>
  })
  }
</List>

issue_state is obtained from MongoDB. Can I add another column to my list showing another field from the database? I tried:

<ListItemText primary={item.issue_state}/>
<ListItemText primary={item.issue_title}/>

This displays what I want but the issue_title test is centered. I'd like it left aligned. Can this be done?

I have this material-ui list:

<List dense>
  {this.state.issues.map((item, i) => {
    return <Link target="_blank" to={item.issue_url} key={i}>
      <ListItem button>
        <ListItemText primary={item.issue_state}/>
        <ListItemSecondaryAction>
          <IconButton>
            <ArrowForward/>
          </IconButton>
        </ListItemSecondaryAction>
      </ListItem>
    </Link>
  })
  }
</List>

issue_state is obtained from MongoDB. Can I add another column to my list showing another field from the database? I tried:

<ListItemText primary={item.issue_state}/>
<ListItemText primary={item.issue_title}/>

This displays what I want but the issue_title test is centered. I'd like it left aligned. Can this be done?

Share Improve this question asked Dec 2, 2018 at 19:15 runnerpaulrunnerpaul 7,32410 gold badges70 silver badges161 bronze badges 2
  • Have you tried alignItems property ? – Code Maniac Commented Dec 2, 2018 at 19:18
  • Yes. I tried alignItems='flex-start but no luck. – runnerpaul Commented Dec 2, 2018 at 19:24
Add a ment  | 

1 Answer 1

Reset to default 4

ListItemText ponent renders with the following CSS style that allows it to be flexible to grow and shrink according as the width and height of its content.

flex: 1 1 auto;

Its ancestor ListItem ponent renders as an inline-flex. AFAICT, the results you're looking to achieve can't be done without overriding these styles. Not to worry, there are other ways to go that uses available APIs exposed in the ponent.

Never mind that the name for the ponent seems to be misleading that its usage is specific for rendering text in the list item. A closer look in the ListItemText ponent API documentation shows that the primary property is of the node type.

That implies that the ListItemText can be used to render string, function, and React.Element in a manner similar to the snippet below.

<ListItemText primary={<div>Foo<br/>Bar<br/>Baz</div>} />

There is also the secondary property that renders the elements with textual emphasis.

<ListItemText primary="Foo" secondary={<div>Bar<br/>Baz</div>} />

If you need more control over the children of the ListItemText, the API allows for the flexibility to write it this way

      <ListItemText>
        <Typography variant="subheading">Foo</Typography>
        <Typography variant="body1" color="textSecondary">Bar</Typography>
        <Typography variant="body1" color="textSecondary">Baz</Typography>
      </ListItemText>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745159392a4614318.html

相关推荐

  • javascript - Unable to align ListItem text - Stack Overflow

    I have this material-ui list:<List dense>{this.state.issues.map((item, i) => {return <Link

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信