question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I change the default color for row hover?

See original GitHub issue

I’m trying to change the default color for the row hover event. As I see it, the default seems to be,

.MuiTableRow-root.MuiTableRow-hover:hover {
  background-color: 'rgba(0, 0, 0, 0.07)';
}

How do I change it from the React component?

Many thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:25 (5 by maintainers)

github_iconTop GitHub Comments

27reactions
GBincazcommented, Oct 28, 2019

If anyone read this, that’s how I did it :

       const tableTheme = createMuiTheme({
            overrides: {
                MuiTableRow: {
                    hover: {
                        "&:hover": {
                            backgroundColor: "rgba(33, 150, 243, 0.25) !important"
                        }
                    }
                }
            }
        });

        <ThemeProvider theme={tableTheme}>
             <MaterialTable 
                ... 
                onRowClick={(event, rowData) => {
                     console.log(rowData);
                }}
                ...
              />
         </ThemeProvider>

The onRowClick assignement enable hover in the grid, the theme override the style of the hover.

15reactions
OnkelTemcommented, Nov 11, 2019

I’m trying to change the default color for the row hover event. As I see it, the default seems to be,

.MuiTableRow-root.MuiTableRow-hover:hover {
  background-color: 'rgba(0, 0, 0, 0.07)';
}

How do I change it from the React component?

Many thanks!

I’m not quite sure why do all these people recommend patching the theme 😉

This is how I did it:

const useStyles = makeStyles(theme => ({
  table: {
    '& tbody>.MuiTableRow-root:hover': {
      background: 'red',
    }
  },
}));

function MyTable() {
  const classes = useStyles();
  return (
    <div className={classes.table}>
      <MaterialTable .../>
    </div>
  );
}

The thing is - passing className to the <MaterialTable> element wouldn’t help because it sort of screws up standard MaterialUI techniques a little.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change default hover color of TableRow MUI - Stack Overflow
I would like to change the default hover color of a MUI TableRow by adding styles to the TableRow. This question has been...
Read more >
How to change Background Color of Table Row upon hover?
To change background color of the table row when user hovers over the row using mouse pointer, set the CSS background-color property with...
Read more >
Disable hover color change / Retain table row color based on ...
Currently I am trying to keep the color retained in certain conditions, e.g. to show the row record as red when it is...
Read more >
Change row hover color RowBound Event AddClass Grid
I have a row bound event to change the background color of a row but I would also like to change the hover...
Read more >
Highlight Table Row on hover using CSS - Text Fixer
You can use CSS without any javascript to make the row of a table highlight on hover. All it requires is that the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found