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

Commit 0643fd3

Browse files
rvanbaalenwesleycho
rvanbaalen
authored andcommitted
fix(accordion): apply disabled style to accordion-header
- Disable the header if `is-disabled` is true Closes #3599 Fixes #3233
1 parent 577b2a2 commit 0643fd3

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

src/accordion/accordion.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
121121
link: function(scope, element, attr, controller) {
122122
scope.$watch(function() { return controller[attr.accordionTransclude]; }, function(heading) {
123123
if ( heading ) {
124-
element.html('');
125-
element.append(heading);
124+
element.find('span').html('');
125+
element.find('span').append(heading);
126126
}
127127
});
128128
}

src/accordion/test/accordion.spec.js

+59-31
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ describe('accordion', function () {
126126
describe('with static panels', function () {
127127
beforeEach(function () {
128128
var tpl =
129-
'<accordion>' +
130-
'<accordion-group heading="title 1">Content 1</accordion-group>' +
131-
'<accordion-group heading="title 2">Content 2</accordion-group>' +
132-
'</accordion>';
129+
'<accordion>' +
130+
'<accordion-group heading="title 1">Content 1</accordion-group>' +
131+
'<accordion-group heading="title 2">Content 2</accordion-group>' +
132+
'</accordion>';
133133
element = angular.element(tpl);
134134
$compile(element)(scope);
135135
scope.$digest();
@@ -172,9 +172,9 @@ describe('accordion', function () {
172172
var model;
173173
beforeEach(function () {
174174
var tpl =
175-
'<accordion>' +
176-
'<accordion-group ng-repeat="group in groups" heading="{{group.name}}">{{group.content}}</accordion-group>' +
177-
'</accordion>';
175+
'<accordion>' +
176+
'<accordion-group ng-repeat="group in groups" heading="{{group.name}}">{{group.content}}</accordion-group>' +
177+
'</accordion>';
178178
element = angular.element(tpl);
179179
model = [
180180
{name: 'title 1', content: 'Content 1'},
@@ -217,10 +217,10 @@ describe('accordion', function () {
217217
describe('is-open attribute', function() {
218218
beforeEach(function () {
219219
var tpl =
220-
'<accordion>' +
221-
'<accordion-group heading="title 1" is-open="open.first">Content 1</accordion-group>' +
222-
'<accordion-group heading="title 2" is-open="open.second">Content 2</accordion-group>' +
223-
'</accordion>';
220+
'<accordion>' +
221+
'<accordion-group heading="title 1" is-open="open.first">Content 1</accordion-group>' +
222+
'<accordion-group heading="title 2" is-open="open.second">Content 2</accordion-group>' +
223+
'</accordion>';
224224
element = angular.element(tpl);
225225
scope.open = { first: false, second: true };
226226
$compile(element)(scope);
@@ -247,10 +247,10 @@ describe('accordion', function () {
247247
describe('is-open attribute with dynamic content', function() {
248248
beforeEach(function () {
249249
var tpl =
250-
'<accordion>' +
251-
'<accordion-group heading="title 1" is-open="open1"><div ng-repeat="item in items">{{item}}</div></accordion-group>' +
252-
'<accordion-group heading="title 2" is-open="open2">Static content</accordion-group>' +
253-
'</accordion>';
250+
'<accordion>' +
251+
'<accordion-group heading="title 1" is-open="open1"><div ng-repeat="item in items">{{item}}</div></accordion-group>' +
252+
'<accordion-group heading="title 2" is-open="open2">Static content</accordion-group>' +
253+
'</accordion>';
254254
element = angular.element(tpl);
255255
scope.items = ['Item 1', 'Item 2', 'Item 3'];
256256
scope.open1 = true;
@@ -274,9 +274,9 @@ describe('accordion', function () {
274274
describe('is-open attribute with dynamic groups', function () {
275275
beforeEach(function () {
276276
var tpl =
277-
'<accordion>' +
278-
'<accordion-group ng-repeat="group in groups" heading="{{group.name}}" is-open="group.open">{{group.content}}</accordion-group>' +
279-
'</accordion>';
277+
'<accordion>' +
278+
'<accordion-group ng-repeat="group in groups" heading="{{group.name}}" is-open="group.open">{{group.content}}</accordion-group>' +
279+
'</accordion>';
280280
element = angular.element(tpl);
281281
scope.groups = [
282282
{name: 'title 1', content: 'Content 1', open: false},
@@ -310,9 +310,9 @@ describe('accordion', function () {
310310
var groupBody;
311311
beforeEach(function () {
312312
var tpl =
313-
'<accordion>' +
314-
'<accordion-group heading="title 1" is-disabled="disabled">Content 1</accordion-group>' +
315-
'</accordion>';
313+
'<accordion>' +
314+
'<accordion-group heading="title 1" is-disabled="disabled">Content 1</accordion-group>' +
315+
'</accordion>';
316316
element = angular.element(tpl);
317317
scope.disabled = true;
318318
$compile(element)(scope);
@@ -340,17 +340,38 @@ describe('accordion', function () {
340340
scope.$digest();
341341
expect(groupBody.scope().isOpen).toBeTruthy();
342342
});
343+
344+
it('should have text-muted styling', function () {
345+
expect(findGroupLink(0).find('span:first')).toHaveClass('text-muted');
346+
});
343347
});
344348

349+
// This is re-used in both the accordion-heading element and the accordion-heading attribute tests
350+
function isDisabledStyleCheck() {
351+
var tpl =
352+
'<accordion ng-init="a = [1,2,3]">' +
353+
'<accordion-group heading="I get overridden" is-disabled="true">' +
354+
'<accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </accordion-heading>' +
355+
'Body' +
356+
'</accordion-group>' +
357+
'</accordion>';
358+
scope.disabled = true;
359+
element = $compile(tpl)(scope);
360+
scope.$digest();
361+
groups = element.find('.panel');
362+
363+
expect(findGroupLink(0).find('span').hasClass('text-muted')).toBe(true);
364+
}
365+
345366
describe('accordion-heading element', function() {
346367
beforeEach(function() {
347368
var tpl =
348-
'<accordion ng-init="a = [1,2,3]">' +
349-
'<accordion-group heading="I get overridden">' +
369+
'<accordion ng-init="a = [1,2,3]">' +
370+
'<accordion-group heading="I get overridden">' +
350371
'<accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </accordion-heading>' +
351372
'Body' +
352-
'</accordion-group>' +
353-
'</accordion>';
373+
'</accordion-group>' +
374+
'</accordion>';
354375
element = $compile(tpl)(scope);
355376
scope.$digest();
356377
groups = element.find('.panel');
@@ -359,20 +380,25 @@ describe('accordion', function () {
359380
expect(findGroupLink(0).text()).toBe('Heading Element 123 ');
360381
});
361382
it('attaches the same scope to the transcluded heading and body', function() {
362-
expect(findGroupLink(0).find('span').scope().$id).toBe(findGroupBody(0).find('span').scope().$id);
383+
expect(findGroupLink(0).find('span.ng-scope').scope().$id).toBe(findGroupBody(0).find('span').scope().$id);
363384
});
385+
it('should wrap the transcluded content in a span', function () {
386+
expect(findGroupLink(0).find('span:first').length).toEqual(1);
387+
});
388+
389+
it('should have disabled styling when is-disabled is true', isDisabledStyleCheck);
364390

365391
});
366392

367393
describe('accordion-heading attribute', function() {
368394
beforeEach(function() {
369395
var tpl =
370-
'<accordion ng-init="a = [1,2,3]">' +
371-
'<accordion-group heading="I get overridden">' +
396+
'<accordion ng-init="a = [1,2,3]">' +
397+
'<accordion-group heading="I get overridden">' +
372398
'<div accordion-heading>Heading Element <span ng-repeat="x in a">{{x}}</span> </div>' +
373399
'Body' +
374-
'</accordion-group>' +
375-
'</accordion>';
400+
'</accordion-group>' +
401+
'</accordion>';
376402
element = $compile(tpl)(scope);
377403
scope.$digest();
378404
groups = element.find('.panel');
@@ -381,9 +407,11 @@ describe('accordion', function () {
381407
expect(findGroupLink(0).text()).toBe('Heading Element 123 ');
382408
});
383409
it('attaches the same scope to the transcluded heading and body', function() {
384-
expect(findGroupLink(0).find('span').scope().$id).toBe(findGroupBody(0).find('span').scope().$id);
410+
expect(findGroupLink(0).find('span.ng-scope').scope().$id).toBe(findGroupBody(0).find('span').scope().$id);
385411
});
386412

413+
it('should have disabled styling when is-disabled is true', isDisabledStyleCheck);
414+
387415
});
388416

389417
describe('accordion-heading, with repeating accordion-groups', function() {

0 commit comments

Comments
 (0)