How do I change Material-UI MenuItem background on hover change from AutoComplete props?

冷暖自知 提交于 2021-01-27 18:50:57

问题


AutoComplete uses Menu to render MenuItems as shown in the docs on those pages.

I need to change the backgroundColor of the hovered MenuItem. I am able to change color of all items by using "menuItemStyle" which expects a style object but I'm not sure what the syntax for hover style is in the Material-UI style objects.


回答1:


They are still working on hoverColor which is possible in List Item. But for the time being you can use these Props

<MenuItem 
  primaryText="MenuItem"
  onMouseEnter={(e) => e.target.style.backgroundColor= 'red'}
  onMouseLeave={(e) => e.target.style.backgroundColor = '#ffffff'}/>

This might fix your problem temporarily.




回答2:


Applying hover style on root should do it.

const MyMenuItem = withStyles({
  root: {
    '&:hover': {
      backgroundColor: 'red !important',
      color: 'blue'
    }
  }
})(MenuItem)


来源:https://stackoverflow.com/questions/45536092/how-do-i-change-material-ui-menuitem-background-on-hover-change-from-autocomplet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!