-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Slider] Individual MarkLabel customization #17023
Comments
What do you think of adding
Then, you can target the right mark with CSS. |
Thanks @oliviertassinari for your quickly answer. MuiSlider: {
markLabel: {
color: graysDefault,
'&[data-index="1"]': {
left: '50%',
},
},
}, thanks! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think we must consider #17034 before implementing the fix. |
This comment has been minimized.
This comment has been minimized.
@oliviertassinari pull request submitted :) |
@mstrugo Thanks, we will review it :) |
Why would |
Because that css selector only works in markup elements instead of class names, and all of Slider components are Span in same tree level |
I should have thought about it in the first place, the label accept any node. You can style it so it has the required margin shift to match your app layout requirement. In the future, we can consider to have an option to handle it automatically. I think that we should wait for more upvotes. |
Regarding a future potential API, one option is to have: interface Mark {
value: number;
label?: React.ReactNode;
labelAlign?: 'left' | 'center' | 'right';
} It would also help when the marks are too close and the labels overlap. |
@mstrugo Right, nth-of-type doesn't count among the parent selector. It would still help to share the actual code and what you're trying to do. This would help a lot more than adding an API to make it easier to style every label differently. |
What is the status of this issue? I'm having the same issue as the OP. Has this solution been implemented? MuiSlider: {
markLabel: {
color: graysDefault,
'&[data-index="1"]': {
left: '50%',
},
},
}, |
Has this solution been implemented? It doesn't seem work.
|
@Lijun21 It works, yes: const Slider = styled(MuiSlider)({
'& .MuiSlider-markLabel[data-index="0"]': {
transform: "translateX(0%)"
},
'& .MuiSlider-markLabel[data-index="1"]': {
transform: "translateX(-100%)"
}
}); https://codesandbox.io/s/material-demo-forked-ekd4f?file=/demo.js:121-327 |
@oliviertassinari how would you propose the data-index value could be changed dynamically? I'm wondering if there is a way to pass in a desired index to style, such as this:
|
@enza252 You can do that with https://next.material-ui.com/components/slider-styled and emotion's |
@oliviertassinari thank you, that's a great point in the right direction - we currently export our Slider using withStyles, so I'll investigate |
I have found a better solution, so if you would like to add styling to the first index and last one dynamically, you can try like this .MuiSlider-mark, MuiSlider-markActive {
&[style="left: 0%;"], &[style="left: 100%;"]{
your css here
}
} |
In ES2015 you can use computed property names, like below. This may not be your idea of dynamic, but rather computed (once).
FYI - I've used this approach to specify 3 different styles of marks, whose data indices are computed at initial render, when I generate the
|
i was able to customize the mark completely using slots: <Slider
marks
slots={{ mark: CustomMark }}
valueLabelDisplay="auto"
...
/>
type MarkProps = {
"data-index": number
className: string
ownerState: {
marks: boolean
sx: {
"& .MuiSlider-markLabel": {
fontSize: string
}
}
slots: {}
size: string
value: number
max: number
valueLabelDisplay: string
isRtl: boolean
min: number
disabled: boolean
disableSwap: boolean
orientation: string
color: string
step: number
track: string
marked: boolean
dragging: boolean
focusedThumbIndex: number
}
markActive: boolean
style: {
right: string
}
}
const CustomMark = (props:MarkProps) => {
return (
<div
className={props.className}
style={{
...props.style, // holds { right: <percentage> }
position: "absolute",
width: 5,
height: 5,
borderRadius: "50%",
background: "red",
}}
></div>
);
}; |
Current Behavior ✋
In a RangeSlider with MarkLabels in Min and Max, it doesn't seem possible to style only one MarkLabel. With MuiSlider-markLabel theme override we could affect all mark labels but couldn't apply certain style to only one.
MarkLabels position is absolute, with a transform (translateX) and inline margin left.
If MarkLabel is overrided, I could have my Min MarkLabel OK, but I couldn't do the same with the Max one.
Also, we couldn't use css selectors because all the markup is maded with Span
Expected Behavior 👌
I expect to have something like this:
So I think I need a different class for each mark or a something to style only my Max (right) MarkLabel
Steps to Reproduce ⏯️
Tweak left MarkLabel overriding MUI Theme
Your Environment 💻
Thank you! 😄
P.S.: I love MUI and this is my first issue submitted... sorry for my bad english!
The text was updated successfully, but these errors were encountered: