Skip to content
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

feat(react-slider): adjust slider thumb position #32424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: adjust thumb positioning",
"packageName": "@fluentui/react-slider",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const sliderClassNames: SlotClassNames<SliderSlots> = {

// Internal CSS variables
const thumbSizeVar = `--fui-Slider__thumb--size`;
const innerThumbRadiusVar = `--fui-Slider__inner-thumb--radius`;
const thumbPositionVar = `--fui-Slider__thumb--position`;
const railSizeVar = `--fui-Slider__rail--size`;
const railColorVar = `--fui-Slider__rail--color`;
const progressColorVar = `--fui-Slider__progress--color`;
Expand Down Expand Up @@ -40,12 +42,14 @@ const useRootStyles = makeStyles({

small: {
[thumbSizeVar]: '16px',
[innerThumbRadiusVar]: '5px',
[railSizeVar]: '2px',
minHeight: '24px',
},

medium: {
[thumbSizeVar]: '20px',
[innerThumbRadiusVar]: '6px',
[railSizeVar]: '4px',
minHeight: '32px',
},
Expand Down Expand Up @@ -172,7 +176,7 @@ const useRailStyles = makeStyles({
'::before': {
width: `var(${railSizeVar})`,
top: '-1px',
bottom: '1px',
bottom: '-1px',
},
},
});
Expand All @@ -182,6 +186,10 @@ const useRailStyles = makeStyles({
*/
const useThumbStyles = makeStyles({
thumb: {
// Ensure the thumb stays within the track boundaries.
// When the value is at 0% or 100%, the distance from the track edge
// to the thumb center equals the inner thumb radius.
[`${thumbPositionVar}`]: `clamp(var(${innerThumbRadiusVar}), var(${sliderProgressVar}), calc(100% - var(${innerThumbRadiusVar})))`,
gridRowStart: '2',
gridRowEnd: '2',
gridColumnStart: '2',
Expand Down Expand Up @@ -214,11 +222,11 @@ const useThumbStyles = makeStyles({
},
horizontal: {
transform: 'translateX(-50%)',
left: `var(${sliderProgressVar})`,
left: `var(${thumbPositionVar})`,
},
vertical: {
transform: 'translateY(50%)',
bottom: `var(${sliderProgressVar})`,
bottom: `var(${thumbPositionVar})`,
},
});

Expand Down
Loading