Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover effect on IconButton in Material-UI

IconButton Hover

This is an iconButton from Material-UI that I am using. As you can see there is a slight grey border around the icon when you hover on it. What is the property to disable this? I have not found it in Material-UI docs, and I need to get rid of this grey hover feature.

Code:

<IconButton>
    <BackButton />
</IconButton>
like image 200
Roman S Avatar asked Jun 22 '18 17:06

Roman S


4 Answers

(Alternative Way)

You can also override the IconButton style via MuiThemeProvider:

import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';

const theme = createMuiTheme({
  overrides: {
    MuiIconButton: {
      root: {
        '&:hover': {
          backgroundColor: "$labelcolor"
        }
      }
    }
  }
})

And Wrap your component that you want to edit with this code:

<MuiThemeProvider theme={theme}>

// Your Component here

</MuiThemeProvider>
like image 70
Konstantinos Kalaras Lafkiotis Avatar answered Nov 10 '22 13:11

Konstantinos Kalaras Lafkiotis


There is no property to disable it. You'll just have to override the CSS:

<IconButton className={"MyCustomButton"}>
    <BackButton />
</IconButton>

With a css rule like:

.MyCustomButton:hover {
  background-color: inherit !important;
}
like image 7
Kevin Raoofi Avatar answered Nov 10 '22 13:11

Kevin Raoofi


It is possible to use makeStyles(styles) hook logic to change default material-ui IconButton CSS Pseudo-classes e.g. :hover style

code example:

import { makeStyles } from "@material-ui/core/styles";
import { IconButton } from "@material-ui/core";
import ArrowBackIcon from "@material-ui/icons/ArrowBack";

const useStyles = makeStyles((theme) => ({
  myClassName: {
    backgroundColor: "#EFD26E",
    position: "relative",
    "&:hover": {
      backgroundColor: "green"
    }
  }
}));

export default function App() {
  const classes = useStyles();

  return (
    <div className="App">
      <IconButton color="inherit" className={classes.myClassName}>
        <ArrowBackIcon />
      </IconButton>
    </div>
  );
}

screens:

  • bg color
  • bg color on hover
like image 1
A1I Avatar answered Nov 10 '22 11:11

A1I


<IconButton sx={{ "&:hover": { color: "green" } }}>
    <BackButton />
</IconButton>
like image 1
alberto gutierrez Avatar answered Nov 10 '22 11:11

alberto gutierrez