Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put text inside ListItem on the right side?

I have these now, and the "YoYo" text are aligned to the left (as default). And I'd like to control the "YoYo" texts' positions so some of them could appear on the right.

I tried to supply a style object with justifyContent:'flex-end' or alignSelf:'flex-end' but none of them is working.

  <List>
    <ListItem containerElement={<ChatObject id='1' value="YoYo" style={{alignSelf:'flex-end'}} />} />
    <ListItem containerElement={<ChatObject id='1' value="YoYo" />} />
    <ListItem containerElement={<ChatObject id='1' value="YoYo" />} />
    <ListItem containerElement={<ChatObject id='1' value="YoYo" />} />
    <ListItem containerElement={<ChatObject id='1' value="YoYo" />} />
  </List>

The ChatObject is defined as:

render() {
    return (
      <TextField
        id={this.props.id}
        value={this.props.value}
        underlineShow={false}
      />
    );
  }
like image 364
Marson Mao Avatar asked Jan 21 '26 11:01

Marson Mao


1 Answers

I successfully did it with this:

<ListItem style={{display:'flex', justifyContent:'flex-end'}} >
  <ChatObject id={item.id} value={item.value} />
</ListItem>

The key here is to add display:'flex'.

like image 72
Marson Mao Avatar answered Jan 25 '26 11:01

Marson Mao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!