The Best Page The ajax-populated and -revealed element that exists with" /> The Best Page The ajax-populated and -revealed element that exists with" /> The Best Page The ajax-populated and -revealed element that exists with"/>

Prevent screen-readers / assistive tech from triggering click handler

313 Views Asked by At

I have this link:

<a href="/path/to/page" data-trigger="expedient-element">The Best Page</a>

The ajax-populated and -revealed element that exists within the current page is an "enhancement" and has aria-hidden="true". It would be preferable for screen-readers and assistive tech to follow the link's href to the subsequent static page, rather than triggering the click handler (especially since the element that it will acts on is already hidden, as previously mentioned).

Will this behavior already take place or do I need to add something?

1

There are 1 best solutions below

0
QuentinC On BEST ANSWER

When pressing enter on a link, it does the same as a click, and it's a very bad idea to intercept the enter key in order to do something different.

  • There are keyboard users, perfectly sighted, who aren't using screen reader. These users will experience an unexpected behavior.
  • Screen readers may choose to send directly a click event, rather than keyboard events, even though enter has been actually pressed. So idem in the opposite direction.
  • There may be other ways to activate a link, other than click or enter: spacebar, tap on touch screen, assistive techs to click by winking the eyes, etc. How it should behave in these cases ?

By the way, you can't do something different based on whether a screen reader is used or not, simply because you have no 100% reliable way to detect it.

The questions you should ask yourself are:

  • Why do you want a different behavior between click and enter ? or between screen reader and normal users ?
  • Are you trying to work around inaccessible content, or do you have two versions of the same content (an accessible and a unaccessible one) ? In that case, it would be much better to have a single content and make it accessible. Rare are the cases where it's really impossible, and experience shows that the two versions are eventually going to be out of sync, more quicker than you think.