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

New tab prop #51

Closed
wants to merge 3 commits into from
Closed

New tab prop #51

wants to merge 3 commits into from

Conversation

jb-reefer
Copy link

Per the discussion on Issue #48, I have added a newTab boolean prop that, if provided, will set target: _blank on matched URLs.

I added unit tests for the positive and negative cases, but I would LOVE feedback - this style of React is a bit different from what I'm used to writing 😃

@tasti tasti mentioned this pull request Jan 6, 2018
16 tasks
@tasti
Copy link
Owner

tasti commented Jan 6, 2018

This does increase ease of use for enabling target: _blank, but implementing this as a one-off doesn't seem scalable for other use-cases.

Currently, you can get the same result by doing:

<Linkify properties={{target: '_blank'}}>
  ...
</Linkify>

In v1.0.0, you'll be able to do:

const componentDecorator = (href, text, key) => (
  <a href={href} key={key} target="_blank">
    {text}
  </a>
);

<Linkify componentDecorator={componentDecorator}>
  ...
</Linkify>

This may look like more code, but the idea is to make Linkify more customizable. To simplify, you can place the above in your own LinkifyWithTargetBlank component and reuse as often as you'd like.

Does this seem reasonable?

@tasti tasti closed this Jan 6, 2018
@tasti tasti mentioned this pull request Jan 7, 2018
@tasti tasti mentioned this pull request Feb 11, 2020
@AppLoidx
Copy link

AppLoidx commented Feb 12, 2020

Using target="_blank" without rel="noopener noreferrer" is a security risk.

Example: https://mathiasbynens.github.io/rel-noopener

I think good way is to use with rel property

    const componentDecorator = (href, text, key) => (
        <a href={href} key={key} target="_blank" rel="noopener noreferrer">
            {text}
        </a>
    );

    <Linkify componentDecorator={componentDecorator}>
      ...
    </Linkify>

Anyway, thank you!

@nevermore11184
Copy link

nevermore11184 commented Feb 12, 2020

@tasti I recently downloaded the latest version of react-linkify and looks like new tab property does not work for me. I even haven`t found it in props, which in turn means that package was downloaded without this update. Can u help me with this issue?

@tasti
Copy link
Owner

tasti commented Feb 12, 2020

@nevermore11184 have you tried using the componentDecorator prop? Please see the examples above.

@karanraj97
Copy link

@tasti please update in documentation here http://tasti.github.io/react-linkify . For target new tab, no more 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

Successfully merging this pull request may close these issues.

5 participants