From ee6efc4cca5dca645d37bc482755a32152a89d37 Mon Sep 17 00:00:00 2001 From: Ephraim Duncan <55143799+ephraimduncan@users.noreply.github.com> Date: Fri, 27 Dec 2024 09:29:12 +0000 Subject: [PATCH] fix: avoid having a drawn and typed signature at the same time (#1516) --- .../ui/primitives/signature-pad/signature-pad.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/ui/primitives/signature-pad/signature-pad.tsx b/packages/ui/primitives/signature-pad/signature-pad.tsx index 753fb1873..bb84bfd5c 100644 --- a/packages/ui/primitives/signature-pad/signature-pad.tsx +++ b/packages/ui/primitives/signature-pad/signature-pad.tsx @@ -191,8 +191,9 @@ export const SignaturePad = ({ } const point = Point.fromEvent(event, DPI, $el.current); + const lastPoint = currentLine[currentLine.length - 1]; - if (point.distanceTo(currentLine[currentLine.length - 1]) > 5) { + if (lastPoint && point.distanceTo(lastPoint) > 5) { setCurrentLine([...currentLine, point]); // Update the canvas here to draw the lines @@ -301,6 +302,7 @@ export const SignaturePad = ({ setTypedSignature(''); setLines([]); setCurrentLine([]); + setIsPressed(false); }; const renderTypedSignature = () => { @@ -349,6 +351,17 @@ export const SignaturePad = ({ const handleTypedSignatureChange = (event: React.ChangeEvent) => { const newValue = event.target.value; + + // Deny input while drawing. + if (isPressed) { + return; + } + + if (lines.length > 0) { + setLines([]); + setCurrentLine([]); + } + setTypedSignature(newValue); if ($el.current) {