Problem/Motivation
The skip-to-main-content link in the html.html.twig templates is not documented, and is important for keyboard-only users.
Proposed resolution
Add a twig-style comment before the skip-link to explain it's accessibility purpose, and note that the target anchor is in page.html.twig
Remaining tasks
Add the comment to all html.html.twig templates in core:
- core/modules/system/templates/html.html.twig
- core/themes/classy/templates/layout/html.html.twig
- core/themes/stable/templates/layout/html.html.twig
User interface changes
None.
API changes
None.
Data model changes
None.
Original report by droplet
What is the main-content and why is hidden.
seven theme page.tpl.php:
<div id="content" class="clearfix">
<div class="element-invisible"><a id="main-content"></a></div>
<?php if ($messages): ?>
<div id="console" class="clearfix"><?php print $messages; ?></div>
<?php endif; ?>
Comments
Comment #1
Everett Zufelt commentedmain-content is the anchor used for the "Skip to main content" link. This is to make it easier for keyboard only usrs to move focus to the beginning of the main content.
.element-invisible is a system class that makes elements invisible, but keeps them available for screen-reader users.
Comment #2
droplet commentedno supports :) we need comments on it I think.
Comment #3
Everett Zufelt commented@droplet
Are their guidelines for when comments are required in templates?
.element-invisible is well documented
The anchor is pretty self explanatory for people familiar with HTML. I suppose the only missing connection is what brings focus to the anchor.
From modules/system/html.tpl.php
Should this be documented in page.tpl.php?
Comment #4
droplet commented@Everett Zufelt,
I'm not sure if there's any guidelines. Yeah, .element-invisible is well-known but Empty #main-content doesn't. I thought it is a placeholder for main content at beginning, not a link anchor for "skip-link".
Oh. Bartik has it too
<a id="main-content"></a>I think its better to rename #main-content to skip-to-main or something reflect the usage if it only used for skip-link. and basically empty html has no dimension, does it need a .element-invisible class? Is it better to screen reader ?
a better way is patch html.tpl and point it to a real html tag instead drop an empty tag around the coding. (it's another issue)
also I would suggest add .screen-reader-text to .skip-link or comment it too. encouraged themers do not remove it (carelessly).
Comment #5
Everett Zufelt commentedClarifying title.
I don't really think that this needs comments, but I'm happy to review any patch that is submitted.
Comment #6
andrewmacpherson commentedI think it would be worth documenting the purpose of the skip link (and the target anchor) with inline comments in the template files.
As Droplet suggests, themers can remove it carelessly. See #1393062: Should the "Skip to main content" link be removed?.
In that issue, a site owner who didn't know the purpose of the link deliberately commented it out of the template.
Affects Bartik and system.module too, not just Seven theme.
Comment #7
mgifford@andrew - can you come up with a patch?
Comment #8
lauriiiComment #9
mgiffordIsn't this just in this system file now? /core/modules/system/templates/html.html.twig
I couldn't find html.html.twig in a Core theme.
Could be just adding it to the other documentation on top of the page. That would probably be the easiest. At this point there isn't any description of what skip-links are or how they work.
Comment #10
droplet commentedIt has documented now:
https://github.com/drupal/drupal/blob/8.0.x/core/modules/system/template...
For me, it's enough but I think most of newbie still don't know it's for Screen Reader.
Comment #11
mgiffordHow about extending it like this:
<a id="main-content" tabindex="-1"></a>{# Used by link is in html.html.twig for skip-link accessibility #}Basically we don't want themers just deleting this line. Providing context will help him see it stays there.
Comment #12
heliogabalprovided a patch with a comment as proposed in #11.
Comment #13
mgiffordThis looks good, other than accessibility was spelled incorrectly. It should be:
{# keyboard navigation / accessibility link to main content section in page.html.twig #}Comment #14
heliogabalHi mgifford,
thanks for checking, I'm not native speaker, so missed that. Corrected patch attached.
Comment #15
mgiffordLooks good then.
Comment #16
star-szrI think because this is docs it should be a proper sentence (start with a capital and end with a period) per https://www.drupal.org/node/1354#drupal.
Also the comment goes over 80 characters, it should probably be a block-type comment in the Twig template, see https://www.drupal.org/node/1823416#comments.
Thanks!
Comment #17
heliogabalHi Scott,
thanks for your guidance, much appreciated, hopefully I got it right this time...
Comment #19
andrewmacpherson commentedThe patch in #17 meets twig coding standards for long comments and applies cleanly. Looks good, thanks heliogabal.
The equivalent templates in the System module and Stable themes would also benefit from this doc comment.
Let's do those in the same patch.
Adding standard issue summary for whoever reviews + commits this.
Comment #20
chernous_dn commentedBased on #17 comment, create patch.
Add the comment to:
core/modules/system/templates/html.html.twig
core/themes/classy/templates/layout/html.html.twig
core/themes/stable/templates/layout/html.html.twig
Comment #21
andrewmacpherson commentedLooks good, latest patch documents the skip link in all versions of html.html.twig, as I suggested. Applies cleanly to 8.1.x and 8.2.x branches.
Since this now updates several themes, I'm changing the component to theme system, and tagging so stable + classy maintainers still see it.
Stable and Classy don't normally accept changes, but this is pure documentation so it should be OK.
Comment #22
star-szrAssigning for committer (and Stable maintainer) review.
Comment #23
star-szrSorry for the delayed review.
The spaces around the slash threw me off, I did a bit of digging and based on https://www.drupal.org/drupalorg/style-guide/content (which you can get to via https://www.drupal.org/node/1354#drupal) and http://www.apvschicago.com/2011/06/slashes-uses-and-restrictions.html I don't think it makes sense to have spaces on either side of the slash here. They're not lines of poetry or open compounds so let's remove the extra spaces :)
Since 8.2.x has diverged in the surrounding code we will need two patches: One for 8.2.x and one for 8.1.x.
Comment #24
mohit_aghera commentedRemoving space around slash as mentioned by @Cottser
Update:
Ignore this patch. Accidentally committed wrong file, updating another patch
Comment #25
mohit_aghera commentedRemoving space around slash as mentioned by @Cottser
Please ignore patch in #24
This patch contains interdiff from #20
Comment #26
mohit_aghera commentedRe-rolling patch for 8.2.x dev
Comment #27
andrewmacpherson commentedVery straightforward, thanks for the latest patches. Both apply cleanly to their branches.
So, RTBC for the patches in #25 and #26.
Attaching interdiff from 20 to 26 for completeness.
Comment #28
star-szrCommitted and pushed efad394 to 8.2.x and 381321e to 8.1.x. Thanks!