Skip to content

Commit

Permalink
Merge pull request #58 from tfaller/empty-redraw
Browse files Browse the repository at this point in the history
Stay empty after redraw if was empty
  • Loading branch information
michaeldzjap authored Aug 25, 2023
2 parents 1063404 + b5b0c57 commit a5d319c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions __tests__/SignaturePad.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ describe('Component', () => {
render(<SignaturePad ref={instance} redrawOnResize />);

const signaturePad = instance.current as SignaturePad;

signaturePad.fromDataURL(signature);

const spy = jest.spyOn(signaturePad.instance, 'toDataURL');

scaleCanvas(768, 768);
Expand All @@ -233,13 +236,30 @@ describe('Component', () => {
render(<SignaturePad ref={instance} redrawOnResize />);

const signaturePad = instance.current as SignaturePad;

signaturePad.fromDataURL(signature);

const spy = jest.spyOn(signaturePad.instance, 'toDataURL');

signaturePad.handleResize();

expect(spy).not.toHaveBeenCalled();
});

it('does not redraw a signature when the canvas is empty', () => {
const instance = React.createRef<SignaturePad>();

render(<SignaturePad ref={instance} redrawOnResize />);

const signaturePad = instance.current as SignaturePad;

expect(signaturePad.isEmpty()).toBeTruthy();

scaleCanvas(768, 768);

expect(signaturePad.isEmpty()).toBeTruthy();
});

it('does not add the resize event listener on mount', () => {
const spy = jest.spyOn(window, 'addEventListener');
const instance = React.createRef<SignaturePad>();
Expand Down
2 changes: 1 addition & 1 deletion src/SignaturePad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class SignaturePad extends React.PureComponent<Props, State> {

let data;

if (this.props.redrawOnResize && this.signaturePad) {
if (this.props.redrawOnResize && this.signaturePad && !this.signaturePad.isEmpty()) {
data = this.signaturePad.toDataURL();
}

Expand Down

0 comments on commit a5d319c

Please sign in to comment.