Re:Reddit's Recently Announced API Changes, and the future o...
by extra88 on Sunday June 11, 2023 @11:46PM
(#36288230)
No, your first code snippet is totally fine. The button's name comes from its descendent elements by default. In this case, the `alt` attribute of the image provides the name.
Sara is good source for accessibility information but I think you've misinterpreted that post. If an icon button uses an `img`, making the image's `alt` the name of the button works well. If the button's icon comes from an inline SVG, background image, or icon font, I recommend Sara's first technique, visually hidden text within the `button`; names from text nodes are more robust than from attributes (`alt` being an exception, in part because it has been around far longer).
However a button that looks like this:
Is not. Screen readers will read the simple text on the button, but any descendants of the button will be considered purely presentational (even if as in the example above the img tag includes an 'alt' attribute, it won't be read).Modern screen readers will now often parse text content out of the button even if there are descendants, but this behaviour is not reliable or according to spec.
To fix:
There are other techniques as well such as using CSS to hide text (not with 'display: none' though, which also hides from screen readers, meaning this often feels a bit hacky) or using a hidden element with text content and aria-labelledby to reference the element's ID.This is a pretty good walk through: https://www.sarasoueidan.com/blog/accessible-icon-buttons/#a...