Skip to content

Commit

Permalink
fix(Slider,RangeSlider): reverse marks order in vertical orientation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Nov 1, 2021
1 parent d0bbf53 commit 07fdd09
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/RangeSlider/RangeSlider.tsx
Expand Up @@ -111,7 +111,9 @@ const RangeSlider = React.forwardRef((props: RangeSliderProps, ref) => {
const getValueByPosition = useCallback(
(event: React.MouseEvent) => {
const barOffset = getOffset(barRef.current);
const offset = vertical ? event.pageY - barOffset.top : event.pageX - barOffset.left;
const offset = vertical
? barOffset.top + barOffset.height - event.pageY
: event.pageX - barOffset.left;
const val = rtl && !vertical ? barOffset.width - offset : offset;

return getValueByOffset(val) + min;
Expand Down
2 changes: 1 addition & 1 deletion src/Slider/Graduated.tsx
Expand Up @@ -69,7 +69,7 @@ const Graduated: RsRefForwardingComponent<'div', GraduatedProps> = React.forward

return (
<Component ref={ref} className={classes}>
<ul>{graduatedItems}</ul>
<ol>{graduatedItems}</ol>
</Component>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Slider/Handle.tsx
Expand Up @@ -50,7 +50,7 @@ const Handle: RsRefForwardingComponent<'div', HandleProps> = React.forwardRef(

const rootRef = useRef<HTMLDivElement>();
const horizontalKey = rtl ? 'right' : 'left';
const direction = vertical ? 'top' : horizontalKey;
const direction = vertical ? 'bottom' : horizontalKey;
const styles = { ...style, [direction]: `${position}%` };
const { merge, prefix } = useClassNames(classPrefix);
const handleClasses = merge(className, prefix('handle'), { active });
Expand Down Expand Up @@ -146,7 +146,7 @@ const Handle: RsRefForwardingComponent<'div', HandleProps> = React.forwardRef(
{renderTooltip ? renderTooltip(value) : value}
</Tooltip>
)}
<Input value={value} {...rest} />
<Input tabIndex={-1} value={value} {...rest} />
{children}
</Component>
);
Expand Down
2 changes: 1 addition & 1 deletion src/Slider/ProgressBar.tsx
Expand Up @@ -27,7 +27,7 @@ const ProgressBar: RsRefForwardingComponent<'div', ProgressBarProps> = React.for

const sizeKey = vertical ? 'height' : 'width';
const dirKey = rtl ? 'right' : 'left';
const startKey = vertical ? 'top' : dirKey;
const startKey = vertical ? 'bottom' : dirKey;

const styles = { ...style, [startKey]: `${start}%`, [sizeKey]: `${end - start}%` };
const classes = merge(className, withClassPrefix());
Expand Down
4 changes: 3 additions & 1 deletion src/Slider/Slider.tsx
Expand Up @@ -193,7 +193,9 @@ const Slider = React.forwardRef((props: SliderProps, ref) => {
const getValueByPosition = useCallback(
(event: React.MouseEvent) => {
const barOffset = getOffset(barRef.current);
const offset = vertical ? event.pageY - barOffset.top : event.pageX - barOffset.left;
const offset = vertical
? barOffset.top + barOffset.height - event.pageY
: event.pageX - barOffset.left;
const offsetValue = rtl && !vertical ? barOffset.width - offset : offset;

return getValueByOffset(offsetValue) + min;
Expand Down
34 changes: 20 additions & 14 deletions src/Slider/styles/index.less
Expand Up @@ -83,9 +83,13 @@
}
}

.rs-slider-vertical &::before {
left: ((@slider-handle-diameter - @slider-bar-side-length)/2);
margin-top: (-@slider-handle-diameter / 2);
.rs-slider-vertical & {
top: unset;

&::before {
left: ((@slider-handle-diameter - @slider-bar-side-length)/2);
margin-top: (-@slider-handle-diameter / 2);
}
}
}

Expand Down Expand Up @@ -127,12 +131,12 @@
.rs-slider-graduator {
width: 100%;

ul,
ol,
li {
list-style: none;
}

> ul {
> ol {
display: flex;
padding-left: 0;
width: 100%;
Expand All @@ -157,7 +161,8 @@

// Vertical styles
.rs-slider-vertical & {
top: -4px;
top: unset;
bottom: -4px;
margin-left: -1px;
}
}
Expand All @@ -168,8 +173,8 @@
// Vertical styles
.rs-slider-vertical & {
left: 0;
top: auto;
bottom: -4px;
bottom: unset;
top: -4px;
}
}

Expand All @@ -188,10 +193,10 @@
display: block;
height: 100%;

> ul {
> ol {
width: @slider-bar-side-length;
display: flex;
flex-direction: column;
flex-direction: column-reverse;
height: 100%;
padding: 0;

Expand All @@ -212,7 +217,7 @@

.rs-slider-vertical & {
width: @slider-bar-side-length;
border-radius: (@slider-bar-side-length / 2) (@slider-bar-side-length / 2) 0 0;
border-radius: 0 0 (@slider-bar-side-length / 2) (@slider-bar-side-length / 2);
}
}

Expand All @@ -222,7 +227,8 @@

// Reset all setting
.rs-slider-mark {
top: -8px;
top: unset;
bottom: -8px;
left: (@slider-bar-side-length + @slider-mark-margin-top);

&-content {
Expand All @@ -231,7 +237,7 @@
}

.rs-slider-mark-last {
top: auto;
bottom: -8px;
bottom: unset;
top: -8px;
}
}

1 comment on commit 07fdd09

@vercel
Copy link

@vercel vercel bot commented on 07fdd09 Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.