Accessibility when data is loaded

[亡魂溺海] 提交于 2019-12-11 06:06:57

问题


I am working on accessibility issue. I have a spinny/loader which appears on screen when data is getting loaded.

<spinny aria-live="polite" role="alert" aria-label="Loading Page">

So when the spinny appears on screen, screen readers give me alert that spinny is loaded. Now I want that when the spinny goes away from screen i want the screen reader to provide message such as data loaded or something like that.

I have tried aria-relevant, aria-atomic etc but nothing seems to have worked.


回答1:


First off, your code sample is specifying conflicting information. Using role="alert" gives you an implicit aria-live="assertive" but you are also specifying aria-live="polite". I would recommend removing role="alert". Having aria-live="polite" is sufficient.

However, if you remove the role from <spinny> (which I'm guessing is a custom html tag?), then your aria-label may not be honored because aria-label'ed things often need a role in addition to the label in order for the label to be read by a screen reader. See "Practical Support: aria-label, aria-labelledby and aria-describedby"

But, I think you might be using aria-label incorrectly anyway. Your live region should look something like:

<div aria-live="polite" class="sr-only" id="myspinny"></div>

(See What is sr-only in Bootstrap 3? for the "sr-only" class. It will visually "hide" the <div> so that any text you put inside it will not be visible to the sighted user but will still be available to screen reader users.)

When data is loading, you should inject text (via javascript) into "myspinny" so that it looks like:

<div aria-live="polite" class="sr-only" id="myspinny">Loading Page</div>

Since the <div> is a live region, the text ("Loading Page") will be announced.

When the data is finished loading and you want to remove the spinner, inject new text into "myspinny" so that it looks like:

<div aria-live="polite" class="sr-only" id="myspinny">Data Loaded</div>

and the screen reader will say "Data Loaded".



来源:https://stackoverflow.com/questions/53083628/accessibility-when-data-is-loaded

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!