-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Links that open in a new tab/window need to inform users a new tab/window will open #1577
Conversation
Is this the correct way to do this? I wish we could use CSS and use |
In another project at Yoast we've actually built a simple |
@iseulde |
I think |
Thank you, afercia. I'll see whether adding the external icon looks OK in the PostPermalink area, and if it does I'll add it in and also create a component for them. |
I've exported the newWindowIcon into its own component, but I didn't find a way to use it the 2nd time yet. |
I'm sure there will be. What I actually meant is something like |
I think we do want to keep the SVG instead of using the icon font? Cc @jasmussen |
Change of heart @iseulde ? (you previously mentioned "I wish we could use CSS"). I saw the inlined SVG icons are used almost everywhere, but also saw that the dashicons font is enqueued in the guttenberg page, so... let me know and I'll add the SVG back in or not when I go about creating the ExternalLink component to replace the externalIcon I just created. |
Yeah, I wish we could use CSS. 🙂 |
Let's avoid the icon font if we can. Pretty sure this ticket is a duplicate, and Andrew Duthie, had an idea for how to add "external" as a property that would simply output the icon after the link. It sounded pretty good to me, and so long as the js code is simple, it's cool. |
Doh, sorry, didn't realize this was a PR referencing the very issue I was talking about. My apologies, I blame being mobile. |
Understood, jasmussen. Yes, the iconfont can be avoided. I'll update the PR accordingly. |
I've resurrected the usage of the SVG and dropped the iconfont according to @jasmussen 's input. Thank you for all your recommendations. |
components/external-link/index.js
Outdated
return ( | ||
<a { ...additionalProps } href={ href } target="_blank"> | ||
{ children } | ||
<span className="new-window-icon"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need for this span
? Can the class not be put on the parent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iseulde
This isn't needed, I'll update the PR to include it on the anchor tag instead and drop the span.
components/external-link/style.scss
Outdated
height: 1.4em; | ||
vertical-align: top; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have checks for it, but: https://github.com/WordPress/gutenberg/blob/v0.3.0/.editorconfig#L9. Is there any way to add checks @nylen or @ntwb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's checked as part of the default stylelint config:
I've handled the latest update and also updated the PR description to match the PULL_REQUEST_TEMPLATE.md I've seen, such that it's easier to get all of this in. |
components/external-link/index.js
Outdated
import Dashicon from '../dashicon'; | ||
import './style.scss'; | ||
|
||
function ExternalLink( { href, children, className, ...additionalProps } ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we drop href
(it's not used here, and could be included by ...additionalProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally passed that through the href={ href } because without it the ExternalLink becomes useless (opens up a new empty tab). I know it's not a real required parameter, but it felt better this way.
I'd say leave `href`, it's such a fundamental property of a link that you
want to see it in the code.
…On Jul 3, 2017 11:05 AM, "Riad Benguella" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In components/external-link/index.js
<#1577 (comment)>:
> + * External dependencies
+ */
+import classnames from 'classnames';
+
+/**
+ * WordPress dependencies
+ */
+import { __ } from 'i18n';
+
+/**
+ * Internal dependencies
+ */
+import Dashicon from '../dashicon';
+import './style.scss';
+
+function ExternalLink( { href, children, className, ...additionalProps } ) {
Should we drop href (it's not used here, and could be included by
...additionalProps
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1577 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAN2zsJsUEu54Jh0SNyuwZsj6dhwD8OVks5sKK7MgaJpZM4OI85u>
.
|
@iseulde any steps I can take to allow this development to more forward and not get stale? |
I've refreshed the PR with the latest in master (a small conflict was popping up). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking quite good, but I'd suggest the addition of a rel
attribute.
First for the external
link type, see also:
https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types
Second for noopener
and noreferrer
, see also:
- https://dev.to/ben/the-targetblank-vulnerability-by-example
- Add rel="noopener noreferrer" wherever target="_blank" is used Automattic/wp-calypso#7680
We can can join with incoming prop value:
function ExternalLink( { href, children, className, rel = '', ...additionalProps } ) {
rel = uniq( compact( [
...rel.split( ' ' ),
'external',
'noreferrer',
'noopener'
] ) ).join( ' ' );
https://lodash.com/docs/4.17.4#uniq
https://lodash.com/docs/4.17.4#compact
components/external-link/style.scss
Outdated
@@ -0,0 +1,7 @@ | |||
.new-window-icon { | |||
.dashicon { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of horizontal margin might be nice, but is minor and can be addressed in a styling pass if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll make that happen. Good point with the noopener/etc. rels.
…ndow will open ## Description Fixes WordPress#1105 by adding the external dashicon and the standard screen reader text too. ## How Has This Been Tested? I checked that the Excerpt external link which makes use of the new ExternalLink component contains the new icon and displays it correctly in major OSX browsers (Safari, Chrome, Firefox). I used the browser's inspector to confirm the screen-reader-text element gets properly added as well. ## Screenshots: ![Updated panel](http://files.urldocs.com/share/excerpt-block-updated/excerpt-bloc k-updated.png) ## Types of changes New feature (non-breaking change which adds functionality) ## Checklist: - [x] My code is tested. - [x] My code follows the WordPress code style. - [x] My code follows has proper inline documentation. (Other as basic components don't have inline documentation, just like this one)
Your input has been handled. I've also squashed my changes in a single commit and updated this to the latest in master. Thanks for the resource links, they've been really handy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, and I think could be merged after the class name change.
components/external-link/index.js
Outdated
'noreferrer', | ||
'noopener', | ||
] ) ).join( ' ' ); | ||
const classes = classnames( 'new-window-icon', className ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per recommended CSS Naming guidelines, the default class name should be components-external-link
https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#naming
components/external-link/index.js
Outdated
return ( | ||
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel }> | ||
{ children } | ||
<span className="screen-reader-text">{ __( '(opens in a new window)' ) }</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Elsewhere in the WordPress codebase, this string is preceded with a translator comment translators: accessibility text
. My main concern would be if omitting the translator comment would create a separate string entry in GlotPress (I'm not sure)
Otherwise this could be:
<span className="screen-reader-text">
{
/* translators: accessibility text */
__( '(opens in a new window)' )
}
</span>
@aduth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Description
Fixes #1105 by adding the external dashicon and the standard screen reader text too.
How Has This Been Tested?
I checked that the Excerpt external link which makes use of the new ExternalLink component contains the new icon and displays it correctly in major OSX browsers (Safari, Chrome, Firefox).
I used the browser's inspector to confirm the screen-reader-text element gets properly added as well.
Screenshots:
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: