Skip to content

Commit de18bba

Browse files
* onTouchStart and onTouchEnd props added
1 parent d38ed72 commit de18bba

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ const handleValueChange = useCallback((low, high) => {
8383
| `renderLabel` | Should render label above thumbs.<br/>If no function is passed, no label will be drawn. | `(value: number) => Node` | `undefined` |
8484
| `renderNotch` | Should render the notch below the label (above the thumbs).<br/>Classic notch is a small triangle below the label.<br/>If `allowLabelOverflow` is not set to true, the notch will continue moving with thumb even if the label has already reached the edge of the component and can't move further.| `() => Node` | `undefined` |
8585
| `onValueChanged` | Will be called when a value was changed.<br/>If `disableRange` is set to true, the second argument should be ignored.<br/>`fromUser` will be true if the value was changed by user's interaction. | `(low: number, high: number, fromUser: boolean) => void` | `undefined` |
86+
| `onTouchStart` | Will be called when user starts interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
87+
| `onTouchEnd` | Will be called when user ends interaction with slider.<br/>If `disableRange` is set to true, the second argument should be ignored. | `(low: number, high: number) => void` | `undefined` |
8688

8789
All the other props (e.g. style) will be passed to root container component.
8890

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const Slider = (
2121
disableRange,
2222
disabled,
2323
onValueChanged,
24+
onTouchStart,
25+
onTouchEnd,
2426
renderThumb,
2527
renderLabel,
2628
renderNotch,
@@ -127,6 +129,7 @@ const Slider = (
127129
const containerX = pageX - downX;
128130

129131
const { low, high, min, max } = inPropsRef.current;
132+
onTouchStart?.(low, high);
130133
const containerWidth = containerWidthRef.current;
131134

132135
const lowPosition = thumbWidth / 2 + (low - min) / (max - min) * (containerWidth - thumbWidth);
@@ -166,6 +169,8 @@ const Slider = (
166169

167170
onPanResponderRelease: () => {
168171
setPressed(false);
172+
const { low, high } = inPropsRef.current;
173+
onTouchEnd?.(low, high);
169174
},
170175
}), [pointerX, inPropsRef, thumbWidth, disableRange, disabled, onValueChanged, setLow, setHigh, labelUpdate, notchUpdate, updateSelectedRail]);
171176

0 commit comments

Comments
 (0)