Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the hover color of Material-UI table?

I am using React and Material UI for my web application. I want to change the hover color of table row but cannot do that.

Sample code:

x={
  hover:{
    color:'green'
  }
}

<TableRow
  hover
  key={lead.id} className={classes.row}
  classes={{
    hover:x.hover
  }}
  onClick={() => {}}
>
like image 227
Nayan Srivastava Avatar asked Sep 01 '18 16:09

Nayan Srivastava


People also ask

How do you style hover in MUI?

MUI Styled Components Code Here's a simple styled button: const StyledButton = styled(Button)` background-color: grey; color: #fff; padding: 6px 12px; &:hover { background-color: #a9a9a9; } &:focus { background-color: green; } `; The hover selector is simple to add.

How do I change the row height in a material-UI table?

Set Material-UI Table Row Height with Class Override. I will override the TableRow in the TableHead using class based overrides. There are two steps to this for the Table component: set a height in the TableRow, and remove the vertical padding in the TableCell.


2 Answers

I've got this solution so far. Maybe there are other approaches to override css of tableRow but this one works like a charm:

const styles = theme => ({
tableRow: {
    "&:hover": {
      backgroundColor: "blue !important"
    }
  }
});


<TableRow hover
      key={lead.id} className={classes.tableRow}

      onClick={() => {}}>

Feel free to ask any question.

like image 117
Sakhi Mansoor Avatar answered Sep 19 '22 18:09

Sakhi Mansoor


tableRow: {
    hover: {
        "&$hover:hover": {
            backgroundColor: '#49bb7b',
        },
    },
}

<TableRow className={classes.tableRow} key={n.id} hover onClick={event => this.handleClick(event)}>Text</TableRow>
like image 30
Ulthane Avatar answered Sep 20 '22 18:09

Ulthane