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

Commit

Permalink
fix(accordion): ensure panelOpen class is present
Browse files Browse the repository at this point in the history
- Ensure panelOpen class is present on initialization of panel

Closes #4849
Closes #4870
  • Loading branch information
chenyuzhcy authored and wesleycho committed Nov 10, 2015
1 parent 44820a0 commit 0917623
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
accordionCtrl.addGroup(scope);

scope.openClass = attrs.openClass || 'panel-open';
scope.panelClass = attrs.panelClass;
scope.panelClass = attrs.panelClass || 'panel-default';
scope.$watch('isOpen', function(value) {
element.toggleClass(scope.openClass, !!value);
if (value) {
Expand Down
23 changes: 23 additions & 0 deletions src/accordion/test/accordion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,29 @@ describe('uib-accordion', function() {
});
});

describe('is-open attribute with custom class', function() {
beforeEach(function() {
var tpl =
'<uib-accordion>' +
'<uib-accordion-group ng-repeat="group in groups" heading="{{group.name}}" is-open="group.open" class="testClass">{{group.content}}</uib-accordion-group>' +
'</uib-accordion>';
element = angular.element(tpl);
scope.groups = [
{name: 'title 1', content: 'Content 1', open: false},
{name: 'title 2', content: 'Content 2', open: true}
];
$compile(element)(scope);
scope.$digest();

groups = element.find('.panel');
});

it('should add "panel-open" class', function(){
expect(groups.eq(0)).not.toHaveClass('panel-open');
expect(groups.eq(1)).toHaveClass('panel-open');
});
});

describe('`is-disabled` attribute', function() {
var groupBody;
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 {{panelClass || 'panel-default'}}">
<div class="panel" ng-class="panelClass || 'panel-default'">
<div class="panel-heading" ng-keypress="toggleOpen($event)">
<h4 class="panel-title">
<div tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" uib-accordion-transclude="heading"><span ng-class="{'text-muted': isDisabled}">{{heading}}</span></div>
Expand Down

0 comments on commit 0917623

Please sign in to comment.