Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJs: Material-UI table - changing padding

For this fullstack app I moved into the original devs seem to have implemented some component to create the tables for the app's webpage

Problem is the padding on all the cells is quite large. Opening the rendered page in chrome and using chrome developer tools I can see

.MuiTableCell-sizeSmall{
    padding: 6px 24px 6px 16px;
}

It seems like MuiTableCell isn't directly implemented in the code (hence I'll only see it in the rendered DOM and not in the code) . Seems like it mostly implements material-ui and material-table.

I have a little front end experience but I'm not familiar with what to do next to modify the padding.

Specifically, from playing around with the chrome developer tools, I want to set the right padding (set at 24px) down to 0px so that the rendered DOM uses this

.MuiTableCell-sizeSmall{
    padding: 6px 0px 6px 16px;
}

Any advice?

Some imports from @Material-UI i think might be relevant are: ToolBar, Appbar, FormControl, InputField, TextField, ViewColumn, and TablePagination

And imported from material-table are' MaterialTable, and MTableToolbar

In intellij I did a blind search and found that the SizeSmall property seems to come from TableCell (part of material-ui)

like image 756
CaptainObv Avatar asked Jul 20 '26 11:07

CaptainObv


1 Answers

That CSS is the work of small value for size prop.

One of the ways to override it is to use makeStyles and override .MuiTableCell-sizeSmall

import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles({
  customTable: {
    "& .MuiTableCell-sizeSmall": {
      padding: "6px 0px 6px 16px" // <-- arbitrary value
    }
  },
});

function YourComponent() {
  const classes = useStyles();

  return (
    ...
      <Table classes={{root: classes.customTable}} size="small">
        ...
like image 90
95faf8e76605e973 Avatar answered Jul 22 '26 23:07

95faf8e76605e973



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!