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

fix: slider: fixes hidetrack and hiderail props typos and ommissions #656

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
3 changes: 3 additions & 0 deletions src/components/Slider/Slider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,10 @@ const sliderArgs: Object = {
hideMax: false,
hideMin: false,
hideThumb: false,
hideRail: false,
hideTrack: false,
hideValue: false,
included: true,
id: 'mySliderId',
labelPosition: 'bottom',
marks: null,
Expand Down
36 changes: 36 additions & 0 deletions src/components/Slider/Slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,40 @@ describe('Slider', () => {
);
expect(container1.getElementsByClassName('error')).toHaveLength(1);
});

test('should hide track', () => {
const { container: container1 } = render(
<Slider value={50} step={10} hideTrack />
);
expect(
container1.getElementsByClassName('slider-track-opacity')
).toHaveLength(1);
expect(
container1.getElementsByClassName('slider-rail-opacity')
).toHaveLength(0);
});

test('should hide rail', () => {
const { container: container1 } = render(
<Slider value={50} step={10} hideRail />
);
expect(
container1.getElementsByClassName('slider-rail-opacity')
).toHaveLength(1);
expect(
container1.getElementsByClassName('slider-track-opacity')
).toHaveLength(0);
});

test('should hide rail and track', () => {
const { container: container1 } = render(
<Slider value={50} step={10} hideRail hideTrack />
);
expect(
container1.getElementsByClassName('slider-rail-opacity')
).toHaveLength(1);
expect(
container1.getElementsByClassName('slider-track-opacity')
).toHaveLength(1);
});
});
11 changes: 8 additions & 3 deletions src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ export const Slider: FC<SliderProps> = React.forwardRef(
[styles.data]: type === 'data',
},
{
[styles.sliderRailOpacity]: !!hideTrack || !!showMarkers,
[styles.sliderRailOpacity]: !!hideRail || !!showMarkers,
},
])}
onMouseDown={
Expand Down Expand Up @@ -791,7 +791,8 @@ export const Slider: FC<SliderProps> = React.forwardRef(
<div
className={mergeClasses(styles.railMarkerSegment, {
[styles.data]: type === 'data',
[styles.active]: isMarkerSegmentActive(mark.value),
[styles.active]:
!hideTrack && isMarkerSegmentActive(mark.value),
[styles.success]:
isMarkerSegmentActive(mark.value) &&
!!trackStatus &&
Expand All @@ -806,7 +807,11 @@ export const Slider: FC<SliderProps> = React.forwardRef(
trackStatus === SliderTrackStatus.Error,
[styles.railMarkerSegmentHidden]:
index === markers.length - 1,
[styles.railMarkerSegmentOpacity]: !!hideTrack,
[styles.railMarkerSegmentOpacity]:
(!!hideRail &&
!!hideTrack &&
isMarkerSegmentActive(mark.value)) ||
(!!hideRail && !isMarkerSegmentActive(mark.value)),
})}
key={index}
onMouseDown={
Expand Down