简体   繁体   中英

Prevent 'aria-live' element from being focused by screen reader

Is there a way to prevent an 'aria-live' element from being focused by a screen reader?

I'm developing a calendar and would like to notify user whenever the currently selected month is changed.

As others have said, keyboard focus does not have to move to the aria-live region. Any changes made to a live region will just be announced. The focus will not move.

However, if you are asking whether you can prevent the user from moving their screen reader focus to the element, no, you can't prevent that. As long as the element is part of the accessibility tree (a subset of the DOM), the user can navigate to that element and hear its contents.

The rules on whether a DOM element is part of the accessibility tree are spelled out pretty well in " 5.1 General rules for exposing WAI-ARIA semantics ". Specifically, in the " 5.1.2 Including... " section, it says elements that have text will be included. I'm presuming your aria-live element has text because it's being announced as you change it. If you jump back up to the " 5.1.1 Excluding... " section, you can prevent the element from being on the accessibility tree if you use aria-hidden="true" , but if you do that, then the live changes won't be read.

If implemented correctly, aria-live region will never receive visual focus.

Make sure that the live region is present on the page initially, only then dynamically added/changed content will be announced. Live region of the page that gets announced whenever content changes but the focus doesn't shift to the live region.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM