How to override MuiPaper-root style in material-table

Viewed 19012

I'm using the material-table (https://material-table.com/).

My issue is that I want to change the table border-radius and table shadow, apparently, this option does not exist using 'option feature'

But when I inspect the table I could modify radius and shadow as you can see below :

enter image description here

I'm wondering how to override these values from Reactjs :


const useStyles = makeStyles(theme => ({
  root: {
  }
}));


const MainTable = props => {
  const {className, params, ...rest} = props

(...)
  return (
    <MaterialTable
      className={classes.MuiPaperRounded}
      columns={[
        {title: 'Equipement', field: 'equipement'},
        {title: 'TAG', field: 'tag'},
        {title: 'Nombre de points de mesures', field: 'nombreDePointsDeMesures'},
        {title: 'Mesuré', field: 'mesure', type: 'boolean'}
      ]}
      data={rows}
      icons={(...)}
      options={{
        tableLayout: {backgroundColor: 'green'},
      }}
      title="Routine vibration"
    />
  );
};
2 Answers

If it's difficult to customize styles inside third party component,

Use nesting selector with className from outside would be fine.

For your example:

"& .MuiPaper-root"

Full code:

import React from "react";
import "./styles.css";
import { makeStyles } from "@material-ui/core";
import MaterialTable from "material-table";

const useStyles = makeStyles(theme => ({
  root: {
    "& .MuiPaper-root": {
      borderRadius: "100px",
      boxShadow: "10px 10px 5px 0px rgba(0,0,0,0.75);"
    }
  }
}));

export default function App() {
  const classes = useStyles();
  return (
    <div className={classes.root}>
      <MaterialTable />
    </div>
  );
}

Edit sleepy-thunder-s947k

enter image description here

root: {
        display: 'flex'
        "&.MuiPaper-root":{
            backgroundColor:"#fafafa" //as an Example
        }
  },

//that was working

Related