Dragging on a numeric prop with a range now respects the range.

Fixes #31
This commit is contained in:
Aria Minaei 2021-10-04 20:10:16 +02:00
parent 69acb61f84
commit 1647d91dc5

View file

@ -241,7 +241,7 @@ const BasicNumberInput: React.FC<{
const onDrag = (deltaX: number, _dy: number) => { const onDrag = (deltaX: number, _dy: number) => {
const curState = refs.current.state as IState_Dragging const curState = refs.current.state as IState_Dragging
const newValue = let newValue =
curState.valueBeforeDragging + curState.valueBeforeDragging +
propsA.nudge({ propsA.nudge({
deltaX, deltaX,
@ -249,6 +249,10 @@ const BasicNumberInput: React.FC<{
magnitude: 1, magnitude: 1,
}) })
if (propsA.range) {
newValue = clamp(newValue, propsA.range[0], propsA.range[1])
}
setState({ setState({
...curState, ...curState,
currentDraggingValue: newValue, currentDraggingValue: newValue,