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

Everett Zufelt’s picture

Category: task » support
Status: Active » Fixed

main-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.

droplet’s picture

Category: support » task
Status: Fixed » Active

no supports :) we need comments on it I think.

Everett Zufelt’s picture

@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

    <div id="skip-link">
      <a href="#main-content" class="element-invisible element-focusable"><?php print t('Skip to main content'); ?></a>
    </div>

Should this be documented in page.tpl.php?

droplet’s picture

@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).

Everett Zufelt’s picture

Title: Missing comments on main-content » Add comments for main-content anchor in page.tpl.php

Clarifying title.

I don't really think that this needs comments, but I'm happy to review any patch that is submitted.

andrewmacpherson’s picture

Title: Add comments for main-content anchor in page.tpl.php » Add comments for skip link and main-content anchor in templates
Component: Seven theme » theme system
Issue tags: +skip navigation

I 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.

mgifford’s picture

@andrew - can you come up with a patch?

lauriii’s picture

Component: theme system » Classy theme
Issue summary: View changes
mgifford’s picture

Issue tags: +Documentation

Isn'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.

droplet’s picture

It 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.

mgifford’s picture

How 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.

heliogabal’s picture

Status: Active » Needs review
StatusFileSize
new613 bytes

provided a patch with a comment as proposed in #11.

mgifford’s picture

This looks good, other than accessibility was spelled incorrectly. It should be:

{# keyboard navigation / accessibility link to main content section in page.html.twig #}

heliogabal’s picture

Hi mgifford,
thanks for checking, I'm not native speaker, so missed that. Corrected patch attached.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Looks good then.

star-szr’s picture

Status: Reviewed & tested by the community » Needs work

I 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!

heliogabal’s picture

Status: Needs work » Needs review
StatusFileSize
new634 bytes

Hi Scott,
thanks for your guidance, much appreciated, hopefully I got it right this time...

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andrewmacpherson’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Accessibility

The 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.

chernous_dn’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB

Based 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

andrewmacpherson’s picture

Component: Classy theme » theme system
Status: Needs review » Reviewed & tested by the community
Issue tags: +stable, +Classy

Looks 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.

star-szr’s picture

Assigned: Unassigned » star-szr

Assigning for committer (and Stable maintainer) review.

star-szr’s picture

Assigned: star-szr » Unassigned
Status: Reviewed & tested by the community » Needs work
Issue tags: +Novice

Sorry 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.

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new6.39 KB
new6.29 KB

Removing space around slash as mentioned by @Cottser
Update:
Ignore this patch. Accidentally committed wrong file, updating another patch

mohit_aghera’s picture

Removing space around slash as mentioned by @Cottser
Please ignore patch in #24
This patch contains interdiff from #20

mohit_aghera’s picture

Re-rolling patch for 8.2.x dev

andrewmacpherson’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.57 KB

Very 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.

star-szr’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed efad394 to 8.2.x and 381321e to 8.1.x. Thanks!

  • Cottser committed 381321e on 8.1.x
    Issue #1390580 by mohit_aghera, heliogabal, Chernous_dn,...

  • Cottser committed efad394 on 8.2.x
    Issue #1390580 by mohit_aghera, heliogabal, Chernous_dn,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.