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

Commit 22ebd23

Browse files
bekospkozlowski-opensource
authored andcommitted
feat(dropdown): add WAI-ARIA attributes
* Add `aria-haspopup` and `and aria-expanded` attributes to dropdown toggle. * Dynamically change `aria-expanded` when the dropdown closes or opens. Closes #1733
1 parent 794954a commit 22ebd23

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/dropdown/docs/demo.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<div ng-controller="DropdownCtrl">
33
<!-- Simple dropdown -->
44
<span class="dropdown" on-toggle="toggled(open)">
5-
<a class="dropdown-toggle">
5+
<a href class="dropdown-toggle">
66
Click me for a dropdown, yo!
77
</a>
88
<ul class="dropdown-menu">
99
<li ng-repeat="choice in items">
10-
<a>{{choice}}</a>
10+
<a href>{{choice}}</a>
1111
</li>
1212
</ul>
1313
</span>

src/dropdown/dropdown.js

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ angular.module('ui.bootstrap.dropdown', [])
5353
return $scope.isOpen = arguments.length ? !!open : !$scope.isOpen;
5454
};
5555

56+
// Allow other directives to watch status
57+
this.isOpen = function() {
58+
return $scope.isOpen;
59+
};
60+
5661
$scope.$watch('isOpen', function( value ) {
5762
self.$element.toggleClass( openClass, value );
5863

@@ -103,6 +108,12 @@ angular.module('ui.bootstrap.dropdown', [])
103108
});
104109
}
105110
});
111+
112+
// WAI-ARIA
113+
element.attr({ 'aria-haspopup': true, 'aria-expanded': false });
114+
scope.$watch(dropdownCtrl.isOpen, function( isOpen ) {
115+
element.attr('aria-expanded', !!isOpen);
116+
});
106117
}
107118
};
108119
});

src/dropdown/test/dropdown.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ describe('dropdownToggle', function() {
106106
checkboxEl.click();
107107
expect($rootScope.clicked).toBeTruthy();
108108
});
109+
110+
// WAI-ARIA
111+
it('should aria markup to the `dropdown-toggle`', function() {
112+
var toggleEl = element.find('a');
113+
expect(toggleEl.attr('aria-haspopup')).toBe('true');
114+
expect(toggleEl.attr('aria-expanded')).toBe('false');
115+
116+
clickDropdownToggle();
117+
expect(toggleEl.attr('aria-expanded')).toBe('true');
118+
clickDropdownToggle();
119+
expect(toggleEl.attr('aria-expanded')).toBe('false');
120+
});
109121
});
110122

111123
describe('without trigger', function() {

0 commit comments

Comments
 (0)