Skip to content

Commit

Permalink
fix: slider: increase vertical hit target and handle segmented gap cl…
Browse files Browse the repository at this point in the history
…icks (#635)

* fix: slider: increase vertical hit target and handle segmented gap clicks

* fix: slider: ensure default behavior of tooltip does not hide on reference click
  • Loading branch information
dkilgore-eightfold committed Jun 6, 2023
1 parent 693ee85 commit b4cad7b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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

0 comments on commit b4cad7b

Please sign in to comment.