1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MaterialUIでTableRowの背景色よりTableCellの背景色が優先されてしまうためTableRowのhover設定が機能しない問題

Posted at

はじめに

MaterialUIのv4を使っています。
TableRowのhover設定をオンにした場合でも、TableCellの背景色が優先されてしまうため、hoverしても背景色が変わりません。
これを解決しました。

コード

sample.tsx
const useStyles = makeStyles({
  tableRow: {
    '&.MuiTableRow-hover': {
      '&:hover': {
        '& > .MuiTableCell-root': {
          backgroundColor: 'blue'
        }
      }
    }
  },
  tableCell: {
    backgroundColor: 'red'
  }
});

export const Table: React.FC<Props> = () => {
  const classes = useStyles();

  return (
    <Table>
      <TableHead>
        <TableRow>
          <HeaderCell/>
        </TableRow>
      </TableHead>
      <TableBody>
        {rowData.map((row, index) => (
          <TableRow hover key={index} className={classes.tableRow}>
            <TableCell className={classes.tableCell}/>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  );
};
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?