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

Commit

Permalink
feat(typeahead): add WAI-ARIA markup
Browse files Browse the repository at this point in the history
Closes #1814
  • Loading branch information
bekos authored and pkozlowski-opensource committed Feb 22, 2014
1 parent d19b4c0 commit 5ca23e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Expand Up @@ -130,11 +130,16 @@ describe('typeahead tests', function () {

it('should open and close typeahead based on matches', function () {
var element = prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue"></div>');
var inputEl = findInput(element);
expect(inputEl.attr('aria-expanded')).toBe('false');

changeInputValueTo(element, 'ba');
expect(element).toBeOpenWithActive(2, 0);
expect(inputEl.attr('aria-expanded')).toBe('true');

changeInputValueTo(element, '');
expect(element).toBeClosed();
expect(inputEl.attr('aria-expanded')).toBe('false');
});

it('should not open typeahead if input value smaller than a defined threshold', function () {
Expand Down
8 changes: 8 additions & 0 deletions src/typeahead/typeahead.js
Expand Up @@ -69,6 +69,12 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

var hasFocus;

// WAI-ARIA
element.attr({
'aria-autocomplete': 'list',
'aria-expanded': false
});

//pop-up element used to display matches
var popUpEl = angular.element('<div typeahead-popup></div>');
popUpEl.attr({
Expand All @@ -93,6 +99,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
var resetMatches = function() {
scope.matches = [];
scope.activeIdx = -1;
element.attr('aria-expanded', false);
};

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

element.attr('aria-expanded', true);
} else {
resetMatches();
}
Expand Down
4 changes: 2 additions & 2 deletions template/typeahead/typeahead-popup.html
@@ -1,5 +1,5 @@
<ul class="dropdown-menu" ng-if="isOpen()" ng-style="{top: position.top+'px', left: position.left+'px'}" style="display: block;">
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">
<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()}}">
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option">
<div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
</li>
</ul>

1 comment on commit 5ca23e9

@ElvisYang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bekos I see there is ng-if="isOpen()", why still need aria-hidden="{{!isOpen()}}" here?

Please sign in to comment.