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

feat(accordion): support spacebar to toggle group #4319

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
6 changes: 4 additions & 2 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
}
});

scope.toggleOpen = function() {
scope.toggleOpen = function($event) {
if (!scope.isDisabled) {
scope.isOpen = !scope.isOpen;
if (!$event || $event.which === 32) {
scope.isOpen = !scope.isOpen;
}
}
};
}
Expand Down
16 changes: 16 additions & 0 deletions src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ describe('accordion', function() {
scope.$digest();
expect(group).not.toHaveClass('panel-open');
});

it('should toggle element on spacebar when focused', function() {
var group = groups.eq(0);
findGroupLink(0)[0].focus();
var e = $.Event('keypress');
e.which = 32;
findGroupLink(0).trigger(e);

expect(group).toHaveClass('panel-open');

e = $.Event('keypress');
e.which = 32;
findGroupLink(0).trigger(e);

expect(group).not.toHaveClass('panel-open');
});
});

describe('with open-class attribute', function() {
Expand Down
2 changes: 1 addition & 1 deletion template/accordion/accordion-group.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="panel {{panelClass || 'panel-default'}}">
<div class="panel-heading">
<div class="panel-heading" ng-keypress="toggleOpen($event)">
<h4 class="panel-title">
<a href tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" accordion-transclude="heading"><span ng-class="{'text-muted': isDisabled}">{{heading}}</span></a>
</h4>
Expand Down