Skip to content
This repository was 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 1 commit
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
5 changes: 5 additions & 0 deletions src/collapse/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ angular.module('ui.bootstrap.collapse', [])
link: function (scope, element, attrs) {
function expand() {
element.removeClass('collapse').addClass('collapsing');
element.attr('aria-expanded', true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just chain on the element actions instead of typing element again.

element.attr('aria-hidden', false);

$animate.addClass(element, 'in', {
to: { height: element[0].scrollHeight + 'px' }
}).then(expandDone);
Expand All @@ -26,6 +29,8 @@ angular.module('ui.bootstrap.collapse', [])
// prevents the animation from jumping to collapsed state
.removeClass('collapse')
.addClass('collapsing');
element.attr('aria-expanded', false);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can chain on the other calls to element right after .addClass(...) instead of calling it again

element.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