-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, the ref will always return an SVGGElement when the element's type is one of `path`, `circle`, `line`, `rect`, `ellipse`, `polygon`, `polyline`. Because we wrap these types of elements in an SVGGElement and return the SVGGElement as the ref. https://github.com/Bowen7/react-rough-fiber/blob/70f91aa7588ec8375dd53225d8ca74445a716f72/packages/react-rough-fiber/src/renderer.ts#L26-L32 Now, I have changed it to return the first path element of the SVGGElement. It's just a better, not a perfect way to handle the ref. Because `roughjs` renders all shapes to SVGPathElement, we can't get the original ref.
- Loading branch information
Showing
4 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { RoughSVG } from '../index'; | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('return correct ref', () => { | ||
it('render g', () => { | ||
let ref: SVGElement | null = null; | ||
render( | ||
<RoughSVG> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
> | ||
<path d="M0 0 L 10 10" data-testid="path" /> | ||
<g ref={_ref => ref = _ref}/> | ||
</svg> | ||
</RoughSVG> | ||
); | ||
expect(ref!.tagName).toBe('g'); | ||
}); | ||
|
||
it('render path', () => { | ||
let ref: SVGElement | null = null; | ||
render( | ||
<RoughSVG> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
> | ||
<path d="M0 0 L 10 10" data-testid="path" ref={_ref => ref = _ref} /> | ||
<g/> | ||
</svg> | ||
</RoughSVG> | ||
); | ||
expect(ref!.tagName).toBe('path'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters