Skip to content

Use <Fragment> instead of <span> as root element ? #72

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

Closed
robertu7 opened this issue Apr 27, 2018 · 3 comments
Closed

Use <Fragment> instead of <span> as root element ? #72

robertu7 opened this issue Apr 27, 2018 · 3 comments

Comments

@robertu7
Copy link

image

@robertu7 robertu7 changed the title Use <Fragment> intead of <span> as root element ? Use <Fragment> instead of <span> as root element ? Apr 27, 2018
@ryandrewjohnson
Copy link
Owner

ryandrewjohnson commented Apr 27, 2018

@robermac so the only time the <span> should be added is when there's HTML markup detected in your translation. The reason for this is behind the scenes I use React's dangerouslySetInnerHTML to render HTML.

I've looked into adding the dangerouslySetInnerHTML as a prop on the <Fragment> component, but unfortunately at the time of this writing that isn't possible. This means I'm still stuck using a valid HTML element - hence the <span>.

See the Have Fragments support dangerouslySetInnerHTML on react's open issue

I'll keep an eye on the above issue, and if they ever add dangerouslySetInnerHTML support to Fragment I'll update on my end.

@guicara
Copy link

guicara commented Nov 5, 2018

Hello,

Any update on this?
It will be really great to remove this <span>!

In the meantime, I override the initialize renderInnerHtml option for translation (set to false), then use ReactHtmlParser:

import ReactHtmlParser from 'react-html-parser';
const title = ReactHtmlParser(this.props.translate('title_with_html', null, { renderInnerHtml: false }));

@ryandrewjohnson
Copy link
Owner

ryandrewjohnson commented Nov 5, 2018

I'd have a look at the convo happening in #134 as it's related to this. In terms of this issue though I believe the initial issue stands where a Fragment element doesn't support the dangerouslySetInnerHTML property

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

No branches or pull requests

3 participants