Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove default padding from material ui List Item?

Tags:

material-ui

Material ui add default padding on List and ListItem how to remove it ? Any help or direction to resources would be appreciated.

like image 548
Panayiotis Georgiou Avatar asked Apr 23 '19 15:04

Panayiotis Georgiou


People also ask

What is material UI list?

Lists are a continuous group of text or images. They are composed of items containing primary and supplemental actions, which are represented by icons and text. Material UI for React has this component available for us, and it is very easy to integrate.


2 Answers

You can override the root class of the ListItem component and pass the padding you want.

const styles = theme => ({
  root: {
    width: "100%",
    maxWidth: 360,
    backgroundColor: theme.palette.background.paper
  },

  item: {
    padding: 0
  }
});

function SimpleList(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <List component="nav">
        <ListItem button classes={{ root: classes.item }}>
          <ListItemText primary="Item 01" />
        </ListItem>
        <ListItem button classes={{ root: classes.item }}>
          <ListItemText primary="Item 02" />
        </ListItem>
        <ListItem button classes={{ root: classes.item }}>
          <ListItemText primary="Item 03" />
        </ListItem>
      </List>
    </div>
  );
}

See working sample.

like image 172
Arnaud Christ Avatar answered Sep 17 '22 11:09

Arnaud Christ


If you're just using a ListItem component, you can use the disableGutters (Boolean) property to disable the left and right padding, as seen from the API documentation: https://material-ui.com/api/list-item/

<ListItem disableGutters={true} button={true} key='Home' component={Link} to={"/"} selected={'/' === pathname}>
   <ListItemIcon><Home /></ListItemIcon>
   <ListItemText primary='Home' />
</ListItem>
like image 37
Ian Smith Avatar answered Sep 17 '22 11:09

Ian Smith