-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add an icon and visually hidden a11y text to links that open in a new tab #7883
Conversation
@karmatosed Would be great if you could just double-check the screenshots look ok. The only thing I spotted is that the link text color isn't the same for the permalink and the rich text link. I can make a separate issue if you think that's worth making consistent. |
components/button/style.scss
Outdated
@@ -181,6 +181,15 @@ | |||
padding: 0 8px 1px; | |||
font-size: 11px; | |||
} | |||
|
|||
.components-external-link__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.
I wasn't entirely sure that these are the right selectors to use, or whether I should somehow specify a class of components-button__icon on the 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.
The class should begin with components-button__
since the element is in the Button component.
ah - I need to add some tests, particularly on the button element. Will add some asap. |
Very supportive of the changes to the link formatting tool and permalink editor here. It looks great 👍 I'm not so sure about changing the Preview button, though. In my mind1, the point of the external icon is to shape the user's expectation so that they're not surprised when a new tab opens. This makes total sense since the expectation when clicking a hyperlink is that the browser navigates to a new page in-place. But I don't think users have any such expectations when they click on a button. A button doesn't imply that clicking it will navigate to a new page. It's a button—buttons can do anything! Could an alternative to this be to make the Preview button a 1 Read: I am not a UX designer! 🙂 |
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.
@noisysocks is hereby granted temporary 'UX designer' status as he was on point with suggesting this doesn't get done to the preview button :) I would say apart from that so long as things are just links (not buttons hiding in link clothing) this is a great improvement.
e241a6a
to
77422fc
Compare
@@ -83,6 +83,7 @@ class PostPermalink extends Component { | |||
href={ ! isPublished ? postLink : samplePermalink } | |||
target="_blank" | |||
ref={ ( permalinkButton ) => this.permalinkButton = permalinkButton } | |||
isExternalLink |
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.
Rather than modifying Button
, could we just make PostPermalink
use an ExternalLink
component? It doesn't look like we need any Button
functionality in this case, and I'm wary of Button
becoming a component that has too many responsibilities.
<ExternalLink
className="editor-post-permalink__link"
href={ ! isPublished ? postLink : samplePermalink }
ref={ this.permalinkRef }
/>
(To make the above work, we'll likely need to make ExternalLink
forward refs.)
This is the main reason why a previous attempt in #6786 was abandoned. It ended up in adding a lot of stuff to the Button component. Currently, the Button component is named based on its visual appearance. This is far from ideal and introduces some potential confusion. Components should be named based on what they do. In the discussion on #6786 (comment) at some point it was agreed to split the Button component in two separate components, in short:
Based on that #7534 was created to separate the two components and eliminate ExternalLink. I know that takes a different path from the work done here, sorry for that, but I'd strongly encourage to focus on the effort proposed on #7534. |
9d284b3
to
39f82fe
Compare
Agree that separate components would be nice, I've addressed most of the feedback now. Will take a look at this failing test tomorrow. |
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.
Aside from the failing test this looks great! 🙂
It looks like the failing test was just an intermittent E2E test failure. I restarted the job for you. |
Great - thanks @noisysocks. @karmatosed - I've updated the screenshots at the top, are you happy to approve this now? |
Btw, I spotted a bug - the edit link popover in paragraph blocks doesn't always open in the right place (It's ok the first time you select a link, but the second time it goes wandering off). That bug is present in master so I'll make a separate issue for it (#7992). |
@talldan do we need to have the link icon in the actual link interface? That feels over the top to me. |
@karmatosed - do you mean this icon? I thought that was one of the main points we were trying to address from #1105. My opinion is that we should use the icon consistently on anything that looks like and interacts like a link. I think in any case where a user might be concerned about losing their state or unsaved changes it's good to indicate the link will launch in a new tab. |
@talldan my understanding was that it was for interface links not links in the drop down. It's this bit I am questioning: If everyone wants that's ok it just feels a little odd seeing beside something like this. |
Links added in RichText are opened in a new tab when using the editor toolbar. This commit switches the anchor tag with an ExternalLink component. This makes the link more accessible (it adds some hidden text) and provides an icon indicating that the link is external.
For accessibility purposes the post preview button is now rendered as a button, meaning it can be interacted with using the keyboard (space bar to open a preview page).
… for scss selectors" This reverts commit 77422fce000a2b75788b5fadaa1cd26e770799e3. Revert "Add tests for isExternalLink prop in Button component" This reverts commit 5102826e2c22c7ae59c8d21a3b1fb44781babe5f. Revert "Use flex to center icon in button and add a tiny bit of margin to adjust" This reverts commit 0f3c5fa792dc3386e05acd3821ea32b245b42377. Revert "Set isExternalLink true for post permalink and adjust styling" This reverts commit 402ecd3ff93f3b945072124f4bd47e15fb3470ce. Revert "Position dashicon for external links when rendered via Button" This reverts commit 0930efac6c9eb709b5af7e0e28e9d05d3346bebd. Revert "Allow Button component to render an ExternalLink" This reverts commit 1b8e9ca5c5fe67aab5d08d2ffc0798fb7edfaa8d. Revert "Add prop for icon class name to ExternalLink" This reverts commit ddac73dd0f09a1076f842fdb89ece370e274ac82.
6d47458
to
e1a63e8
Compare
@karmatosed My feeling is that it should be consistent across links. I'm happy for you to make a call and I'll make the necessary changes. Here's a gif so you can see what it looks like in action: |
Let's add it in @talldan and iterate. |
Description
Closes #1105
Adds an icon and the visually hidden text '(Opens in a new window)' for improved a11y to two links that open in a new tab.
ExternalLink
component for the link editor toolbar option on the Paragraph block. It replaces ana
tag. This adds an additional icon and the visibly hidden text to the url.ExternalLink
component for the permalink url when editing the post headerFurthermore a change has been made to the preview button in the top toolbar so that is a button element instead of an anchor.
How has this been tested?
Screenshots
Permalink:
Preview (visually unchanged, but is now a button element):
Paragraph Block Link:
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: