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

Commit

Permalink
feat(tabs): support optional classes on tab
Browse files Browse the repository at this point in the history
- Add support for optional classes on each tab

Closes #5430
  • Loading branch information
amahfouz authored and wesleycho committed Feb 25, 2016
1 parent 8575155 commit 8364e76
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/tabs/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@

<hr />

Tabbed pills with CSS classes
<uib-tabset type="pills">
<uib-tab heading="Default Size">Tab 1 content</uib-tab>
<uib-tab heading="Small Button" classes="btn-sm">Tab 2 content</uib-tab>
</uib-tabset>

<hr />

Tabs using nested forms:
<form name="outerForm" class="tab-form-demo">
<uib-tabset active="activeForm">
Expand Down
10 changes: 10 additions & 0 deletions src/tabs/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ AngularJS version of the tabs directive.

### uib-tab settings

* `active`
<small class="badge">$</small>
<i class="glyphicon glyphicon-eye-open"></i>
_(Default: `false`)_ -
Whether tab is currently selected.

* `classes`
<small class="badge">$</small> -
An optional string of space-separated CSS classes.

* `deselect()`
<small class="badge">$</small> -
An optional expression called when tab is deactivated.
Expand Down
5 changes: 5 additions & 0 deletions src/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ angular.module('ui.bootstrap.tabs', [])
scope: {
heading: '@',
index: '=?',
classes: '@?',
onSelect: '&select', //This callback is called in contentHeadingTransclude
//once it inserts the tab's content into the dom
onDeselect: '&deselect'
Expand All @@ -143,6 +144,10 @@ angular.module('ui.bootstrap.tabs', [])
}
}

if (angular.isUndefined(attrs.classes)) {
scope.classes = '';
}

scope.select = function() {
if (!scope.disabled) {
var index;
Expand Down
15 changes: 13 additions & 2 deletions src/tabs/test/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ describe('tabs', function() {
scope.first = '1';
scope.second = '2';
scope.active = 1;
scope.firstClass = 'first-class';
scope.secondClass = 'second-class-1 second-class-2';
scope.selectFirst = jasmine.createSpy();
scope.selectSecond = jasmine.createSpy();
scope.deselectFirst = jasmine.createSpy();
scope.deselectSecond = jasmine.createSpy();
elm = $compile([
'<uib-tabset class="hello" data-pizza="pepperoni" active="active">',
' <uib-tab index="1" heading="First Tab {{first}}" select="selectFirst()" deselect="deselectFirst()">',
' <uib-tab index="1" heading="First Tab {{first}}" classes="{{firstClass}}" select="selectFirst()" deselect="deselectFirst()">',
' first content is {{first}}',
' </uib-tab>',
' <uib-tab index="2" select="selectSecond()" deselect="deselectSecond()">',
' <uib-tab index="2" classes="{{secondClass}}" select="selectSecond()" deselect="deselectSecond()">',
' <uib-tab-heading><b>Second</b> Tab {{second}}</uib-tab-heading>',
' second content is {{second}}',
' </uib-tab>',
Expand Down Expand Up @@ -77,6 +79,15 @@ describe('tabs', function() {
expect(scope.active).toBe(1);
});

it('should set optional classes on each tab', function() {
expect(titles().eq(0)).toHaveClass(scope.firstClass);

var secondClassArr = scope.secondClass.split(' ');
secondClassArr.forEach(function(clazz) {
expect(titles().eq(1)).toHaveClass(clazz);
});
});

it('should change active on click', function() {
titles().eq(1).find('> a').click();
expect(contents().eq(1)).toHaveClass('active');
Expand Down
2 changes: 1 addition & 1 deletion template/tabs/tab.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<li ng-class="{active: active, disabled: disabled}" class="uib-tab nav-item">
<li ng-class="[{active: active, disabled: disabled}, classes]" class="uib-tab nav-item">
<a href ng-click="select()" class="nav-link" uib-tab-heading-transclude>{{heading}}</a>
</li>

0 comments on commit 8364e76

Please sign in to comment.