Material UI: affect children based on class

删除回忆录丶 提交于 2020-04-16 03:55:27

问题


What I am trying to achieve

I have two classes - root and button - I want to affect button class on root state (for example :hover).


My attempt

I'm trying to display button on root:hover.

const styles = {
   root: {
      '&:hover' {
         // here I can style `.root:hover`
         button: {
            // and I've tried to affect `.root:hover .button` here
            display: 'block'
         }
      }
   },
   button: {
      display: 'none'
   }
}

Expected ouput:

.element-root-35 .element-button-36:hover {
  display: block;
}

Current output:

.element-root-35:hover {
  button: [object Object];
}

Environment

I'm using Material-UI with React.js. In this situation I'm using withStyles() export.


回答1:


Below is the correct syntax:

const styles = {
  root: {
    "&:hover $button": {
      display: "block"
    }
  },
  button: {
    display: "none"
  }
};

Related answers and documentation:

  • jss-plugin-nested documentation
  • Using material ui createStyles
  • Advanced styling in material-ui


来源:https://stackoverflow.com/questions/58626226/material-ui-affect-children-based-on-class

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