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.

[IconButton] : iconHoverColor

See original GitHub issue

Problem Description

I am using IconButton with a nested SVG Icon, Settings. When I set hoverColor on the SVG icon itself, the effect I desired (a highlighted-on-hover cog) works up until being clicked.

I am trying to use iconStyles on the IconButton and change iconHoverColor but cannot seem to emulate this effect. Any feedback is appreciated. Ideally, I want to do something like this so that the SVG icon will keep the color when being highlighted:

<IconButton tooltip="Font Icon" iconStyle={{iconHoverColor: '#55ff55'}} style={styles.icon}>
   <Settings style={styles.settings} color={'white'} />
</IconButton>

Versions

  • Material-UI: 0.15.0-alpha.2
  • React: 15.0.1
  • Browser: Chrome 49.0.2623.110

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
catphatcommented, Oct 19, 2016

I recently ran into this issue and solved it with the following implementation.

.parent-span svg {
  transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms;
}

.parent-span:hover svg {
  fill: #0097a7 !important;
}
import IconButton from 'material-ui/IconButton'
import ChevronLeftIcon from 'material-ui/svg-icons/navigation/chevron-left'

...

<span className="parent-span">
  <IconButton>
    <ChevronLeftIcon />
  </IconButton>
</span>
3reactions
tintin1343commented, Apr 13, 2016

@kingscott : There is not property called iconHoverColor in css. And i don’t think you can specify :hover property like in css. However what you can do here is use the onMouseEnter and onMouseLeave props of iconButton and try and achieve what you want to.

Check this out:

import React from 'react';
import IconButton from 'material-ui/IconButton';
import ActionHome from 'material-ui/svg-icons/action/home';

const iconStyles = {
  marginRight: 24,
};

const styles = {
  icon: {
    margin: 0,
  },
};

function addColor() {
  this.style.backgroundColor = 'magenta';
}

function removeColor() {
  this.style.backgroundColor = 'white';
}

const IconButtonExampleSimple = () => (
  <IconButton tooltip="Font Icon" onMouseEnter={addColor}
    onMouseLeave={removeColor} style={styles.icon}
  >
    <ActionHome style={iconStyles} color={'black'} />
  </IconButton>
);

export default IconButtonExampleSimple;

This certainly works for me.

iconbutton

hope this helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hover effect on IconButton in Material-UI
This is an iconButton from Material-UI that I am using. As you can see there is a slight grey border around the icon...
Read more >
The Complete Guide to MUI IconButton onClick and Hover
The Material-UI IconButton creates a clickable icon with all the props and behavior of a MUI Button. In this post we will learn...
Read more >
hoverColor property - IconButton class - material library
The color for the button when a pointer is hovering over it. If ThemeData.useMaterial3 is set to true, this hoverColor will be mapped...
Read more >
IconButton hover focus
IconButton hover focus ... https://github.com/mui-org/material-ui/blob/master/docs/src/pages/components/buttons/IconButtons.js ... @material-ui/icons.
Read more >
[IconButton] : iconHoverColor · Issue #3916 · mui/material-ui
I am using IconButton with a nested SVG Icon, Settings . When I set hoverColor on the SVG icon itself, the effect I...
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