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

Overriding React component props #1802

Open
Jastrzebowski opened this issue Sep 16, 2024 · 4 comments
Open

Overriding React component props #1802

Jastrzebowski opened this issue Sep 16, 2024 · 4 comments
Assignees

Comments

@Jastrzebowski
Copy link

Documentation issue

I have an issue with the Trans Component Overriding React component props behaviour. I checked the Trans tests, and there is no test for Overwriting props; once I add one, it's failing. Is it a feature removed from the code but left in the documentation?

For

/**
 * With messages:
 * myKey: 'This is a <CustomLink href="https://example.com/en-EN">link to example.com</CustomLink>.'
 **/  

<Trans
  i18nKey="myKey"
  components={{ 
    CustomLink: <a href="value-to-be-overridden"/> 
    }}
/>

Existing behaviour

This is a <a href="value-to-be-overridden">link to example.com</a>.

Expected behaviour

This is a <a href="https://example.com/en-EN">link to example.com</a>.

Motivation

I want to fix the flows in the documentation and, at best, bring back the props substitution. The use case with links seems valuable, especially when using Routing. However, I can see additional ones, such as using icons as a component.

@adrai
Copy link
Member

adrai commented Sep 17, 2024

Here is the test:

describe('trans overwrites translation prop', () => {

with this key: https://github.com/i18next/react-i18next/blob/master/test/i18n.js#L44

@Jastrzebowski
Copy link
Author

Thank you, @adrai! The test is different than the examples in the documentation with custom components. The corresponding one I was looking at yesterday is:

describe('trans simple with custom html tag', () => {

Would that mean the costume tags were never meant to have overwriteable props?

@adrai
Copy link
Member

adrai commented Sep 17, 2024

Feel free to provide a PR for that.

@jamuhl
Copy link
Member

jamuhl commented Sep 17, 2024

it('should render correct content', () => {
if the code has no prop it should pick from translation string...

honestly...idk...but setting props from translations is another pandora's box

If I remember right sole reason to introduce this was to allow for some keepBasicHtmlTags that contained links...but not to allow full props replacement (therefore also component props if existing win over translations)

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