Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add padding-top in react-virtualized <List />

I have a <List /> component where I want to add an initial padding-top to the wrapper. Since all the elements are absolute positioned I found this solution but I wonder if it's right or is there another solution less expensive:

const rowRenderer = ({ index, key, style, isScrolling }) => {
// ...

return (
  <ul key={key}
    style={{
      ...style,
      top: style.top + 50,
    }}>
    { items.map(itemRenderer) }
  </ul>
)

}

The related part is the style prop.

like image 737
Lionel T Avatar asked May 19 '26 16:05

Lionel T


1 Answers

You can avoid the unnecessary object-creation and spread operation by moving the padding to the level of the List, eg:

<List
  {...props}
  style={{
    paddingTop: '50px',
    boxSizing: 'content-box',
  }}
  containerStyle={{
    position: 'relative',
    overflow: 'visible'
  }}
/>

See an example of this here: https://plnkr.co/edit/vNHDmpEY2bjQbCup4xsG?p=preview

like image 140
bvaughn Avatar answered May 22 '26 08:05

bvaughn



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!