I was just forwarded this article - http://hugogiraudel.com/2016/10/13/css-hide-and-seek/

I haven't tested this, but essentially she's recommending:

.visually-hidden {
  border: 0 !important;
  clip: rect(1px, 1px, 1px, 1px) !important;
  clip-path: inset(50%) !important;
  height: 1px !important;
  overflow: hidden !important;
  padding: 0 !important;
  position: absolute !important;
  width: 1px !important;
  white-space: nowrap !important;
}
.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
  clip-path: none !important;
  height: auto !important;
  overflow: visible !important;
  position: static !important;
  width: auto !important;
  white-space: normal !important;
}

We'd need to keep clip (even though it is depreciated) and add clip-path as the latter's support isn't all that great thus far.

Would love feedback on this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mgifford created an issue. See original summary.

mgifford’s picture

Issue tags: -accesibility +Accessibility
andrewmacpherson’s picture

andrewmacpherson’s picture

Issue tags: +SprintWeekend2017

This would be a good one to review at the upcoming Global Sprint Weekend.

mgifford’s picture

Issue tags: +SprintWeekend2017a11y

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

left’s picture

Hello,

I did some testing in Ubuntu Chrome Version 56.0.2924.76 (64-bit) and Firefox 51.0.1 (64-bit) on the 'Skip to main content' anchor element.

From Can I Use http://caniuse.com/#feat=css-clip-path, I understand I shouldn't need the -webkit- prefix for the clip-path property in my version of Chrome.
However, when I use @mgifford's CSS rules from the original post, the 'Skip to main content' anchor element does not display visually when in focus. It is however still read out by ChromeVox.

If I refer to the article @mgifford linked to (http://hugogiraudel.com/2016/10/13/css-hide-and-seek/) and use its recommended CSS, we get:

.visually-hidden {
  border: 0 !important;
  clip: rect(1px, 1px, 1px, 1px) !important;
  -webkit-clip-path: inset(50%) !important;
  clip-path: inset(50%) !important;
  height: 1px !important;
  overflow: hidden !important;
  padding: 0 !important;
  position: absolute !important;
  width: 1px !important;
  white-space: nowrap !important;
}
.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
  clip: auto !important;
  -webkit-clip-path: none !important;
  clip-path: none !important;
  height: auto !important;
  overflow: visible !important;
  position: static !important;
  width: auto !important;
  white-space: normal !important;
}

I think this works as intended, but second opinions would be good :)

mgifford’s picture

Status: Active » Needs review
FileSize
2.47 KB

Thanks for testing this @left. I've rolled it up here. Would be good to test the patch again (and with Windows and Mac). Thanks for testing this in Ubuntu.

afoster’s picture

Tested on Mac 10.11 and it worked fine in with voice over in Chrome 55.0.2883.95 and Safari 10.0.2, and firefox 50.0.1

mgifford’s picture

I'd like this to get tested in Windows too. Thanks for testing this @afoster

andrewmacpherson’s picture

@left Thanks for working on this during the sprint weekend.

develdru’s picture

@mgifford I tested on Windows 10 and found following result:

  • On Firefox 51.0.1 I used text2voice plugin for firefox and paragraph with .visually-hidden was narrated properly
  • On Chrome 55.0.2883.87 I used ChromeVox and similar result as of Firefox
  • On Microsoft Edge 38.14393 I used Windows default Narrator app, and it was able to read the the paragraph which was visually hidden

Thanks

develdru’s picture

Status: Needs review » Reviewed & tested by the community
andrewmacpherson’s picture

Category: Bug report » Plan

@left Thanks for reviewing the suggested changes.
@develdru - Thanks for these additional testing results.

I'm not sure if we should go ahead and commit this in a hurry, or if it's worth checking for other suggestions among wider front-end/accessibility community. My own view is that I haven't encountered any visually-hidden text in Drupal where we'd consider it broken. So to me this sounds more like a modernization plan than a urgent bug-fix.

@mgifford What do you think? Is it urgent?

Note that this patch still includes the deprecated clip but keeps it before the new clip-path. The CSS nuances are beyond me, I'm afraid.

I think it's worth considering this article too: Beware smushed off-screen accessible text. The issue there is that some screen reader speech doesn't have the right pauses. It would be good to look for any examples of this among Drupal's many hidden titles, and whether this patch is makes any difference. The patch in #8 includes the suggested white-space: no-wrap. Before reading that article, I would have put it down as a speech-synthesis quirk that is beyond our control. It's good to know that we might be able to improve it.

andrewmacpherson’s picture

Maybe let's say this is a target for 8.4.x, which gives us time to play with it.

mgifford’s picture

As far as I know it isn't urgent. I think browsers will support clip for a bit. Just something to fix going ahead.

andrewmacpherson’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Let's see if the major browsers have indicated when they expect to remove CSS clip support.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.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

There's a brand new issue about visuallyhidden class in the HTML5 Boilerplate repo. It's another approach to compare ours against.

macOS - VoiceOver / Chrome announcing visually hidden text out of order

mgifford’s picture

Issue tags: +displaynone
Related issues: +#2909931: Refresh CSS CLASS: .visually-hidden

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.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 tags: -displaynone +visually-hidden

changing issue tag to a more accurate name, got some others with this tag already

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mgifford’s picture

Seems like there is still partial support across the board https://caniuse.com/css-clip-path

From HTML5 Boilerplate
https://github.com/h5bp/main.css/blob/main/src/_helpers.css

/*
 * Hide visually and from screen readers
 */

.hidden,
[hidden] {
  display: none !important;
}

/*
 * Hide only visually, but have it available for screen readers:
 * https://snook.ca/archives/html_and_css/hiding-content-for-accessibility
 *
 * 1. For long content, line feeds are not interpreted as spaces and small width
 *    causes content to wrap 1 word per line:
 *    https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
 */

.visually-hidden {
  border: 0;
  clip: rect(0, 0, 0, 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
  /* 1 */
}

/*
 * Extends the .visually-hidden class to allow the element
 * to be focusable when navigated to via the keyboard:
 * https://www.drupal.org/node/897638
 */

.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
  clip: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  position: static;
  white-space: inherit;
  width: auto;
}

/*
 * Hide visually and from screen readers, but maintain layout
 */

.invisible {
  visibility: hidden;
}
mgifford’s picture

Adding another example from the community - https://blog.logrocket.com/design-accessibility-css-visually-hidden-class/

Still no need to update as long as browser support clip[] at this point.