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

Commit 575eb85

Browse files
daviouswesleycho
authored andcommitted
fix(accordion): add custom open class support
- Add support for using custom class when accordion is opened Closes #4198
1 parent dccd619 commit 575eb85

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/accordion/accordion.js

+2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
7979
link: function(scope, element, attrs, accordionCtrl) {
8080
accordionCtrl.addGroup(scope);
8181

82+
scope.openClass = attrs.openClass || 'panel-open';
8283
scope.$watch('isOpen', function(value) {
84+
element.toggleClass(scope.openClass, value);
8385
if (value) {
8486
accordionCtrl.closeOthers(scope);
8587
}

src/accordion/test/accordion.spec.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe('accordion', function() {
212212
expect(findGroupBody(0).scope().isOpen).toBe(false);
213213
});
214214

215-
it('should add "open" when opened', function() {
215+
it('should add, by default, "panel-open" when opened', function() {
216216
var group = groups.eq(0);
217217
findGroupLink(0).click();
218218
scope.$digest();
@@ -224,6 +224,34 @@ describe('accordion', function() {
224224
});
225225
});
226226

227+
describe('with open-class attribute', function() {
228+
beforeEach(function() {
229+
var tpl =
230+
'<accordion>' +
231+
'<accordion-group heading="title 1" open-class="custom-open-class">Content 1</accordion-group>' +
232+
'<accordion-group heading="title 2" open-class="custom-open-class">Content 2</accordion-group>' +
233+
'</accordion>';
234+
element = angular.element(tpl);
235+
$compile(element)(scope);
236+
scope.$digest();
237+
groups = element.find('.panel');
238+
});
239+
afterEach(function() {
240+
element.remove();
241+
});
242+
243+
it('should add custom-open-class when opened', function() {
244+
var group = groups.eq(0);
245+
findGroupLink(0).click();
246+
scope.$digest();
247+
expect(group).toHaveClass('custom-open-class');
248+
249+
findGroupLink(0).click();
250+
scope.$digest();
251+
expect(group).not.toHaveClass('custom-open-class');
252+
});
253+
});
254+
227255
describe('with dynamic panels', function() {
228256
var model;
229257
beforeEach(function() {

template/accordion/accordion-group.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="panel panel-default" ng-class="{'panel-open': isOpen}">
1+
<div class="panel panel-default">
22
<div class="panel-heading">
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>

0 commit comments

Comments
 (0)