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

Commit 9255134

Browse files
Ricardo Fariawesleycho
Ricardo Faria
authored andcommittedJul 17, 2015
feat(collapse): add accessibility support
- Add addition of appropriate `aria-` attributes for representation of states for the collapse component Closes #3920
1 parent ede9ea4 commit 9255134

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

Diff for: ‎src/collapse/collapse.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ angular.module('ui.bootstrap.collapse', [])
55
return {
66
link: function (scope, element, attrs) {
77
function expand() {
8-
element.removeClass('collapse').addClass('collapsing');
8+
element.removeClass('collapse')
9+
.addClass('collapsing')
10+
.attr('aria-expanded', true)
11+
.attr('aria-hidden', false);
12+
913
$animate.addClass(element, 'in', {
1014
to: { height: element[0].scrollHeight + 'px' }
1115
}).then(expandDone);
@@ -29,7 +33,9 @@ angular.module('ui.bootstrap.collapse', [])
2933
// initially all panel collapse have the collapse class, this removal
3034
// prevents the animation from jumping to collapsed state
3135
.removeClass('collapse')
32-
.addClass('collapsing');
36+
.addClass('collapsing')
37+
.attr('aria-expanded', false)
38+
.attr('aria-hidden', true);
3339

3440
$animate.removeClass(element, 'in', {
3541
to: {height: '0'}

Diff for: ‎src/collapse/test/collapse.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ describe('collapse directive', function () {
7070
expect(element.height()).toBe(0);
7171
});
7272

73+
it('should change aria-expanded attribute', function() {
74+
scope.isCollapsed = false;
75+
scope.$digest();
76+
expect(element.attr('aria-expanded')).toBe('true');
77+
78+
scope.isCollapsed = true;
79+
scope.$digest();
80+
expect(element.attr('aria-expanded')).toBe('false');
81+
});
82+
83+
it('should change aria-hidden attribute', function() {
84+
scope.isCollapsed = false;
85+
scope.$digest();
86+
expect(element.attr('aria-hidden')).toBe('false');
87+
88+
scope.isCollapsed = true;
89+
scope.$digest();
90+
expect(element.attr('aria-hidden')).toBe('true');
91+
});
92+
7393
describe('dynamic content', function() {
7494

7595
var element;

0 commit comments

Comments
 (0)
This repository has been archived.