Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollable List Component from Material-UI in React

How to make the List component (see https://material-ui.com/components/lists/) fixed-size and scrollable? Every time I add a new ListItem the List expands, however I would like to be able to scroll through it if content gets bigger than the container.

like image 214
optional Avatar asked May 04 '17 17:05

optional


People also ask

How do I add a scrollbar in MUI?

const styles = (theme: Theme) => createStyles({ scrollBar: { '&::-webkit-scrollbar': { width: '0.4em' }, '&::-webkit-scrollbar-track': { '-webkit-box-shadow': 'inset 0 0 6px rgba(0,0,0,0.00)' }, '&::-webkit-scrollbar-thumb': { backgroundColor: 'rgba(0,0,0,. 1)', outline: '1px solid slategrey' } } });

How do I add a scrollbar to a list?

Drag the list object into the block. Select the block and in the properties pane, select "Size and Overflow". In the "Size and Overflow" window, set the desired dimensions of the block. Select the "Always use scrollbars" radio button.


2 Answers

I just found out that you can add properties. 'maxHeight' and 'overflow' are the ones I was needing to solve my problem. For example for a List in a Paper container:

<Paper style={{maxHeight: 200, overflow: 'auto'}}>   <List>    ...   </List> </Paper> 
like image 95
optional Avatar answered Sep 19 '22 12:09

optional


This works if you want the list to fill all height of the container:

<List style={{maxHeight: '100%', overflow: 'auto'}} /> 
like image 34
Onuray Sahin Avatar answered Sep 20 '22 12:09

Onuray Sahin