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

Commit aa5a991

Browse files
committed
feat(accordion): support spacebar to toggle group
- Allow spacebar to toggle the accordion group Closes #4319 Resolves #4249
1 parent 9b2f7ac commit aa5a991

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/accordion/accordion.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
8888
}
8989
});
9090

91-
scope.toggleOpen = function() {
91+
scope.toggleOpen = function($event) {
9292
if (!scope.isDisabled) {
93-
scope.isOpen = !scope.isOpen;
93+
if (!$event || $event.which === 32) {
94+
scope.isOpen = !scope.isOpen;
95+
}
9496
}
9597
};
9698
}

src/accordion/test/accordion.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,22 @@ describe('accordion', function() {
222222
scope.$digest();
223223
expect(group).not.toHaveClass('panel-open');
224224
});
225+
226+
it('should toggle element on spacebar when focused', function() {
227+
var group = groups.eq(0);
228+
findGroupLink(0)[0].focus();
229+
var e = $.Event('keypress');
230+
e.which = 32;
231+
findGroupLink(0).trigger(e);
232+
233+
expect(group).toHaveClass('panel-open');
234+
235+
e = $.Event('keypress');
236+
e.which = 32;
237+
findGroupLink(0).trigger(e);
238+
239+
expect(group).not.toHaveClass('panel-open');
240+
});
225241
});
226242

227243
describe('with open-class attribute', function() {

template/accordion/accordion-group.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="panel {{panelClass || 'panel-default'}}">
2-
<div class="panel-heading">
2+
<div class="panel-heading" ng-keypress="toggleOpen($event)">
33
<h4 class="panel-title">
44
<a href tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" accordion-transclude="heading"><span ng-class="{'text-muted': isDisabled}">{{heading}}</span></a>
55
</h4>

0 commit comments

Comments
 (0)