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

Improved accessibility of collapse #3920

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/collapse/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ angular.module('ui.bootstrap.collapse', [])
return {
link: function (scope, element, attrs) {
function expand() {
element.removeClass('collapse').addClass('collapsing');
element.removeClass('collapse')
.addClass('collapsing')
.attr('aria-expanded', true)
.attr('aria-hidden', false);

$animate.addClass(element, 'in', {
to: { height: element[0].scrollHeight + 'px' }
}).then(expandDone);
Expand All @@ -25,7 +29,9 @@ angular.module('ui.bootstrap.collapse', [])
// initially all panel collapse have the collapse class, this removal
// prevents the animation from jumping to collapsed state
.removeClass('collapse')
.addClass('collapsing');
.addClass('collapsing')
.attr('aria-expanded', false)
.attr('aria-hidden', true);

$animate.removeClass(element, 'in', {
to: {height: '0'}
Expand Down
20 changes: 20 additions & 0 deletions src/collapse/test/collapse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ describe('collapse directive', function () {
expect(element.height()).toBe(0);
});

it('should change aria-expanded attribute', function() {
scope.isCollapsed = false;
scope.$digest();
expect(element.attr('aria-expanded')).toBe('true');

scope.isCollapsed = true;
scope.$digest();
expect(element.attr('aria-expanded')).toBe('false');
});

it('should change aria-hidden attribute', function() {
scope.isCollapsed = false;
scope.$digest();
expect(element.attr('aria-hidden')).toBe('false');

scope.isCollapsed = true;
scope.$digest();
expect(element.attr('aria-hidden')).toBe('true');
});

describe('dynamic content', function() {

var element;
Expand Down