Problem/Motivation
The external link module adds a visual indicator that a link is external. To create this same experience for an unsighted user, there needs to be some screen-reader only text that serves the same purpose. This text should be something like <span class="sr-only">Link is external</span>.
Additionally, accessibility standards require that people are warned when a link will open a new window.
This module offers the ability to force external links to open in new windows, but when that option is selected, we also need to add a warning about this behavior. Because new windows can be hard to navigate with screen-readers, many people would prefer not to click the link if there is a chance they can't get back to the originating site.
Proposed resolution
When the option to force links to open in new windows IS NOT selected
<a href="https://bayareametro.zoom.us/j/85868739599" rel="nofollow noopener noreferrer" class="ext" data-extlink="">
Attend on Zoom
<span class="fa-ext extlink">
<span class="fa fa-external-link"></span>
<span class="sr-only">Link is external.</span>
</span>
</a>
When the option to force links to open in new windows IS selected
<a href="https://bayareametro.zoom.us/j/85868739599" rel="nofollow noopener noreferrer" class="ext" data-extlink="" target="_blank">
Attend on Zoom
<span class="fa-ext extlink">
<span class="fa fa-external-link"></span>
<span class="sr-only">link is external, and opens a new window.</span>
</span>
</a>
Original Issue Summary
Hello,
Working on a project very concerned with the accessibility and using the module external link, I had to create a feature for the screen reader to tell for each external link of the site that it will open in a new window .
I will upload the patch regarding this feature.
| Comment | File | Size | Author |
|---|
Issue fork extlink-3054538
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3054538-2x-branch
changes, plain diff MR !25
- 3054538-a11y-add-screen
changes, plain diff MR !16
Comments
Comment #2
Piegefull commentedComment #3
grimreaperHello,
The translated string needs to be tested.
Also whitespace before and after parenthesis.
In comment, use the whole word "attribute" and not "attr".
Comment #4
grimreaperTagging the issue.
Comment #5
Piegefull commentedNice one,
Here is the fix for the patch.
Comment #6
grimreaperGood for me except checkstyles.
Comment #7
timwoodThe patch from #5 doesn't appear to check against the ExtLink module's 'Open external links in a new window.' setting before applying
title="(New window)"to the link<a>tag. It should probably check for that since if that option isn't enabled, the link doesn't open in a new window.Comment #8
Piegefull commentedSorry for the wait,
Here is the new patch with the verification for the link attr "target" === "_blank".
Comment #9
grimreaperQueeing tests on a more recent PHP version.
Comment #10
grimreaper@Piegefull: Patch needs to be updated. I can help if you need it :).
Comment #11
alisonI feel like this should be an optional setting -- personally. Like, there are other ways to provide this info for WA purposes -- WCAG recommends putting it in the link text, which I realize is closely related to the title attribute, BUT, I really think this should be an optional setting :-/
(...but I don't have time to help with the code! Just sharing my two cents, I appreciate y'all's efforts.)
Comment #12
alisonOne of my colleagues on our WA team said that some screen readers ignore the title attribute -- and even if the software doesn't ignore it, screen reader users often do, because it's read after the link text (so by the time it gets to the title attribute, they've already "clicked" (or not clicked)).
**Either way,** as I'm thinking/typing, I think that whatever is implemented, there should be a reference to the relevant WA guidelines/rules/etc. -- not necessarily the WCAG link I shared, someone else might have a better reference, but it should be in the issue description and release notes/changelog. (Do citation-ish links like that go into code comments, too, or not usually? Idk what the normal practice is.)
Comment #13
grimreaperHello,
Here is an updated version of patch from comment 8.
Now there is a dedicated option, an update hook and a dedicated test.
Unfortunately, my environment does not currently allows me to have Javascript tests working.
So we will see with testbot.
Comment #14
grimreaperComment #15
brucedarby commentedI'm picking this up at DrupalCon Amsterdam.
Comment #16
brucedarby commentedComment #17
scuba_flyHelping with this issue as mentor on Drupalcon Amsterdam 2019
Comment #18
petr illekYAY! First time mentoring at DrupalCon Amsterdam 2019.
Comment #19
jwlockhart commentedHelping with this issue at DrupalCon Amsterdam 2019
Comment #20
brucedarby commentedPatch applied ok but found an issue when trying to change the configuration of the module. When you check 'Open external links in a new window.' another option appears 'Add "(New window)" in the title of links that should open in new window.'. After checking this and saving the 'Add (New Window)' option unchecks. So the save does not persist.
I'm presuming this is the required actions to test this properly? Apologies if I've picked this up wrong?
Also when viewing the page we then got a JS error in Drupal.js:
Comment #21
brucedarby commentedComment #22
rachel_norfolkretagging
Comment #23
elachlan commentedI fixed the testing issue. But now the tests aren't passing.
Comment #24
elachlan commentedCould someone please reroll this patch?
Comment #25
andreyjan commentedRerolled the patch.
Comment #27
andreyjan commentedRemoving the failing line
$this->assertSession()->statusCodeEquals(200);. I don't think it's really needed in this test.Comment #29
neslee canil pintoPatch got failed, Needs a reroll
Comment #30
sahana _n commentedPlease review the patch.
Comment #32
suresh prabhu parkala commentedPlease review!
Comment #34
suresh prabhu parkala commentedPlease review!
Comment #36
suresh prabhu parkala commentedPlease review.
Comment #38
suresh prabhu parkala commentedplease review the patch.
Comment #40
rahulrasgon commentedComment #41
rahulrasgon commentedPlease review the patch.
Thanks
Comment #42
wendymc commentedI've applied the patch from #41 but external links still do not have a title attribute.
Thank you for the effort to make this more accessible!
Comment #43
edwardchiapetI've rerolled #41 for 8.x-1.7.
Comment #44
prudloff commented#43 adds the title string twice (
title="(New window) (New window)").This should fix it.
Comment #45
jenlamptonComment #46
jenlamptonUpdating issue description to be more comprehensive.
Comment #47
douggreen commentedThe attached patch :
It does not update the tests.
Comment #49
douggreen commentedI created a MR, so I'm hiding all of the patches attached to this ticket, to avoid confusion.
Comment #50
douggreen commentedThere is some overlap (and conflicts) with #3182802: Aria-label for external links span throws errors on Accessibility Arc Toolkit so I copied that commit from MR!18 to MR!16 and resolved the conflicts.
Comment #51
jenlamptonAccessibility isn't optional. Why is there an option for "Add "(New window)" in the title of links that should open in new window."? The answer to that checkbox needs to be identical to the answer to "Open external links in a new window or tab." So we don't need both.
Either the links are opened in new windows (AND they have a warning) or they are not (and there is no warning). There is not a use-case for having links open in new windows without a warning. That's not accessible.
Comment #52
douggreen commentedWhile I dislike removing options that other people think are helpful, I agree with @jenlampton that the new option extlink_target_append_new_window should not be an option but just always be true.
I'm a little less clear on whether the other new option extlink_target_append_new_window_label should be configurable or some set text. The fact that extlink_target_label is configurable makes me think that extlink_target_append_new_window_label should also be an option.
Also a little unclear to me is if the new JS I wrote should even exist. If both labels are configurable, and if the defaults are as we currently have them, this JS will never be used. And since the site builder has full control over this, is this new JS a waste of time to run in the browser and maintain in code?
Comment #53
douggreen commentedThis was made an option because of comments starting in #11 above without any discussion until #51. Also, #51 suggested linking to WCAG somewhere, but that was never done. And IMO that is a better thing to have done than making the accessible feature optional. What should we link to?
Comment #54
jenlampton> #51 suggested linking to WCAG somewhere, but that was never done.
We could link to https://www.w3.org/TR/2012/NOTE-WCAG20-TECHS-20120103/G201.html
The text they include in that example is
(opens in new window)so I'm tempted to always use that exact text and not allow for it to be modified. The only use-case for modification of the(opens in new window)text would be if someone had already entered the missing warning into the existinglink is externaltext.Making neither configurable would remove that use-case, but I also dislike the idea of removing options that already in use on production sites. If the
link is externaltext changed suddenly it could cause problems for production sites with translations. (Though I wonder about the use-case for that as well. Was it only so that people could add the missing warning?)In a perfect world I'd like the screen-reader text to always be the same, either
(link is external)for opening links in the same window, or(link is external, opens in new window)for opening links in a new window. That would make the same translations work for everyone, and for a consistent screen-reader experience across sites.To remove the
link is externaltext override, however, we'd need to write a BC layer that would check for an existing value that's different from the default, and if that existed, use that override instead of the non-configurable text. We could even have the admin UI hide the existing field for the override when it's not already in use.It's more work, but would make for a better user experience as well as more consistent accessible output.
Comment #55
douggreen commentedI like the idea of removing the config option extlink_target_append_new_window_label which defines the label text and is new to this patch, always using the recommended text, and linking to the external resource (from above). This isn't removing an option in production. This is removing an option that someone in this thread thought helpful, and replacing it with a standardized (maybe industry standard) a11y text.
The current patch checks for "new window" in the existing label (not "opens in a new window") so I think that the existing patch is already backwards compatible with production systems.
If we agree, then what's left is to remove the config option extlink_target_append_new_window_label, link to the external resource, and make sure the tests work. If I understand correctly, we're pretty much at the place that you started with this ticket, it just took me a while to get there (sorry). What do you think?
Comment #56
douggreen commentedComment #60
smustgrave commentedTests are all green and all eslint issues fixed for the pipeline. Thoughts? Would like to include with 2.0.x release.
Comment #61
smustgrave commentedGoing to get a little ahead of myself and merge as this is the last one on the radar for a beta1 release.
Comment #64
penyaskitoPotentially related: #3275748: `[aria-*]` attributes do not match their roles when using FA icons