Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the hover effect of material-ui button inside of a styled component

I added the css hover property to disable the button's hover effect, but it seems not work for my case, how should I fix this?

import Button from 'material-ui/Button'
import styled from 'styled-components'

const StyledButton = styled(Button)`
  &:hover {
    background: none;
  }
`
export const SubmitButton = ({ onClick }) => {
  return (
    <StyledButton
      variant="raised"
      onClick={onClick}>
      login
    </StyledButton>
  )
}
like image 965
ccd Avatar asked May 10 '18 02:05

ccd


People also ask

How can remove hover property in button material UI?

sx={{ "&:hover": { backgroundColor: "transparent" }} } should work in your case.

How do I turn off the hover button?

To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.

What is material UI button?

Buttons allow users to take actions, and make choices, with a single tap. Buttons communicate actions that users can take. They are typically placed throughout your UI, in places like: Modal windows.


4 Answers

You can solve this problem by adding an inline style

export const SubmitButton = ({ onClick }) => {   return (     <StyledButton       variant="raised"       onClick={onClick}       style={{ backgroundColor: 'transparent' }} >       login     </StyledButton>   ) } 
like image 92
ccd Avatar answered Oct 05 '22 22:10

ccd


Try setting it to the same color as the background:

root = {
    backgroundColor: "#FFF"
    "&:hover": {
        //you want this to be the same as the backgroundColor above
        backgroundColor: "#FFF"
    }
}
like image 40
Nishant Mehta Avatar answered Oct 05 '22 23:10

Nishant Mehta


this is solution for v5 if anyone needs it

         <IconButton
            disableElevation
            disableRipple
            size="small"
            sx={{
              ml: 1,
              "&.MuiButtonBase-root:hover": {
                bgcolor: "transparent"
              }
            }}
          >

          </IconButton>
like image 34
Said Pc Avatar answered Oct 05 '22 22:10

Said Pc


You can try setting the background of the button as none

button: {    
    '&:hover': {
        background: 'none',
    },
}
like image 34
Saranya Jena Avatar answered Oct 05 '22 22:10

Saranya Jena