Skip to content

Commit

Permalink
Merge pull request #1 from harshmaur/hide_arrow_if_target_not_present
Browse files Browse the repository at this point in the history
fix(): pierpo#126 hide arrow if target is not in the view
  • Loading branch information
harshmaur authored Nov 24, 2020
2 parents 911c25b + 4557306 commit a4ea8d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/SvgArrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ const SvgArrow = ({
const xStart = startingPoint.x;
const yStart = startingPoint.y;

/**
* If the target is not in the view, endingPoint.x and endingPoint.y are zero.
* In this case, do not render the SvgArrow.
*/
if (endingPoint.x === 0 && endingPoint.y === 0) {
return null;
}

const endingPointWithArrow = computeEndingPointAccordingToArrowHead(
endingPoint.x,
endingPoint.y,
Expand Down
7 changes: 7 additions & 0 deletions src/SvgArrow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,12 @@ describe('SvgArrow', () => {
},
});
});

it('should not render path if target is not in the view', () => {
wrapper.setProps({ endingPoint: new Point(0, 0) });
wrapper.update();
const path = wrapper.find('path');
expect(path).toMatchObject({});
});
});
});

0 comments on commit a4ea8d7

Please sign in to comment.