tailwindlabs / tailwindcss

A utility-first CSS framework for rapid UI development.
https://tailwindcss.com/
MIT License
83.02k stars 4.21k forks source link

Feature Request: Invisible Content for Screen Reader Users #189

Closed neilmispelaar closed 5 years ago

neilmispelaar commented 7 years ago

Hello,

I would like to submit the following feature proposal for Tailwind: Invisible Content for Screen Reader Users. It's hugely helpful when building websites that have to meet WCAG 2.0 compliance.

WEBAim recommends the following:

.hidden-text 
{
position:absolute;
left:-10000px;
top:auto;
width:1px;
height:1px;
overflow:hidden;
} 

More information about Invisible Content from WEBAim: https://webaim.org/techniques/css/invisiblecontent/

Admittedly, this may exist already and I missed it, or perhaps this goes against the utility first approach, but I just wanted to throw it out there.

Thank you.

NM

adamwathan commented 7 years ago

Hey @neilmispelaar thanks for bringing this up, we definitely want to add this and have plans for a dedicated accessibility module where we can keep these sorts of utilities.

I'll keep this open until we have something in!

neilmispelaar commented 7 years ago

Yay! Looking forward to the addition into the project.

On a side note:

The article below recommends a slightly different approach:

.element-invisible {
  position: absolute !important;
  height: 1px; width: 1px; 
  overflow: hidden;
  clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);
}

Source: https://snook.ca/archives/html_and_css/hiding-content-for-accessibility

hacknug commented 7 years ago

That's also not the best way to do it since clip has been deprecated and it still has some accessibility issues with some screen readers (https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe). Taken from html5-boilerplate, this should be a better approach to accomplish the same in a very similar manner.

.visuallyhidden {
    border: 0;
    clip: rect(0 0 0 0);
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    white-space: nowrap;
}
nternetinspired commented 6 years ago

💯 for an screen-reader only text utility, and I would also recommend following the html5bp approach, which has been thoroughly tested recently: https://github.com/h5bp/html5-boilerplate/issues/1985

CreateSean commented 6 years ago

+1 for this. For now I've created a class .sr-only and using that... but would be nice to have it built in to tailwind.

benface commented 5 years ago

There is a great plugin for this: https://github.com/jack-pallot/tailwindcss-accessibility

adrianparr commented 5 years ago

Is there any news on this?

adamwathan commented 5 years ago

Nothing yet but in the mean time you can use the plugin linked above or follow the documentation to add any custom classes you want.

adrianparr commented 5 years ago

Thanks for the quick reply @adamwathan . However, I couldn't get the 'tailwindcss-accessibility' plugin to work. I tried doing the following after installing with npm ...


// tailwind.config.js

module.exports = {

  // Other stuff here

  plugins: [
    require('tailwindcss-accessibility')
  ]
}
hacknug commented 5 years ago

Relevant link just in case anyone wants to update their plugins and config files: https://zellwk.com/blog/hide-content-accessibly/

adamwathan commented 5 years ago

lol jeez what a nightmare. display: screen-reader; please.

hacknug commented 5 years ago

ANOTHER ONE (DJ Khaled's voice): https://github.com/whatwg/html/issues/4623

adamwathan commented 5 years ago

Added classes for this in #964, will be out in v1.1.