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

Commit

Permalink
fix(accordion): Allow accordion heading directives as attributes.
Browse files Browse the repository at this point in the history
Closes #540
  • Loading branch information
nishesj authored and pkozlowski-opensource committed Jun 21, 2013
1 parent e63ebba commit 25f6e55
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
// </accordion-group>
.directive('accordionHeading', function() {
return {
restrict: 'E',
restrict: 'EA',
transclude: true, // Grab the contents to be used as the heading
template: '', // In effect remove this element!
replace: true,
Expand Down
36 changes: 36 additions & 0 deletions src/accordion/test/accordionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,28 @@ describe('accordion', function () {

});

describe('accordion-heading attribute', function() {
beforeEach(function() {
var tpl =
'<accordion ng-init="a = [1,2,3]">' +
'<accordion-group heading="I get overridden">' +
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
'Body' +
'</accordion-group>' +
'</accordion>';
element = $compile(tpl)(scope);
scope.$digest();
groups = element.find('.accordion-group');
});
it('transcludes the <accordion-heading> content into the heading link', function() {
expect(findGroupLink(0).text()).toBe('Heading Element 123 ');
});
it('attaches the same scope to the transcluded heading and body', function() {
expect(findGroupLink(0).find('span').scope().$id).toBe(findGroupBody(0).find('span').scope().$id);
});

});

describe('accordion-heading, with repeating accordion-groups', function() {
it('should clone the accordion-heading for each group', function() {
element = $compile('<accordion><accordion-group ng-repeat="x in [1,2,3]"><accordion-heading>{{x}}</accordion-heading></accordion-group></accordion>')(scope);
Expand All @@ -295,5 +317,19 @@ describe('accordion', function () {
expect(findGroupLink(2).text()).toBe('3');
});
});


describe('accordion-heading attribute, with repeating accordion-groups', function() {
it('should clone the accordion-heading for each group', function() {
element = $compile('<accordion><accordion-group ng-repeat="x in [1,2,3]"><div accordion-heading>{{x}}</div></accordion-group></accordion>')(scope);
scope.$digest();
groups = element.find('.accordion-group');
expect(groups.length).toBe(3);
expect(findGroupLink(0).text()).toBe('1');
expect(findGroupLink(1).text()).toBe('2');
expect(findGroupLink(2).text()).toBe('3');
});
});

});
});

1 comment on commit 25f6e55

@pbrain19
Copy link

Choose a reason for hiding this comment

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

Is this template bs 3 ready?

Please sign in to comment.