I’m not able to access the close image button through keyboard even I’ve added tabindex=0
in <img src= "close img link" tabindex="0" alt= "close" title="close" aria-labelledby="close" />
It is just getting Focus through keyboard but it not able to close by space and enter button on keyboard
2
Answers
Your image is just that, an image.
To be a interactive area, you need to change it into one, e.g. a button (
<button type="image"
>) or a link, or you need to capture the keyboard events with JavaScriptI assume because you have used an
aria-
attribute, as well as been able to close with space, your also wanting to make accessible.I’m no accessibility expert here, but I believe the trick here is to place the image inside a button.
The button is then automatically accessible, you can then add
aria-label
to indicate the button is a close button.Because the
img
has no meaning for accessibility, you can then also mark this witharia-hidden="true"
Below is a working snippet, I’ve used an inline SVG, but using an IMG will be the same.