Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit a25a7df

Browse files
Splaktarmmalerba
authored andcommitted
feat(autocomplete): add support for aria-describedby (#11405)
Fixes #11004
1 parent 2203eec commit a25a7df

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/components/autocomplete/demoBasicUsage/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<div ng-controller="DemoCtrl as ctrl" layout="column" ng-cloak>
22
<md-content class="md-padding">
33
<form ng-submit="$event.preventDefault()">
4-
<p>Use <code>md-autocomplete</code> to search for matches from local or remote data sources.</p>
4+
<p id="autocompleteDescription">
5+
Use <code>md-autocomplete</code> to search for matches from local or remote data sources.
6+
</p>
57
<md-autocomplete
68
ng-disabled="ctrl.isDisabled"
79
md-no-cache="ctrl.noCache"
@@ -12,7 +14,8 @@
1214
md-items="item in ctrl.querySearch(ctrl.searchText)"
1315
md-item-text="item.display"
1416
md-min-length="0"
15-
placeholder="What is your favorite US state?">
17+
placeholder="What is your favorite US state?"
18+
aria-describedby="autocompleteDescription autocompleteDetailedDescription">
1619
<md-item-template>
1720
<span md-highlight-text="ctrl.searchText" md-highlight-flags="^i">{{item.display}}</span>
1821
</md-item-template>
@@ -25,7 +28,7 @@
2528
<md-checkbox ng-model="ctrl.simulateQuery">Simulate query for results?</md-checkbox>
2629
<md-checkbox ng-model="ctrl.noCache">Disable caching of queries?</md-checkbox>
2730
<md-checkbox ng-model="ctrl.isDisabled">Disable the input?</md-checkbox>
28-
<p>
31+
<p id="autocompleteDetailedDescription">
2932
By default, <code>md-autocomplete</code> will cache results when performing a query.
3033
After the initial call is performed, it will use the cached results to eliminate unnecessary
3134
server requests or lookup logic. This can be disabled above.

src/components/autocomplete/demoFloatingLabel/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<p>The following example demonstrates floating labels being used as a normal form element.</p>
55
<div layout-gt-sm="row">
66
<md-input-container flex>
7-
<label>Name</label>
8-
<input type="text"/>
7+
<label for="floatingLabelName">Name</label>
8+
<input id="floatingLabelName" type="text"/>
99
</md-input-container>
1010
<md-autocomplete flex required
1111
md-input-name="autocompleteField"
@@ -17,7 +17,8 @@
1717
md-items="item in ctrl.querySearch(ctrl.searchText)"
1818
md-item-text="item.display"
1919
md-require-match=""
20-
md-floating-label="Favorite state">
20+
md-floating-label="Favorite state"
21+
aria-describedby="favoriteStateDescription">
2122
<md-item-template>
2223
<span md-highlight-text="ctrl.searchText">{{item.display}}</span>
2324
</md-item-template>
@@ -28,6 +29,9 @@
2829
<div ng-message="maxlength">Your entry is too long.</div>
2930
</div>
3031
</md-autocomplete>
32+
<p id="favoriteStateDescription" hide>
33+
A person's favorite state tells you a lot about them
34+
</p>
3135
</div>
3236
</form>
3337
</md-content>

src/components/autocomplete/js/autocompleteController.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
9393
if ($scope.autofocus) {
9494
$element.on('focus', focusInputElement);
9595
}
96+
if ($scope.ariaDescribedBy) {
97+
elements.input.setAttribute('aria-describedby', $scope.ariaDescribedBy);
98+
}
9699
});
97100
}
98101

src/components/autocomplete/js/autocompleteDirective.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ angular
130130
* as much as possible.
131131
* @param {string=} md-dropdown-position Overrides the default dropdown position. Options: `top`,
132132
* `bottom`.
133+
* @param {string=} aria-describedby A space-separated list of element IDs. This should contain the
134+
* IDs of any elements that describe this autocomplete. Screen readers will read the content of
135+
* these elements at the end of announcing that the autocomplete has been selected and
136+
* describing its current state. The descriptive elements do not need to be visible on the page.
133137
* @param {string=} md-selected-message Attribute to specify the text that the screen reader will
134138
* announce after a value is selected. Default is: "selected". If `Alaska` is selected in the
135139
* options panel, it will read "Alaska selected". You will want to override this when your app
@@ -259,6 +263,7 @@ function MdAutocomplete ($$mdSvgRegistry) {
259263
itemsExpr: '@mdItems',
260264
itemText: '&mdItemText',
261265
placeholder: '@placeholder',
266+
ariaDescribedBy: '@?ariaDescribedby',
262267
noCache: '=?mdNoCache',
263268
requireMatch: '=?mdRequireMatch',
264269
selectOnMatch: '=?mdSelectOnMatch',

0 commit comments

Comments
 (0)