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

fix(accordion): panel-open class not shown with custom class #4870

Closed
wants to merge 2 commits into from
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
3 changes: 2 additions & 1 deletion src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ 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';
element.addClass(scope.panelClass);
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">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do want the ng-class to replace the interpolated class, so

<div class="panel" ng-class="panelClass || 'panel-default'">

This is to keep behavior consistent with dynamic class changing.

<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