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

Commit

Permalink
fix(accordion): add custom open class support
Browse files Browse the repository at this point in the history
- Add support for using custom class when accordion is opened

Closes #4198
  • Loading branch information
davious authored and wesleycho committed Aug 13, 2015
1 parent dccd619 commit 575eb85
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
link: function(scope, element, attrs, accordionCtrl) {
accordionCtrl.addGroup(scope);

scope.openClass = attrs.openClass || 'panel-open';
scope.$watch('isOpen', function(value) {
element.toggleClass(scope.openClass, value);
if (value) {
accordionCtrl.closeOthers(scope);
}
Expand Down
30 changes: 29 additions & 1 deletion src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('accordion', function() {
expect(findGroupBody(0).scope().isOpen).toBe(false);
});

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

describe('with open-class attribute', function() {
beforeEach(function() {
var tpl =
'<accordion>' +
'<accordion-group heading="title 1" open-class="custom-open-class">Content 1</accordion-group>' +
'<accordion-group heading="title 2" open-class="custom-open-class">Content 2</accordion-group>' +
'</accordion>';
element = angular.element(tpl);
$compile(element)(scope);
scope.$digest();
groups = element.find('.panel');
});
afterEach(function() {
element.remove();
});

it('should add custom-open-class when opened', function() {
var group = groups.eq(0);
findGroupLink(0).click();
scope.$digest();
expect(group).toHaveClass('custom-open-class');

findGroupLink(0).click();
scope.$digest();
expect(group).not.toHaveClass('custom-open-class');
});
});

describe('with dynamic panels', function() {
var model;
beforeEach(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,4 +1,4 @@
<div class="panel panel-default" ng-class="{'panel-open': isOpen}">
<div class="panel panel-default">
<div class="panel-heading">
<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>
Expand Down

0 comments on commit 575eb85

Please sign in to comment.