Hello! Using the React MUI wrapper, how can I over...
# javascript
h
Hello! Using the React MUI wrapper, how can I override style of nested components with the
sx
prop?
From https://mui.com/material-ui/customization/how-to-customize/#the-sx-prop
Overriding nested component styles
section:
Copy code
<Slider
  defaultValue={30}
  sx={{
    width: 300,
    color: 'success.main',
    '& .MuiSlider-thumb': { <-- Like this
      borderRadius: '1px',
    },
  }}
/>
t
Copy code
Button {
   sx {
      // your styles
   }
}
h
Yes that part is clear, and standard props like
width
and
color
in the example above are straightforward. However, it is the
Copy code
'& .MuiSlider-thumb': {
      borderRadius: '1px',
    },
styling prop I am struggling with. Effectively it would be a “free-text” styling prop without type-safety to target specific css class names
t
Standard classnames already generated
Copy code
sx {
    and(MuiSlider.thumb) {
       // ... your props
    }
}
h
Exactly what I was looking for, thanks 🙂
170 Views