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

feat(tabs): add the ability to set the direction of the tabs #659

Closed
wants to merge 1 commit into from

Conversation

lgalfaso
Copy link
Contributor

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

@ghost
Copy link

ghost commented Jul 12, 2013

in master it is already possibly to specify direction through <tabset class="tabs-<orientation>"/> see #584

@lgalfaso
Copy link
Contributor Author

@bk1te at master there is the property vertical that sets the class nav-stacked on the <ul>, this adds the class tabs-below, tabs-right or tabs-left on the parent of this element.

This is, what is at trunk is for "Stackable" and this patch is for "Tabbable in any direction"

http://twitter.github.io/bootstrap/components.html#navs

Maybe I am missing something

@ghost
Copy link

ghost commented Jul 13, 2013

update comment

@pkozlowski-opensource
Copy link
Member

@lgalfaso we had an issue opened #102 which was about adding this direction / orientation attribute. But then I've realized that it is possible with a CSS attribute so closed the issue - no one was screaming at the time :-)

I'm in favor of merging it - it makes tabs more semantic and Bootstrap's CSS independent.
@ajoslin @bekos WDYT?

@bekos
Copy link
Contributor

bekos commented Jul 13, 2013

@pkozlowski-opensource +1 for replacing Bootstrap classes with semantic attributes. For this one, looking at the code I think the below option does not work as it is supposed (same problem as #102, need to change elements order).

@lgalfaso
Copy link
Contributor Author

6616b51eb83f4eeff2505815ce06aed29b5304bb fixes the issue of tabs below, it would be simpler to use ng-if but that would add a hard dependency on angular 1.1.5+, so decided to go with the proposed solution at the patch

@lgalfaso
Copy link
Contributor Author

@pkozlowski-opensource With 02664aad9548f2a916a1d4a3bb00887d38ba40d8 the extra <div> will be hidden, without an ng-if I am not sure on how to fully remove it

@ajoslin
Copy link
Contributor

ajoslin commented Jul 15, 2013

Hi @lgalfaso - thanks for coming in with a feature PR :-)

Sorry for the late reply I've been on vacation.

This is a good feature to have - but I dunno if I like the direction of having two ng-repeats.

Can't we just make one ng-repeat and have the <ul> of tab titles be either appended or prepended depending on the option? We can even make it customizable inside the template. Here is how I would probably do it:

tabset.html

<div class="tabbable">
  <div tabset-titles=" tabsAbove "></div>
  <div class="tab-content">
    <div class="tab-pane" 
           ng-repeat="tab in tabs" 
           ng-class="{active: tab.active}"
           tab-content-transclude="tab">
    </div>
  </div>
  <div tabset-titles=" !tabsAbove "></div>
</div>

tabset-titles.html

<ul class="nav {{type && 'nav-' + type}}" ng-class="{'nav-stacked': vertical}">
</ul>

tabsetTitles directive

.directive('tabsetTitles', function($http) {
  return {
    restrict: 'A',
    require: '^tabset',
    templateUrl: 'template/tabs/tabset-titles.html',
    replace: true,
    link: function(scope, elm, attrs, tabsetCtrl) {
      if (!scope.$eval(attrs.tabsetTitles)) {
        elm.remove();
      } else {
        //now that tabs location has been decided, transclude the tab titles in
        tabsetCtrl.$transcludeFn(scope, function(node) {
          elm.append(node);
        });
      }
    }
  };
});

Then tabset directive would just expose its transclude function on its controller.

@lgalfaso
Copy link
Contributor Author

Hi @ajoslin
Updated the patch so there is only one repeat (in fact, there is only one of everything), but there is some DOM manipulation during link to flip things if the direction is below

@ajoslin
Copy link
Contributor

ajoslin commented Jul 15, 2013

Hi @lgalfaso,

Your solution looks the best and simplest at first... but the problem with it is that we want these templates fully customizable. If I make my own completely custom CSS framework that uses a different layout than bootstrap's, I should be able to take tabs.js from this repo, and put my own template in.

So think of it this way: If I had to completely change the css and add a few layers of wrapper divs or some really weird thing, would it still work?

The solution I proposed in the comment above allows a customizable template.

@ajoslin
Copy link
Contributor

ajoslin commented Jul 15, 2013

If you don't quite understand what 'transcludeFn' in my example means tell me & I'll explain it (many people don't understand it, it can be confusing 🌝 )

@lgalfaso
Copy link
Contributor Author

Hi @ajoslin the code you posted is easy to understand, the parts that I dot not fully like are that there is an extra template and there is still some duplication, but agree that the patch I posted will have a tendency to break if a user customizes the templates. Will post a new patch in a few

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
@lgalfaso
Copy link
Contributor Author

e0ddec6 implements the changes proposed by @ajoslin

@ajoslin
Copy link
Contributor

ajoslin commented Jul 24, 2013

edit: nevermind :-)

@ajoslin
Copy link
Contributor

ajoslin commented Jul 24, 2013

Nevermind my above comment! I will merge this in later this week. Thanks @lgalfaso !

@ajoslin ajoslin closed this in 220e7b6 Jul 27, 2013
@lgalfaso lgalfaso deleted the tabs-direction branch July 27, 2013 19:25
@mfrye
Copy link

mfrye commented Jul 31, 2013

@ajoslin I was trying to work on the same thing independently and I just came across this issue. I'm a bit of a noob with Angular, so I'm sorry if this is a stupid question...

I pulled the code from the master, but I can't seem to get the tabs directions to work right and I'm having trouble understanding your code. I'm adding direction="below" to the tabset, but it's not triggering the tabsAbove correctly. I guess I'm still trying to wrap my head around transclude, but can you provide an example of this working?

@bekos
Copy link
Contributor

bekos commented Jul 31, 2013

@mfrye Have you tried with quotes? diection="'below'"

@mfrye
Copy link

mfrye commented Jul 31, 2013

ah that was it. Thank you @bekos

@mfrye
Copy link

mfrye commented Jul 31, 2013

@bekos actually one more question. Say I wanted to dynamically change between top and bottom with a button. What would be the optimal way to do that / like how would I reference that attribute in the controller?

@bekos
Copy link
Contributor

bekos commented Jul 31, 2013

The direction attribute is not watched by the directive (because until we found an easy way to distinct between watchable/unwatchable attributes, we cannot penalty other user's performance for edge cases like this one).

So, you can either edit the tabset's linking function to watch this attribute, or better, you can destroy and recreate your tabs with the click of the button.

@mfrye
Copy link

mfrye commented Jul 31, 2013

Okay, thanks for the help.

chrisirhc added a commit to chrisirhc/angular-ui-bootstrap that referenced this pull request Dec 13, 2013
This reverts commit 220e7b6.

Revert the capability to set the tab direction. This is no longer a
feature in Bootstrap 3 and breaks nested tabs.

Closes angular-ui#783
Relates to angular-ui#659
chrisirhc added a commit to chrisirhc/angular-ui-bootstrap that referenced this pull request Dec 17, 2013
This reverts commit 220e7b6.

Revert the capability to set the tab direction. This is no longer a
feature in Bootstrap 3 and breaks nested tabs.

Closes angular-ui#783
Relates to angular-ui#659
pkozlowski-opensource pushed a commit that referenced this pull request Dec 23, 2013
This reverts commit 220e7b6.

Revert the capability to set the tab direction. This is no longer a
feature in Bootstrap 3 and breaks nested tabs.

Closes #783
Relates to #659
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants