MUI Slider Component: Different Colored Thumbs
P粉709644700
P粉709644700 2023-09-08 22:49:51
0
1
446

MUI has a slider component: https://mui.com/material-ui/react-slider/

I'm currently using this to allow the user to select a range of values ​​(so my slider has two thumbs) MUI multi-thumb slider documentation: https://codesandbox.io/s/gptppq?file=/demo.js

The slider thumb can be styled as follows: https://codesandbox.io/s/359l9t?file=/demo.tsx:3809-3812

My question: How do I make the two thumbs have different styles/colors?

P粉709644700
P粉709644700

reply all(1)
P粉748218846

You can target the data-index prop through the CSS attribute selector. For example:

<Slider
  value={value}
  onChange={handleChange}
  sx={{
    "& .MuiSlider-thumb": {
      "&[data-index='0']": {
        backgroundColor: "pink"
      },
      "&[data-index='1']": {
        backgroundColor: "yellow"
      }
    }
  }}
/>

produce:

Working CodeSandbox: https://codesandbox.io/s/mui-individually-styled-thumbs-c5m2q9

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!