Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 5ca23e9

Browse files
bekospkozlowski-opensource
authored andcommitted
feat(typeahead): add WAI-ARIA markup
Closes #1814
1 parent d19b4c0 commit 5ca23e9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/typeahead/test/typeahead.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,16 @@ describe('typeahead tests', function () {
130130

131131
it('should open and close typeahead based on matches', function () {
132132
var element = prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue"></div>');
133+
var inputEl = findInput(element);
134+
expect(inputEl.attr('aria-expanded')).toBe('false');
135+
133136
changeInputValueTo(element, 'ba');
134137
expect(element).toBeOpenWithActive(2, 0);
138+
expect(inputEl.attr('aria-expanded')).toBe('true');
135139

136140
changeInputValueTo(element, '');
137141
expect(element).toBeClosed();
142+
expect(inputEl.attr('aria-expanded')).toBe('false');
138143
});
139144

140145
it('should not open typeahead if input value smaller than a defined threshold', function () {

src/typeahead/typeahead.js

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
6969

7070
var hasFocus;
7171

72+
// WAI-ARIA
73+
element.attr({
74+
'aria-autocomplete': 'list',
75+
'aria-expanded': false
76+
});
77+
7278
//pop-up element used to display matches
7379
var popUpEl = angular.element('<div typeahead-popup></div>');
7480
popUpEl.attr({
@@ -93,6 +99,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
9399
var resetMatches = function() {
94100
scope.matches = [];
95101
scope.activeIdx = -1;
102+
element.attr('aria-expanded', false);
96103
};
97104

98105
var getMatchesAsync = function(inputValue) {
@@ -125,6 +132,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
125132
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
126133
scope.position.top = scope.position.top + element.prop('offsetHeight');
127134

135+
element.attr('aria-expanded', true);
128136
} else {
129137
resetMatches();
130138
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<ul class="dropdown-menu" ng-if="isOpen()" ng-style="{top: position.top+'px', left: position.left+'px'}" style="display: block;">
2-
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">
1+
<ul class="dropdown-menu" ng-if="isOpen()" ng-style="{top: position.top+'px', left: position.left+'px'}" style="display: block;" role="listbox" aria-hidden="{{!isOpen()}}">
2+
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option">
33
<div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
44
</li>
55
</ul>

0 commit comments

Comments
 (0)