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

fix(svg-title): dont render empty title #341

Merged
merged 2 commits into from
Sep 24, 2019
Merged

fix(svg-title): dont render empty title #341

merged 2 commits into from
Sep 24, 2019

Conversation

sudkumar
Copy link
Contributor

Updates

Summary

Currently when no title is passed and titleProp is set to true, we are
rendering an empty title element which is causing some issues. So we
have added a conditional statement for rendering the title element only
if the title props is not falsy. If we have an existing title, that will
rendered by default. Passing the null values as the title will cause
also cause the title element for not render even if a default title
exists on the svg.

This PR also add support for preserving title attribute which may be present in the svg file.

<svg><title attr="any">Default title</title></svg>

will produce

<svg>
  {title === undefined
    ? <title attr="any">Default title</title>
    : title
      ? <title attr="any">{title}</title> 
      : null}
</svg>

Test plan

Tests have been updated.

Currently when no title is passed and titleProp is set to `true`, we are
rendering an empty title element which is causing some issues. So we
have added a conditional statement for rendering the title element only
if the title props is not falsy. If we have an existing title, that will
rendered by default. Passing the `null` values as the title will cause
also cause the title element for not render even if a default title
exists on the svg

fixes #333
@vercel
Copy link

vercel bot commented Sep 19, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

@codecov
Copy link

codecov bot commented Sep 19, 2019

Codecov Report

Merging #341 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #341      +/-   ##
==========================================
+ Coverage   85.03%   85.06%   +0.03%     
==========================================
  Files          30       30              
  Lines         481      482       +1     
  Branches      134      134              
==========================================
+ Hits          409      410       +1     
  Misses         60       60              
  Partials       12       12
Impacted Files Coverage Δ
...ckages/babel-plugin-svg-dynamic-title/src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b4bd2c...ab9c416. Read the comment docs.

@gregberge
Copy link
Owner

Hello @sudkumar, looks good for me! Thanks!

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.

<title> should be stripped if there is none
3 participants