From 25f6e55c3c6655a723f382dd14204e71623fa0ae Mon Sep 17 00:00:00 2001 From: Nishes Joshi Date: Thu, 20 Jun 2013 13:43:12 +0200 Subject: [PATCH] fix(accordion): Allow accordion heading directives as attributes. Closes #540 --- src/accordion/accordion.js | 2 +- src/accordion/test/accordionSpec.js | 36 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/accordion/accordion.js b/src/accordion/accordion.js index 9179e6e81d..9541aea01b 100644 --- a/src/accordion/accordion.js +++ b/src/accordion/accordion.js @@ -104,7 +104,7 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse']) // .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, diff --git a/src/accordion/test/accordionSpec.js b/src/accordion/test/accordionSpec.js index 2288863b62..cbafd566d8 100644 --- a/src/accordion/test/accordionSpec.js +++ b/src/accordion/test/accordionSpec.js @@ -284,6 +284,28 @@ describe('accordion', function () { }); + describe('accordion-heading attribute', function() { + beforeEach(function() { + var tpl = + '' + + '' + + '
Heading Element {{x}}
' + + 'Body' + + '
' + + '
'; + element = $compile(tpl)(scope); + scope.$digest(); + groups = element.find('.accordion-group'); + }); + it('transcludes the 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('{{x}}')(scope); @@ -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('
{{x}}
')(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'); + }); + }); + }); });