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

titleProp options doesn't preserve the existing title if no title prop is passed #310

Closed
sudkumar opened this issue May 24, 2019 · 2 comments · Fixed by #311
Closed

titleProp options doesn't preserve the existing title if no title prop is passed #310

sudkumar opened this issue May 24, 2019 · 2 comments · Fixed by #311

Comments

@sudkumar
Copy link
Contributor

💬 Questions and Help

When passing the titleProp option, the @svgr/babel-plugin-svg-dynamic-title plugin puts a <title>{title}</title> element inside the svg element. If there is an existing title element inside the svg, it will be replaced with this element only.

My question is: Is there any specific reason for falling back to the content of the existing title element (if present) when the title prop passed to the component is undefined ?

For example, suppose my test.svg has following content:

<svg>
  <title>Default Title</title>
</svg>

When passing this svg through the compiler with titleProp option set to true, the content of React Component is:

<svg>
  <title>{title}</title>
</svg>

Can we not keep the Default Title as fallback when title is not provided ? e.g.

<svg>
-  <title>{title}</title>
+ <title>{title === undefined ? "Default Title" : title}</title>
</svg>

@neoziro Please help.

P.S.: I looked into the babel-plugin-svg-dynamic-title/src/index.js source code but had no clue about the implementation.

@sudkumar
Copy link
Contributor Author

I am working on an application bootstrapped with create-react-app which usage @svgr/webpack. I have also opened an issue regarding this feature in cra (facebook/create-react-app#7103).

@gregberge
Copy link
Owner

Hello @sudkumar, I think you are right, if the user don't remove the title, it should remain in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants