From 1647d91dc5a8465d9eefec86b262836956a36fe5 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Mon, 4 Oct 2021 20:10:16 +0200 Subject: [PATCH] Dragging on a numeric prop with a range now respects the range. Fixes #31 --- theatre/studio/src/uiComponents/form/BasicNumberInput.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx b/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx index db906e0..dedef74 100644 --- a/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx +++ b/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx @@ -241,7 +241,7 @@ const BasicNumberInput: React.FC<{ const onDrag = (deltaX: number, _dy: number) => { const curState = refs.current.state as IState_Dragging - const newValue = + let newValue = curState.valueBeforeDragging + propsA.nudge({ deltaX, @@ -249,6 +249,10 @@ const BasicNumberInput: React.FC<{ magnitude: 1, }) + if (propsA.range) { + newValue = clamp(newValue, propsA.range[0], propsA.range[1]) + } + setState({ ...curState, currentDraggingValue: newValue,