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

Commit 25f6e55

Browse files
nishesjpkozlowski-opensource
authored andcommitted
fix(accordion): Allow accordion heading directives as attributes.
Closes #540
1 parent e63ebba commit 25f6e55

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/accordion/accordion.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
104104
// </accordion-group>
105105
.directive('accordionHeading', function() {
106106
return {
107-
restrict: 'E',
107+
restrict: 'EA',
108108
transclude: true, // Grab the contents to be used as the heading
109109
template: '', // In effect remove this element!
110110
replace: true,

src/accordion/test/accordionSpec.js

+36
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,28 @@ describe('accordion', function () {
284284

285285
});
286286

287+
describe('accordion-heading attribute', function() {
288+
beforeEach(function() {
289+
var tpl =
290+
'<accordion ng-init="a = [1,2,3]">' +
291+
'<accordion-group heading="I get overridden">' +
292+
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
293+
'Body' +
294+
'</accordion-group>' +
295+
'</accordion>';
296+
element = $compile(tpl)(scope);
297+
scope.$digest();
298+
groups = element.find('.accordion-group');
299+
});
300+
it('transcludes the <accordion-heading> content into the heading link', function() {
301+
expect(findGroupLink(0).text()).toBe('Heading Element 123 ');
302+
});
303+
it('attaches the same scope to the transcluded heading and body', function() {
304+
expect(findGroupLink(0).find('span').scope().$id).toBe(findGroupBody(0).find('span').scope().$id);
305+
});
306+
307+
});
308+
287309
describe('accordion-heading, with repeating accordion-groups', function() {
288310
it('should clone the accordion-heading for each group', function() {
289311
element = $compile('<accordion><accordion-group ng-repeat="x in [1,2,3]"><accordion-heading>{{x}}</accordion-heading></accordion-group></accordion>')(scope);
@@ -295,5 +317,19 @@ describe('accordion', function () {
295317
expect(findGroupLink(2).text()).toBe('3');
296318
});
297319
});
320+
321+
322+
describe('accordion-heading attribute, with repeating accordion-groups', function() {
323+
it('should clone the accordion-heading for each group', function() {
324+
element = $compile('<accordion><accordion-group ng-repeat="x in [1,2,3]"><div accordion-heading>{{x}}</div></accordion-group></accordion>')(scope);
325+
scope.$digest();
326+
groups = element.find('.accordion-group');
327+
expect(groups.length).toBe(3);
328+
expect(findGroupLink(0).text()).toBe('1');
329+
expect(findGroupLink(1).text()).toBe('2');
330+
expect(findGroupLink(2).text()).toBe('3');
331+
});
332+
});
333+
298334
});
299335
});

0 commit comments

Comments
 (0)