Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A11y: Add .is-sr-only to helpers #1764

Merged
merged 2 commits into from
Jul 9, 2018
Merged

A11y: Add .is-sr-only to helpers #1764

merged 2 commits into from
Jul 9, 2018

Conversation

Muhnad
Copy link
Contributor

@Muhnad Muhnad commented Mar 28, 2018

This is a **new feature **.

Why we need is-sr-only?

  • we need is-sr-only to hide content visually and keep the screen readers read the content, that's mean the content is accessible to screen readers.

@Come2Daddy
Copy link
Contributor

Come2Daddy commented Mar 29, 2018

If it's hidden to the eye why should it be accessible to screen readers ?
Just found it's case specific, when you want screen readers to access some usefull hidden contents. I guess a more specific name would be better.

@Muhnad
Copy link
Contributor Author

Muhnad commented Mar 29, 2018

@Come2Daddy what about is-sr-only?

@Come2Daddy
Copy link
Contributor

Sounds good.

@Muhnad
Copy link
Contributor Author

Muhnad commented Mar 31, 2018

@jgthms What do you think about class naming?

@jgthms
Copy link
Owner

jgthms commented Apr 8, 2018

is-sr-only is better I think yeah! Can you add some documentation as well to explain the purpose and how it works?

@Muhnad Muhnad changed the title A11y: Add .is-visually-hidden to helpers A11y: Add .is-sr-only to helpers Apr 8, 2018
@Muhnad
Copy link
Contributor Author

Muhnad commented Apr 8, 2018

.is-sr-only: is a class for hiding elements text visually but keep the element available to be announced by a screen reader.

Using .is-sr-only we can:

  • Provide additional details about the element like hidden labels, error details.
  • Add additional instructions and information about navigation, actions and so on.

Examples:

<p class="has-text-danger">
  message here
</p>

in this example, we have a message styled by CSS with color: red and this means the message is important or invalid or danger and when the screen reader read the paragraph will read the text inside it so we need something to tell SR the content of the message is important so we need to hide the text from all users except SR.

<p class="has-text-danger">
  <span class="is-sr-only">Important </span>
  message here
</p>

another example:
imagine you have a button with an icon like this one:

<button class="delete"></button>

when screen reader read this button will announce empty button but actually the buttons have an "X" icon but this icon is added by CSS and screen reader read the HTML text so we need to add text for this button:

<button class="delete">
  <span class="is-sr-only">Close</span>
</button>

now SR will annonce the button with close text, so the user now know this button for close action.

Note we have another replacement for the latest example by adding aria-label for the button

  <button class="delete" aria-label="close"></button>

@Muhnad
Copy link
Contributor Author

Muhnad commented Apr 8, 2018

@Come2Daddy @jgthms take a look please 😄

@jgthms jgthms merged commit e71c248 into jgthms:master Jul 9, 2018
@Muhnad Muhnad deleted the Feature/add-helper branch July 9, 2018 15:17
@anton-g anton-g mentioned this pull request Aug 8, 2018
@darylf
Copy link
Contributor

darylf commented Aug 31, 2018

@Muhnad I have a question about your examples.

What would a screen reader read if you added the aria-label to the danger text? Is there a benefit to using is-sr-only over the aria-label example?

<p class="has-text-danger" aria-label="Important">
  message here
</p>

@Muhnad
Copy link
Contributor Author

Muhnad commented Sep 1, 2018

@darylf in your example Screen reader will read the aria-label text only and will ignore the paragraph text.

Why does this happen?
it's all about accessible name algorithm work.

in your example, the accessible name will be 'Important' not 'message here' because ARIA overrides the HTML

the accessible name provided with the native HTML will be overridden by the accessible name provided with ARIA.

@darylf
Copy link
Contributor

darylf commented Sep 1, 2018

Thanks so much for explaining!

@JohnAherne
Copy link

I notice that is-sr-only-focusable is not in the docs. Has it not been added or not included for any reason.

Any ideas?

@JohnAherne
Copy link

Sorry. Should have said why I was interested.

I was looking to make use of the skip to main content trick. I found some javascript code - I think from w3c aria site - that is meant to make this trick work, but have not found a way to make it work reliably enough so that a partially sighted user would be able to make sense of what was going on.

@Muhnad
Copy link
Contributor Author

Muhnad commented May 11, 2019

@JohnAherne no you don't need any JS for a skip to content. it all about hiding content from the screen and when using :focus show the item.

check this skip navigation on webaim
check this component you will find there is not JS code to make the skip links work it just HTML elements and CSS skip links react component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants