autocomplete: results are not voiced with index information
Bug, enhancement request, or proposal:
The AngularJS Material Autocomplete component does not announce the index of results (e.g., "1 of 3") to screen readers.
Steps to reproduce the issue:
Issue can be reproduced on https://material.angularjs.org/HEAD/demo/autocomplete
Detailed Reproduction Steps:
- Turn on ChromeVox
- Go to https://material.angularjs.org/HEAD/demo/autocomplete
- Enter 'al' into the 'Favorite State' autocompleter and let the results load
- Use the keyboard's arrow keys to move focus to 'Alaska'
- Note that 'Alaska, Status' is voiced
What is the expected behavior?
- 'Alaska, List item, 2 of 2'
What is the current behavior?
- 'Alaska, Status'
What is the use-case or motivation for changing an existing behavior?
Accessibility. Screen reader users need to know how many items are loaded and what the current position of the focus is.
Which versions of AngularJS, Material, OS, and browsers are affected?
- AngularJS: 1.6
- AngularJS Material: 1.1.19
- OS: ChromeOS and GNU/Linux
- Browsers: Chrome
- Screen readers: ChromeVox, VoiceOver and JAWS
Is there anything else we should know? Stack Traces, Screenshots, etc.
Working examples:
The desired behavior can be observed in the Angular Material library. See the demos at https://material.angular.io/components/autocomplete/examples
It can also be observed in the w3.org examples, such as https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.0pattern/combobox-autocomplete-both.html
The reading of "Status" is discussed in some detail in https://github.com/angular/material/issues/11569 and https://github.com/angular/material/issues/10896. The TL;DR is that this was improved in Chrome OS 70 and the remaining "Status" announcements are by design in ChromeVox.
Angular Material uses the following approach:
Combobox
<input aria-label="State"
class="mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-valid ng-touched"
matinput placeholder="State" autocomplete="off" role="combobox" aria-autocomplete="list"
aria-expanded="true" aria-haspopup="true" id="mat-input-0" aria-invalid="false"
aria-required="false" aria-owns="mat-autocomplete-0"
aria-activedescendant="mat-option-79">
Listbox panel
<div class="mat-autocomplete-panel mat-autocomplete-visible" role="listbox"
id="mat-autocomplete-0">
<mat-option class="mat-option" role="option" tabindex="0" id="mat-option-0"
aria-disabled="false">
<span class="mat-option-text">
<span>Arkansas</span> | <small>Population: 2.978M</small>
</span>
</mat-option>
<mat-option class="mat-option" role="option" tabindex="0" id="mat-option-1"
aria-disabled="false">
<span class="mat-option-text">
<span>California</span> | <small>Population: 39.14M</small>
</span>
</mat-option>
</div>
AngularJS Material uses the following approach:
Combobox
<input type="search" id="input-63" ng-class="::inputClass" ng-if="!floatingLabel"
autocomplete="off" ng-required="$mdAutocompleteCtrl.isRequired"
ng-disabled="$mdAutocompleteCtrl.isDisabled" ng-readonly="$mdAutocompleteCtrl.isReadonly"
ng-model="$mdAutocompleteCtrl.scope.searchText"
ng-keydown="$mdAutocompleteCtrl.keydown($event)" ng-blur="$mdAutocompleteCtrl.blur($event)"
ng-focus="$mdAutocompleteCtrl.focus($event)" placeholder="Ex. Alaska" aria-label="Ex. Alaska"
aria-autocomplete="list" role="combobox" aria-haspopup="true" aria-expanded="true"
aria-owns="ul-63"
ng-attr-aria-activedescendant="{{$mdAutocompleteCtrl.index >= 0 ? 'selected_option' : undefined}}"
class="ng-pristine ng-valid ng-scope ng-empty ng-valid-required ng-valid-minlength ng-valid-maxlength ng-touched"
aria-invalid="false" aria-describedby="autocompleteDetailedDescription"
aria-labelledby="favoriteStateLabel">
Listbox Panel
<ul class="md-autocomplete-suggestions" ng-class="::menuClass" id="ul-63"
ng-mouseenter="$mdAutocompleteCtrl.listEnter()" ng-mouseleave="$mdAutocompleteCtrl.listLeave()"
ng-mouseup="$mdAutocompleteCtrl.mouseUp()" role="listbox">
<li md-virtual-repeat="item in $mdAutocompleteCtrl.matches"
ng-class="{ selected: $index === $mdAutocompleteCtrl.index }"
ng-attr-id="{{$index === $mdAutocompleteCtrl.index ? 'selected_option' : undefined}}"
ng-click="$mdAutocompleteCtrl.select($index)" role="option" aria-setsize="50"
aria-posinset="1" aria-selected="false" md-extra-name="$mdAutocompleteCtrl.itemName"
class="ng-scope" tabindex="0">
<md-autocomplete-parent-scope md-autocomplete-replace class="ng-scope">
<span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">Alabama</span>
</md-autocomplete-parent-scope>
</li>
<li md-virtual-repeat="item in $mdAutocompleteCtrl.matches"
ng-class="{ selected: $index === $mdAutocompleteCtrl.index }"
ng-attr-id="{{$index === $mdAutocompleteCtrl.index ? 'selected_option' : undefined}}"
ng-click="$mdAutocompleteCtrl.select($index)" role="option" aria-setsize="50"
aria-posinset="2" aria-selected="false" md-extra-name="$mdAutocompleteCtrl.itemName"
class="ng-scope" tabindex="0">
<md-autocomplete-parent-scope md-autocomplete-replace class="ng-scope">
<span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">Alaska</span>
</md-autocomplete-parent-scope>
</li>
</ul>
Reducing this down to just the attributes which affect a11y...
Angular Material uses the following approach:
Combobox
<input aria-label="State" placeholder="State" autocomplete="off" role="combobox"
aria-autocomplete="list" aria-expanded="true" aria-haspopup="true" id="mat-input-0"
aria-invalid="false" aria-required="false" aria-owns="mat-autocomplete-0"
aria-activedescendant="mat-option-79">
Listbox panel
<div role="listbox" id="mat-autocomplete-0">
<mat-option role="option" tabindex="0" id="mat-option-0" aria-disabled="false">
<span>Arkansas</span>
</mat-option>
<mat-option role="option" tabindex="0" id="mat-option-1" aria-disabled="false">
<span>California</span>
</mat-option>
</div>
AngularJS Material uses the following approach:
Combobox
<input type="search" id="input-63" autocomplete="off" ng-required="$mdAutocompleteCtrl.isRequired"
ng-disabled="$mdAutocompleteCtrl.isDisabled" ng-readonly="$mdAutocompleteCtrl.isReadonly"
placeholder="Ex. Alaska" aria-label="Ex. Alaska" aria-autocomplete="list"
role="combobox" aria-haspopup="true" aria-expanded="true" aria-owns="ul-63"
ng-attr-aria-activedescendant="{{$mdAutocompleteCtrl.index >= 0 ? 'selected_option' : undefined}}"
aria-invalid="false" aria-describedby="autocompleteDetailedDescription"
aria-labelledby="favoriteStateLabel">
Listbox Panel
<ul id="ul-63" role="listbox">
<li ng-attr-id="{{$index === $mdAutocompleteCtrl.index ? 'selected_option' : undefined}}"
role="option" aria-setsize="50" aria-posinset="1" aria-selected="false" tabindex="0">
<span>Alabama</span>
</li>
<li ng-attr-id="{{$index === $mdAutocompleteCtrl.index ? 'selected_option' : undefined}}"
role="option" aria-setsize="50" aria-posinset="2" aria-selected="false" tabindex="0">
<span>Alaska</span>
</li>
</ul>
Overall the designs are very similar now (after significant improvements to AngularJS Material over the last year) and align with the ARIA 1.0 spec. Both use aria-autocomplete="list" instead of aria-autocomplete="both" mentioned in the OP.
The inputs with combobox roles and listboxes are almost equivalent. The primary difference is that Angular Material does not define a type and AngularJS Material defines the type="search" which can give an X icon to clear behavior, but we implement our own version of this for more consistent cross browser support. Both of the examples explicitly call out input type="text".
This article also calls out input type="text" as better for accessibility. This slide deck also discusses this around slide 100.
The AngularJS Material options provide quite a bit more information to screen readers than what the Angular Material options provide. This includes aria-setsize="50" aria-posinset="2" aria-selected="false".
I'm not able to reproduce anything described in the OP with VoiceOver for macOS as index or posinset are not announced for AngularJS Material, Angular Material, or WAI-ARIA 1.0 autocomplete lists.
I'm going to test on ChromeVox next...
OK, I can reproduce this on ChromeVox. AngularJS Material does announce the following for the first item selected in the listbox
Alabama List Item 1 of 50 ... List box with 8 items Alabama Status However, when the second item is selected, it only announces Alaska Status
For Angular Material, it announces the following for the first item selected
Arkansas List Item 1 of 4 ... List box with 4 items When the second item is selected, it announces California List item 2 of 4 ... List box with 4 items
Attempts to solve this
- ~~Use
input type="text"~~ - ~~Remove
aria-setsize="50" aria-posinset="2"from options~~ - ~~Give every option an
id~~ - [x] Give every option an
idand remove announcements of selection changed
I think that we're getting this behavior because the md-autocomplete controller explicitly announces the label for the current selection, and in ChromeVox this would take precedence over other aria metadata announcements.
See https://github.com/angular/material/blob/41c9d00dbb3cd85a31c3a02693854f25b2f7a8df/src/components/autocomplete/js/autocompleteController.js#L545
@mkowalchuk that was a good idea, but I didn't have any luck with it. Removing that results in nothing being announced when using the up/down keys.
I think that the cause of that is something deeper... Angular Material moves visual focus to each list item as the up/down keys are pressed.
AngularJS Material leaves the DOM focus and visual focus on the input (which has the keydown listener) and only changes the styles of the list items to show what is selected. It looks like this is due to our aria-activedescendant implementation not being robust enough. A proper aria-activedescendant implementation should cause the visual focus to move.
I've pushed up a branch which solves this and makes some other a11y improvements. I still need to
- [x] Write some unit tests