From 9c4d56b05da5ba63b63d3a046ebd9e75542cae1c Mon Sep 17 00:00:00 2001 From: Lav39 Date: Thu, 18 Jul 2024 21:04:57 +0530 Subject: [PATCH] fix: add default penColor prop to SignatureCanvas --- src/index.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 398c345..d3c679c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -6,6 +6,7 @@ import trimCanvas from 'trim-canvas' export interface SignatureCanvasProps extends SignaturePad.SignaturePadOptions { canvasProps?: React.CanvasHTMLAttributes clearOnResize?: boolean + penColor?: string } export class SignatureCanvas extends Component { @@ -25,8 +26,14 @@ export class SignatureCanvas extends Component { clearOnResize: PropTypes.bool } - static defaultProps: Pick = { - clearOnResize: true + static defaultProps: Pick = { + clearOnResize: true, + /** + * This ensures that the pen color is set correctly when the parent component re-renders due to state changes and the penColor prop is passed as undefined. + * In such cases, the underlying signature_pad assigns fillColor as undefined, preventing drawing. + * Ideally, this issue should be fixed in the signature_pad library, but since we are using an older version, we need to handle it here. + */ + penColor: 'black', } static refNullError = new Error('react-signature-canvas is currently ' +