Material UI: affect children based on class
Asked Answered
A

1

2

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.

Abbate answered 30/10, 2019 at 13:15 Comment(0)
I
3

Below is the correct syntax:

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

Edit Nested selector

Related answers and documentation:

Indehiscent answered 30/10, 2019 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.