Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add default penColor prop #107

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import trimCanvas from 'trim-canvas'
export interface SignatureCanvasProps extends SignaturePad.SignaturePadOptions {
canvasProps?: React.CanvasHTMLAttributes<HTMLCanvasElement>
clearOnResize?: boolean
penColor?: string
}

export class SignatureCanvas extends Component<SignatureCanvasProps> {
Expand All @@ -25,8 +26,14 @@ export class SignatureCanvas extends Component<SignatureCanvasProps> {
clearOnResize: PropTypes.bool
}

static defaultProps: Pick<SignatureCanvasProps, 'clearOnResize'> = {
clearOnResize: true
static defaultProps: Pick<SignatureCanvasProps, 'clearOnResize' | 'penColor'> = {
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',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it could be a breaking change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a breaking change.
This is inspired from underlying library: https://github.com/szimek/signature_pad/blob/master/src/signature_pad.ts#L96

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or rather, the 2.x version: https://github.com/szimek/signature_pad/blob/2171e510b74362a8dd7c8e7fc77a142f16a4aed1/src/signature_pad.js#L24

Although yes, in both cases, upstream does not prevent you from assigning undefined. As a wrapper, I think following that behavior and not deviating from it is appropriate.

}

static refNullError = new Error('react-signature-canvas is currently ' +
Expand Down