94 points · by gmcharlt · 4y ago · 71 comments
Also, maybe I am too jaded by working at orgs that don't care about a11y, but any indication that any amount of thought has been put into a11y issues is the opposite of a code smell to me.
Note: aria-label is intended for use on interactive elements, or elements made to be interactive via other ARIA declarations, when there is no appropriate text visible in the DOM that could be referenced as a label
https://developer.mozilla.org/en-US/docs/Web/Accessibility/A...
You can actually reduce accessibility by misusing aria attributes. Folks should try to use semantic elements first. Then if those aren't meeting their needs (please try to make them meet your needs), there are good, well tested implementations of the common aria patterns (https://www.w3.org/WAI/ARIA/apg/patterns/) for frameworks like react. Some examples of this are radix and ariakit.
You're absolutely right but that's mainly just because the bar is so low.
Ultimately it does seem like code smell to me. Insofar as it indicates you're doing something toward a11y, it's what I'd call a "good problem" (the type you only encounter when things are going in the right direction), but it seems a good indicator that a11y is being applied as an addon process (where a functional product goes through a11y review before iterating) rather than an intrinsic consideration at the architecting stage.
https://www.w3.org/TR/using-aria/#practical-support-aria-lab...
"In the cases where DOM content or a tooltip is undesirable, authors MAY set the accessible name of the element using aria-label, if the element does not prohibit use of the attribute. [...] Authors MUST NOT specify aria-label on an element which has an explicit or implicit WAI-ARIA role where aria-label is prohibited."[2]
[1] This is WAI-ARIA 1.2 (and not 1.1): https://www.w3.org/TR/wai-aria-1.2/#aria-label
I am particularly concerned if people interpret the parent article to mean that aria-label shouldn't be used on certain semantic containers that are exposed in the accessibility tree by screen readers, such as <section> and <nav>.
The article also mentions that it's explicitly disallowed on a bunch of elements in point #5 [1]. I know that I've used an aria-label on a <time> element in the past because the actual order of the contents of the element in there was kinda funky due to the visual presentation, so it felt like it would make sense to have a more sensible description in an aria-label. I wonder what the problem with that would've been, had browsers not discarded it?
I suspect this could be at least partly responsible for the overuse of aria-label. An element can be implemented using "<img aria-label='avatar' src='user.jpg' />" and then tested using "getByRole('img', { name: 'avatar' })". This is technically wrong because getByAltText would be preferable, but it works and it's easy so devs do it.
I'd say the ideal scenario is conveying the information that the image conveys. If there is no new information in the image (for example, it might be redundant with the username next to it), it's better to explicitly add an empty alt tag, as far as I'm aware.
Rule of thumb: if someone read the page out to you, would you prefer if they read that alt tag you are thinking of adding or not?
I've seen links marked with `role=button` for no reason and generally roles added when one is implied (role=link is implied on anchors for example).
If aria attributes are treated as "private/testing API", then one wouldn't be surprised when the value only makes sense to bots and not humans.
In my experience with medium side components it would take seconds to find the element vs a few milliseconds for getByTestId.
It's always annoying when an article begins with a strained attempt to redefine well known terms.
THIS article defines "code smell" exactly as you did. And it says that using aria-* incorrectly is not a smell, but an error, exactly as you did.
The claim of the article is that using aria-* at all is a code smell, in exactly the sense you said. They list a number of possible problems, and suggest alternatives. They're not saying that using area-* cannot be correct, just that it's so often incorrect as to be a smell.
But do to accessibility correctly you almost ALWAYS need to use aria-*
So it this is just like saying "writing code is a code smell because you'll have bugs" and it turns "code smell" into a useless tautology.
What? No... Screen readers do best with standard elements and you're supposed to avoid aria labels where possible, and only as a last resort.
This sounds about right for the current state of attention paid to assistive technology. Which is to say, it's an afterthought at best. Buying or installing some half-baked framework which attempts to use it correctly without even determining if it's correct or not and calling it good seems about as far as anyone will take it. One could make an analogy with left-pad: easy to use, but turns out it does the wrong thing for several cases.
To correctly implement accessibility on a website can require a fair amount of redoing components so they are properly accessible.
To really test yourself, once you have learnt the basics of using voiceover and narrator, turn off your monitor and navigate your website :)
In my limited experience, many people use one of those two options (the situation in Linux is unfortunately much less functional).
Yes, that's not enough for properly evaluating the performance of what you're working on (screen readers differ far more than browsers do, and there's many different ways of navigating), but it helps form a mental model and to quickly encouter really egregious issues that e.g. make your entire project inaccessible with any screen reader.
[1] I think I used this one, to learn the general principles and to at least find the terms needed to find the shortcuts for my operating system: https://www.youtube.com/watch?v=5R-6WvAihms
Consider making a habit of using it when you are circumstantially visually disabled: in bright sunlight, while you can't be physically present at the phone (eg while doing dishes or folding laundry), etc.
I don't know what platform you're on, but I use VoiceOver on Mac. My blind relative uses JAWS on Windows.
> In my experience, the term code smell usually has a negative connotation when someone mentions it.
> It’s a lot like a noticeable smell emanating from the office refrigerator. Ideally it’s some delicious homemade kimchi someone brought in, but more often than not it’s something like some forgotten fish sticks rotting in the back.
> smells don't always indicate a problem
That's a poorly coined term then, if you're having to immediately clarify that it doesn't mean what its common meaning indicates.
"According to Martin Fowler, code smells are not problematic on their own. They are warning signals that there might be a real problem in the code. For example, long functions are considered a code smell, but not all long functions are necessarily bad or poorly designed. Fowler suggests that junior members of a development team identify code smells and review them together with senior members, who can evaluate if there is really a deeper problem in the code."
https://www.sealights.io/code-quality/the-problem-of-code-sm...
And the first google result, which is Martin Fowler's own website:
"The second is that smells don't always indicate a problem. Some long methods are just fine. You have to look deeper to see if there is an underlying problem there - smells aren't inherently bad on their own - they are often an indicator of a problem rather than the problem themselves."
Wiki says Kent Beck, see https://en.wikipedia.org/wiki/Code_smell
I don't understand how this could be a code smell.
This ignores aria-role, which allows you to set any element (such as a div) as interactive.
https://accessibilityinsights.io/info-examples/web/aria-role...
I have now pain in my finger scrolling so much to try to see what is the point. Also a lot of useless speech and I have not reached the point of why aria label is code smell before giving up...
The main point was that they often see it used to label non-interactive elements, when it should only be used for interactive elements. It's a useful point to make, but that's not a code smell, that's faulty code.
The author should have chosen a better title, e.g. "Think twice before using aria-label".
This was the problem, rather than the font size. Lede buried under 2000 words of generic intro