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: increase vertical hit target and handle segmented gap clicks #635

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
17 changes: 17 additions & 0 deletions src/components/Slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ export const Slider: FC<SliderProps> = React.forwardRef(
}
};

const onSliderHitTargetClick = (
event: React.MouseEvent<HTMLDivElement>
): void => {
event.preventDefault();

onSliderMouseDown(event);
};

const onSliderMouseDown = (
event: React.MouseEvent<HTMLDivElement>
): void => {
Expand Down Expand Up @@ -726,6 +734,14 @@ export const Slider: FC<SliderProps> = React.forwardRef(
ref={sliderRef}
className={mergeClasses(styles.slider, classNames)}
>
<div
className={styles.sliderHitTarget}
onClick={
!allowDisabledFocus && !readOnly
? onSliderHitTargetClick
: null
}
/>
<div
ref={railRef}
className={mergeClasses([
Expand Down Expand Up @@ -825,6 +841,7 @@ export const Slider: FC<SliderProps> = React.forwardRef(
styles.sliderTooltip,
tooltipProps?.classNames,
])}
closeOnReferenceClick={false}
content={getTooltipContentByValue(val)}
key={`value-tooltip-${index}`}
offset={thumbGeometry().diameter + THUMB_TOOLTIP_Y_OFFSET}
Expand Down
12 changes: 12 additions & 0 deletions src/components/Slider/slider.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ $small-min-label-offset-with-steps: 0;
}
}

.rail-marker-segments {
pointer-events: none;
}

.slider-hit-target {
cursor: pointer;
height: 100%;
left: 0;
position: absolute;
width: 100%;
}

.slider-rail,
.slider-track,
.rail-marker-segments {
Expand Down
1 change: 1 addition & 0 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const Tooltip: FC<TooltipProps> = React.memo(
}
if (
!closeOnReferenceClick &&
referenceElement &&
!referenceElement.contains(e.target as Node)
) {
toggle(false)(e);
Expand Down
Loading