Infinite Scroll button (span) cannot be focused (accessibility issue)
This is accessibility question. Recently I was testing Infinite Scroll with footer widgets and noticed that "Older posts" button (span) cannot be focused with keyboard. Is it possible to fix it?
Also it would be better to change span to button type.
Thank you!
I can verify this as well.
The Issue
Using a <span> element as the clickable element for loading posts is problematic because as @mtomas7 mentioned, keyboard users cannot focus on it. Also, screen reader users only hear the text within the <span>. They do not necessarily know that the element here is clickable and fires an action.
This means keyboard users and screen reader users cannot load more posts on a site with the infinite scroll handle enabled.
Steps to Reproduce
- Make sure the Scroll to Infinity checkbox is unchecked in your settings.
- Using the Tab key, tab through an archive page and try to focus on the Older Posts element.
Or
- Make sure the Scroll to Infinity checkbox is unchecked in your settings.
- Using a screen reader, navigate through an archive page and focus on the Older Posts element. Listen to the speech feedback provides by the screen reader.
To Fix
The element should be a <button>. That way, keyboard users can focus on it by default. No other action is needed. Also, screen readers get all the semantic information of a button shared with accessibility APIs.
Additionally, most themes have button styles, so breaking styles in themes should be minimal, but still is a concern.
I hesitate to change this in a point release, but lets definitely change it for 3.3
I totally understand. It's a big, small change. :smile:
I have added a button wrapper inside the span element in #1409 because most themes explicitly target the span element. To make it behave I have reset all styles. @mtomas7 , @davidakennedy can you please review and test it, or perhaps ping someone who will? Thanks!
I can provide a test blog that runs on this branch if needed.
Hey @zinigor, I'd be happy to test this. A test blog would be great.
I think this is the right approach, and it's similar to the one we talked about internally on the Automattic Theme team. Having a button inside the span is valid HTML, so we shouldn't have any huge issues.
One suggestion I would make is maybe adding a class name to the button. Something like: infinite-trigger. That would encourage developers to target the class name in the future, instead of specific elements. It would free us up too, since if we ever had to adjust the elements, we could still keep class names the same and keep breaking things to a minimum.
Whoops, looks like @samhotchkiss has merged this already. I have created a new issue to further improve the IS handle: #1523
Sorry to have kept you waiting @davidakennedy, but the good news is that you can test this on the master branch :smile: