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

Commit e0ddec6

Browse files
committed
feat(tabs): add the ability to set the direction of the tabs
Add the ability to set the direction of the tabs, the possible values are 'right', 'left' and 'below'. If no direction is defined the tabs are rendered on the top as they do now
1 parent 360cd5c commit e0ddec6

File tree

4 files changed

+85
-7
lines changed

4 files changed

+85
-7
lines changed

src/tabs/tabs.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ function TabsetCtrl($scope, $element) {
7777
restrict: 'EA',
7878
transclude: true,
7979
replace: true,
80+
require: '^tabset',
8081
scope: {},
8182
controller: 'TabsetController',
8283
templateUrl: 'template/tabs/tabset.html',
83-
link: function(scope, element, attrs) {
84-
scope.vertical = angular.isDefined(attrs.vertical) ? scope.$eval(attrs.vertical) : false;
85-
scope.type = angular.isDefined(attrs.type) ? scope.$parent.$eval(attrs.type) : 'tabs';
84+
compile: function(elm, attrs, transclude) {
85+
return function(scope, element, attrs, tabsetCtrl) {
86+
scope.vertical = angular.isDefined(attrs.vertical) ? scope.$eval(attrs.vertical) : false;
87+
scope.type = angular.isDefined(attrs.type) ? scope.$parent.$eval(attrs.type) : 'tabs';
88+
scope.direction = angular.isDefined(attrs.direction) ? scope.$parent.$eval(attrs.direction) : 'top';
89+
scope.tabsAbove = (scope.direction != 'below');
90+
tabsetCtrl.$scope = scope;
91+
tabsetCtrl.$transcludeFn = transclude;
92+
};
8693
}
8794
};
8895
})
@@ -280,5 +287,24 @@ function($parse, $http, $templateCache, $compile) {
280287
}
281288
}])
282289

290+
.directive('tabsetTitles', function($http) {
291+
return {
292+
restrict: 'A',
293+
require: '^tabset',
294+
templateUrl: 'template/tabs/tabset-titles.html',
295+
replace: true,
296+
link: function(scope, elm, attrs, tabsetCtrl) {
297+
if (!scope.$eval(attrs.tabsetTitles)) {
298+
elm.remove();
299+
} else {
300+
//now that tabs location has been decided, transclude the tab titles in
301+
tabsetCtrl.$transcludeFn(tabsetCtrl.$scope.$parent, function(node) {
302+
elm.append(node);
303+
});
304+
}
305+
}
306+
};
307+
})
308+
283309
;
284310

src/tabs/test/tabsSpec.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('tabs', function() {
2-
beforeEach(module('ui.bootstrap.tabs', 'template/tabs/tabset.html', 'template/tabs/tab.html'));
2+
beforeEach(module('ui.bootstrap.tabs', 'template/tabs/tabset.html', 'template/tabs/tab.html', 'template/tabs/tabset-titles.html'));
33

44
var elm, scope;
55
function titles() {
@@ -483,6 +483,56 @@ describe('tabs', function() {
483483
});
484484
});
485485

486+
describe('direction', function() {
487+
it('should not have `tab-left`, `tab-right` nor `tabs-below` classes if the direction is undefined', inject(function($compile, $rootScope) {
488+
scope = $rootScope.$new();
489+
scope.direction = undefined;
490+
491+
elm = $compile('<tabset direction="direction"></tabset>')(scope);
492+
scope.$apply();
493+
expect(elm).not.toHaveClass('tabs-left');
494+
expect(elm).not.toHaveClass('tabs-right');
495+
expect(elm).not.toHaveClass('tabs-below');
496+
expect(elm.find('.nav + .tab-content').length).toBe(1);
497+
}));
498+
499+
it('should only have the `tab-left` direction class if the direction is "left"', inject(function($compile, $rootScope) {
500+
scope = $rootScope.$new();
501+
scope.direction = 'left';
502+
503+
elm = $compile('<tabset direction="direction"></tabset>')(scope);
504+
scope.$apply();
505+
expect(elm).toHaveClass('tabs-left');
506+
expect(elm).not.toHaveClass('tabs-right');
507+
expect(elm).not.toHaveClass('tabs-below');
508+
expect(elm.find('.nav + .tab-content').length).toBe(1);
509+
}));
510+
511+
it('should only have the `tab-right direction class if the direction is "right"', inject(function($compile, $rootScope) {
512+
scope = $rootScope.$new();
513+
scope.direction = 'right';
514+
515+
elm = $compile('<tabset direction="direction"></tabset>')(scope);
516+
scope.$apply();
517+
expect(elm).not.toHaveClass('tabs-left');
518+
expect(elm).toHaveClass('tabs-right');
519+
expect(elm).not.toHaveClass('tabs-below');
520+
expect(elm.find('.nav + .tab-content').length).toBe(1);
521+
}));
522+
523+
it('should only have the `tab-below direction class if the direction is "below"', inject(function($compile, $rootScope) {
524+
scope = $rootScope.$new();
525+
scope.direction = 'below';
526+
527+
elm = $compile('<tabset direction="direction"></tabset>')(scope);
528+
scope.$apply();
529+
expect(elm).not.toHaveClass('tabs-left');
530+
expect(elm).not.toHaveClass('tabs-right');
531+
expect(elm).toHaveClass('tabs-below');
532+
expect(elm.find('.tab-content + .nav').length).toBe(1);
533+
}));
534+
});
535+
486536
//https://github.com/angular-ui/bootstrap/issues/524
487537
describe('child compilation', function() {
488538

template/tabs/tabset-titles.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<ul class="nav {{type && 'nav-' + type}}" ng-class="{'nav-stacked': vertical}">
2+
</ul>

template/tabs/tabset.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
<div class="tabbable">
3-
<ul class="nav {{type && 'nav-' + type}}" ng-class="{'nav-stacked': vertical}" ng-transclude>
4-
</ul>
2+
<div class="tabbable" ng-class="{'tabs-right': direction == 'right', 'tabs-left': direction == 'left', 'tabs-below': direction == 'below'}">
3+
<div tabset-titles="tabsAbove"></div>
54
<div class="tab-content">
65
<div class="tab-pane"
76
ng-repeat="tab in tabs"
87
ng-class="{active: tab.active}"
98
tab-content-transclude="tab">
109
</div>
1110
</div>
11+
<div tabset-titles="!tabsAbove"></div>
1212
</div>

0 commit comments

Comments
 (0)