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

Return a more suitable ref #5

Merged
merged 3 commits into from
May 3, 2024
Merged

Return a more suitable ref #5

merged 3 commits into from
May 3, 2024

Conversation

Bowen7
Copy link
Owner

@Bowen7 Bowen7 commented May 3, 2024

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.

if (namespace === SVG_NAMESPACE || type === 'svg') {
// roughjs renders a shape as a fill path(if fill is not none) and a stroke path(if stroke is not none)
// so we need to wrap the shape in a g element
if (!inDefs && type in SVG_SHAPE_MAP) {
type = 'g';
}
domElement = ownerDocument.createElementNS(SVG_NAMESPACE, type);

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.

Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-rough-fiber-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 7:44am

@Bowen7 Bowen7 merged commit ae27e2c into main May 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant