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

Links that open in a new tab/window need to inform users a new tab/window will open #1577

Merged
merged 3 commits into from
Jul 18, 2017

Conversation

mehigh
Copy link
Contributor

@mehigh mehigh commented Jun 29, 2017

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:

Updated panel

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation. (Other as basic components don't have inline documentation, just like this one)

@ellatrix ellatrix requested a review from afercia June 29, 2017 11:36
@ellatrix
Copy link
Member

Is this the correct way to do this? I wish we could use CSS and use target="_blank", otherwise, could we make a shared component for this?

@ellatrix ellatrix added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Jun 29, 2017
@afercia
Copy link
Contributor

afercia commented Jun 29, 2017

could we make a shared component for this?

In another project at Yoast we've actually built a simple <NewTabMessage> component. It's a simple span with a translatable text and visually hidden by default. No icon in our case. Here, the icon could be passed as a prop, maybe.

@mehigh
Copy link
Contributor Author

mehigh commented Jun 29, 2017

@iseulde
The icon can come through via CSS, but the added mark-up (the screen reader extra text) is required either way. And since this is the only occurrence in the Guttenberg interface, I think it can live fine by itself as it is until there's a need for a second usage.

@afercia
Copy link
Contributor

afercia commented Jun 29, 2017

I think PostPermalink uses a second target="_blank".

@mehigh
Copy link
Contributor Author

mehigh commented Jun 30, 2017

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.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

I think PostPermalink uses a second target="_blank".

I looked all over the interface of Guttenberg, but I failed to find the PostPermalink area.

I checked how it's done in the regular posts editing screen:
Permalink
And the page loads in the same tab, hence given the standard functionality an external icon is not required on that element.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

I've exported the newWindowIcon into its own component, but I didn't find a way to use it the 2nd time yet.

@ellatrix
Copy link
Member

ellatrix commented Jul 1, 2017

I'm sure there will be. What I actually meant is something like <ExternalLink href="..." />.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

I've stopped using the inline SVG and instead used CSS to add the icon and it offers an improved UX because now the icon too changes color on hover to match the color of the link text.

Icon matches link text color:
Icon

@ellatrix
Copy link
Member

ellatrix commented Jul 1, 2017

I think we do want to keep the SVG instead of using the icon font? Cc @jasmussen

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

Change of heart @iseulde ? (you previously mentioned "I wish we could use CSS").
With an SVG file inlined, there's no reason to use any CSS whatsoever then for the icon.

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.

@ellatrix
Copy link
Member

ellatrix commented Jul 1, 2017

Yeah, I wish we could use CSS. 🙂

@jasmussen
Copy link
Contributor

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.

@jasmussen
Copy link
Contributor

Doh, sorry, didn't realize this was a PR referencing the very issue I was talking about. My apologies, I blame being mobile.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

Understood, jasmussen. Yes, the iconfont can be avoided. I'll update the PR accordingly.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 1, 2017

I've resurrected the usage of the SVG and dropped the iconfont according to @jasmussen 's input.
I also created the ExternalLink component according to @iseulde 's input. This covers the addition of the icon and the accessibility text.

Thank you for all your recommendations.

return (
<a { ...additionalProps } href={ href } target="_blank">
{ children }
<span className="new-window-icon">
Copy link
Member

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?

Copy link
Contributor Author

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.

height: 1.4em;
vertical-align: top;
}
}
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mehigh
Copy link
Contributor Author

mehigh commented Jul 3, 2017

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.

import Dashicon from '../dashicon';
import './style.scss';

function ExternalLink( { href, children, className, ...additionalProps } ) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

@nylen
Copy link
Member

nylen commented Jul 3, 2017 via email

@mehigh
Copy link
Contributor Author

mehigh commented Jul 12, 2017

@iseulde any steps I can take to allow this development to more forward and not get stale?

@mehigh
Copy link
Contributor Author

mehigh commented Jul 17, 2017

I've refreshed the PR with the latest in master (a small conflict was popping up).

Copy link
Member

@aduth aduth left a 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:

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

@@ -0,0 +1,7 @@
.new-window-icon {
.dashicon {
Copy link
Member

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.

Copy link
Contributor Author

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)
@mehigh
Copy link
Contributor Author

mehigh commented Jul 18, 2017

@aduth

Your input has been handled. I've also squashed my changes in a single commit and updated this to the latest in master.
I've added the rels and a small margin on the sides of the icon - looks better this way.

Thanks for the resource links, they've been really handy.

Copy link
Member

@aduth aduth left a 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.

'noreferrer',
'noopener',
] ) ).join( ' ' );
const classes = classnames( 'new-window-icon', className );
Copy link
Member

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

return (
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel }>
{ children }
<span className="screen-reader-text">{ __( '(opens in a new window)' ) }</span>
Copy link
Member

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)

https://translate.wordpress.org/projects/wp/dev/fr/default?filters%5Bterm%5D=opens+in+a+new+window&filters%5Buser_login%5D=&filters%5Bstatus%5D=current_or_waiting_or_fuzzy_or_untranslated&filter=Filter&sort%5Bby%5D=priority&sort%5Bhow%5D=desc

Otherwise this could be:

<span className="screen-reader-text">
	{
		/* translators: accessibility text */
		__( '(opens in a new window)' )
	}
</span>

@mehigh
Copy link
Contributor Author

mehigh commented Jul 18, 2017

@aduth
Feedback handled.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants