Reputation: 75
Using Material UI DataGrid, the default font in table is too small to see text.
My code is literally a copy/paste of their demo on the page:
https://material-ui.com/components/data-grid/
My fonts are very small in the table. Rest of page not using Material UI (menu etc.) are fine. In Firefox dev tools Inspector I see
Inherited from div:
.MuiDataGrid-root { font-size: 0.875rem; }
Changing that in the browser tool to something like 10px, or disabling it completely, confirms thats the value needing change. It's being automatically added at end (inline) when compiled so it overwrites my previous style. The silly thing is, I can't find where this is being added.
I've looked at several sites using this same table as examples and none have this issue. Can someone enlighten me where to look, how to fix the table having incorrect default font size?
I have these relevant bits:
package.json:
"@material-ui/core": "^4.11.0",
"@material-ui/data-grid": "^4.0.0-alpha.6",
"fontsource-roboto": "^3.0.3",
Index.html
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
Abbreviated .jsx code:
import React from 'react';
import { DataGrid } from '@material-ui/data-grid';
const DemoTableMui = () => {
...
const columns = [{ field: 'id', headerName: 'ID', width: 70 } ]
const rows = [{ id: 1, lastName: 'Smith', firstName: 'Jon', age: 35 } ]
return (
<div style={{ height: 600, width: '100%' }}>
<DataGrid rows={rows} columns={columns} pageSize={5} checkboxSelection />
</div>
);
};
export default DemoTableMui
Since the dev tool indicated it is inherited from div I did stuff like:
return (
<div style={{ height: 600, width: '100%', fontSize:25 }}>
...
But nothing had effect. I'm sure the div it is referring to is buried down in the <DataGrid/>
component...
Upvotes: 7
Views: 20660
Reputation: 2553
import { MuiThemeProvider } from "@material-ui/core/styles";
...
import { createTheme } from '@material-ui/core';
export const muiTheme = createTheme({
typography: {
fontFamily: 'Poppins Regular',
},
});
...
<MuiThemeProvider theme={muiTheme}>...</MuiThemeProvider>
Upvotes: -1
Reputation: 1037
So the best way to use material-UI
IMO is to customize the theme at the root level, and then all of the components should inherit the styling in a uniform kind of way. This is what my App.tsx looks like
import {
createMuiTheme,
MuiThemeProvider
} from "@material-ui/core/styles";
const theme = createMuiTheme({
palette: {
type: 'dark'
},
typography: {
fontSize: 12
},
// overrides: {
// MuiTypography: {
// colorInherit:{
// color: "#fff"
// }
// }
});
function App() {
return (
<MuiThemeProvider theme={theme}>
<LeadPage/>
</MuiThemeProvider>
);
}
export default App;
Setting the typography will trickle down to the class .MuiDataGrid-root
.
I left the palette up there which changes the font color of the grid, and the commented out code is a an example of overriding the class at the theme level, in case you need to tweak that grid further. My example would be if you saw .MuiTypography-colorInherit
in the debugger.
Upvotes: 2
Reputation: 3040
Based on OP feedback, putting an answer here.
Isolating the CSS problem.
Alternatively (based on the OP update in the comments)
Upvotes: 3