WebAIM - Web Accessibility In Mind

E-mail List Archives

Re: [EXTERNAL] Query on landing the focus

for

From: Patrick H. Lauke
Date: Jul 15, 2019 2:55AM


On 15/07/2019 09:50, Mark Magennis wrote:
> Hi Venkatesh,
>
> Your thinking seems to be correct. It makes most sense to set focus back to the same point it was at when the alert appeared. It doesn't matter that this is not an interactive item. Focus is often set to non-interactive items such as the main region in a "Jump to main content" link. Make sure you don't show a visible focus indicator on whatever you set focus back to.
>
> However, since the alert wasn't in response to a user action (at least that's what I understand from your description), I can't see how it's possible to know what the screen reader was reading when the alert appeared. Maybe others on the list might know how this could be done. If that's not possible, I'd say the safest thing would be to set focus back to the h1.

Without trying it, off the top of my head I'd say you could try, as part
of the code that pops up the alert in the first place, storing the value
of document.activeElement and when the popup is closed, programmatically
setting tabindex="-1" on that explicitly, calling the focus() method,
and removing the tabindex="-1" again.

This will only ensure the actual focused/active element gets focused.
This will be different from the virtual cursor/reading cursor of the AT.
I actually suspect that for a page with no focusable/interactive
controls, document.activeElement will simply be the <body> ... and if
that's the case, there's likely no way to move focus back explicitly to
where the virtual focus was at the time since that's not something
exposed to the JS.

Long story short, if the above yields no good results, then it's simply
something that can't be done, and the only option (other than just
losing focus altogether) would be to refocus the start of the document.

P
--
Patrick H. Lauke

www.splintered.co.uk | https://github.com/patrickhlauke
http://flickr.com/photos/redux/ | http://redux.deviantart.com
twitter: @patrick_h_lauke | skype: patrick_h_lauke