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

The properties don't work when in Semantic UI <Comments> #78

Open
ElixirMike opened this issue Jun 15, 2019 · 13 comments
Open

The properties don't work when in Semantic UI <Comments> #78

ElixirMike opened this issue Jun 15, 2019 · 13 comments

Comments

@ElixirMike
Copy link

I'm using Semantic UI to output a users comment and want to convert any links they enter innto hyperlniks. The link gets converted, but it ignores all the properties so the link doesn't open in a new tab, change, color, etc. Here is simple snippet.

        <Linkify properties={{target: '_blank', style: {color: 'red', fontWeight: 'bold'}}}>
        {message.content ? <Comment.Text>{message.content}</Comment.Text> : null }
        </Linkify>

I've also tried moving the tag inside the <Comment.Text> and it made no difference. Any possible solution?

@dlombardi
Copy link

really could use the ability to set target to _blank 😬

@steverecio
Copy link

anybody find a solution?

@steverecio
Copy link

Solution:

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

<Linkify componentDecorator={componentDecorator}>
   some user input http://github.com
</Linkify>

@LaurentiuCotaga
Copy link

@steverecio Good solution!

@amandasavluchinske
Copy link

@steverecio Thank you!

@sydinh
Copy link

sydinh commented Sep 19, 2019

@steverecio Really helpful. Many thanks

@mhemrg
Copy link

mhemrg commented Dec 3, 2019

#78 (comment)

@evoyy
Copy link

evoyy commented Jan 29, 2020

This bug was introduced in 1.0.0-alpha. Release 0.2.2 does not have this issue.

@nodabladam
Copy link

Thanks @steverecio, this solution saved the day! This is what I ended up with to get noopener and punycode going:

import punycode from "punycode";
...
const componentDecorator = (href, text, key) => (
   <a href={href} key={key} target="_blank" rel="noopener">
      {punycode.toASCII(text)}
  </a>
);
...
<Linkify componentDecorator={componentDecorator}>
   ...
</Linkify>

@seromenho
Copy link

Seems properties doesn't work at all. Maybe it's missing to pass them to the default componentDecorator.

starsirius added a commit to starsirius/force that referenced this issue Jul 6, 2020
react-linkify v1.0.0-alpha has a bug that `properties` doesn't work.
This is a workaround to specify target for now.

tasti/react-linkify#78 (comment)
@dbudwin
Copy link

dbudwin commented Dec 26, 2020

You can create a decorator like some of the other comments here have mentioned. If you want to open new tabs securely, especially if the links are leaving the site you control, I suggest implementing the following:

TypeScript supported CodeSandbox: https://codesandbox.io/s/cool-montalcini-vkmtb?file=/src/App.tsx

npm install react-secure-link

...then...

import { SecureLink } from "react-secure-link"

<Linkify componentDecorator={(decoratedHref, decoratedText, key) => (
    <SecureLink href={decoratedHref} key={key}>{decoratedText}</SecureLink>
)}>
    Here is a link that will open securely in a new tab: www.github.com.
</Linkify>

@steverecio
Copy link

@dbudwin is the gist here to add rel="noopener noreferrer" to the <a /> tags?

@dbudwin
Copy link

dbudwin commented Dec 26, 2020

@steverecio yes, that's effectively what it does. Just abstracts away the "how" of creating a secure link in a new tab. Nothing fancy.

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