I am doing Accessibility testing for an Angular project at work. We use JAWS screen reader. We also use a plugin that identifies issues in the UI and reports them as violations. I am getting one for dropdowns that I'm not able to resolve. It is Accessible name does not match or contain the visible label text
.
The code I have for the dropdown is:
<select *ngIf="!viewMode" formControlName="group" placeholder="select" id="group" data-placement="right">
<option value="" [selected]>Select</option>
<option attr.aria-label="{{group.title}}" *ngFor="let group of records"
[ngValue]="group" data-placement="right" data-toggle="tooltip" title="{{group.title}}">
{{group.title | slice:0:30}}
<span *ngIf="group.title.length > 30">...</span>
</option>
</select>
We truncate the text of group.title
and add ellipses ...
if the entire title doesn't fit the fixed width of dropdown. The aria-label
however always has the full title assigned.
Eg. if we have title as Psychology
, maximum characters that we display are 6. Then dropdown will show Psycho...
but the aria-label will stil be `Psychology.
My issue is that whenever the displayed title gets truncated I get a violation as title doesn't match the aria-label
. If I remove the aria-label
the screen reader only reads what is displayed, so it ends up reading the ellipses as dot dot dot
which we don't want. I tried to use a hidden label instead on aria-label inside the option
tag but that didn't work. Can anyone help me with a workaround??
aria
(BAD idea) there is very little you can do here,<selects>
are basic components that convert anything within<option>
into plain text. Also<option>
does not work witharia-label
as far as I am aware, very surprised thattitle
appears to work, but is not really appropriate. Best advice, just leave the...
- it is understood by screen reader users to be a truncated sentence the same as everyone else and if "sighted" users dont need the whole info neither do users who rely on a screen reader. – Graham Ritchie<select>
, don't truncate at all, redesign the form to allow all text to be visible. – Graham Ritchie<select>
d are hard to do much with I am afraid. If you are able to persuade them it is important for usability that the form itself is redesigned to reduce the need for truncating that is your best route as I said, plus it is waaaay easier to get something like that approved than trying to get a stylistic change approved i would have thought! Sorry to be the bringer of bad news but I have had similar conversations about<select>
and visually hidden text / labels in the past, form redesign was always the way we went due to the limitations. – Graham Ritchie