Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have some mui tabs coming dynamicaly , how can i activate the tabs from javascript #44

Closed
mukuljp opened this issue Sep 15, 2015 · 10 comments

Comments

@mukuljp
Copy link

mukuljp commented Sep 15, 2015

No description provided.

@amorey
Copy link
Member

amorey commented Sep 15, 2015

There's an undocumented feature which lets you activate tabs from JavaScript:

mui.tabs.activate(paneId);

@mukuljp
Copy link
Author

mukuljp commented Sep 16, 2015

yes ,I have checked that already, it lets you activate the tabs onebyone right, that too by passing pane id , if i have 20 sections , if each section has a tabbed content of which has say 3 tabs,
so to activate all those i have give 60 unique id's to individual identify panes and activate them using mui.tabs.activate.instead it would be great if i have a single function call that activates all tabs in those 20 sections , and set the first tab selected by default. does mui have this feature? thank you

@amorey
Copy link
Member

amorey commented Sep 16, 2015

I see... to activate the tab on page load you can use the mui-is-active CSS state:

<ul class="mui-tabs">
  <li class="mui-is-active"><a data-mui-toggle="tab" data-mui-controls="pane-default-1">Tab-1</a></li>
  <li><a data-mui-toggle="tab" data-mui-controls="pane-default-2">Tab-2</a></li>
  <li><a data-mui-toggle="tab" data-mui-controls="pane-default-3">Tab-3</a></li>
</ul>
<div class="mui-tab-content">
  <div class="mui-tab-pane mui-is-active" id="pane-default-1">Pane-1</div>
  <div class="mui-tab-pane" id="pane-default-2">Pane-2</div>
  <div class="mui-tab-pane" id="pane-default-3">Pane-3</div>
</div>

There's a typo in the documentation which I'll fix ASAP.

@amorey
Copy link
Member

amorey commented Sep 18, 2015

@mukuljp Did the CSS class fix your problem?

@mukuljp
Copy link
Author

mukuljp commented Sep 18, 2015

@amorey , the html for the tabs is coming up via ajax, i gave a class to all tabs initialy (only to first tab).

<ul class="mui-tabs "  >
   <li ><a ng-click="activateThisTab('bla-' + p.program_numeric_id + '-1', null)" data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-1">Next Steps</a></li>
   <li><a  ng-click="activateThisTab('bla-' + p.program_numeric_id + '-2', null)"  data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-2">Details</a></li>
   <li><a  ng-click="activateThisTab('bla-' + p.program_numeric_id + '-3', p.offices)"  data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-3">Hours & Locations</a></li>
</ul>
<div class="mui-tab-content">
   <div class="mui-tab-pane  first_mui_tab_set" id="bla-{{p.program_numeric_id}}-1">
      <div class="mui-panel">
      </div>
   </div>
   <div class="mui-tab-pane" id="bla-{{p.program_numeric_id}}-2">
      <div class="mui-panel">

      </div>
   </div>
   <div class="mui-tab-pane" id="bla-{{p.program_numeric_id}}-3">
      <div class="mui-panel">

      </div>
   </div>
</div> .

and in activateThisTab function i added the mui.tabs.activate(paneId);
and finally to set the first tab as selected, I called a jquery code after the html got finished rendering,

 jQuery(".first_mui_tab_set").each(function () {
                var id_pane = jQuery(this).attr("id");
                mui.tabs.activate(id_pane);
            });

Overall its a hack :)

i had to put unique ids and click handlers for every tab, it would have been easier if its done by class .

@amorey
Copy link
Member

amorey commented Sep 18, 2015

I see. That works but using the mui-is-active class is definitely easier. This should fix the problem:

<ul class="mui-tabs "  >
   <li class="mui-is-active"><a ng-click="activateThisTab('bla-' + p.program_numeric_id + '-1', null)" data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-1">Next Steps</a></li>
   <li><a  ng-click="activateThisTab('bla-' + p.program_numeric_id + '-2', null)"  data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-2">Details</a></li>
   <li><a  ng-click="activateThisTab('bla-' + p.program_numeric_id + '-3', p.offices)"  data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-3">Hours & Locations</a></li>
</ul>

@mukuljp
Copy link
Author

mukuljp commented Sep 18, 2015

oh let me try that,

@amorey
Copy link
Member

amorey commented Sep 18, 2015

Ok, let me know if it works.

Just to clarify, you need to add the mui-is-active class to the tab and the pane:

<ul class="mui-tabs "  >
   <li ><a class="mui-is-active" ng-click="activateThisTab('bla-' + p.program_numeric_id + '-1', null)" data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-1">Next Steps</a></li>
   <li><a  ng-click="activateThisTab('bla-' + p.program_numeric_id + '-2', null)"  data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-2">Details</a></li>
   <li><a  ng-click="activateThisTab('bla-' + p.program_numeric_id + '-3', p.offices)"  data-mui-toggle="tab" data-mui-controls="bla-{{p.program_numeric_id}}-3">Hours & Locations</a></li>
</ul>
<div class="mui-tab-content">
   <div class="mui-tab-pane mui-is-active first_mui_tab_set" id="bla-{{p.program_numeric_id}}-1">
      <div class="mui-panel">
      </div>
   </div>
   <div class="mui-tab-pane" id="bla-{{p.program_numeric_id}}-2">
      <div class="mui-panel">

      </div>
   </div>
   <div class="mui-tab-pane" id="bla-{{p.program_numeric_id}}-3">
      <div class="mui-panel">

      </div>
   </div>
</div>

@mukuljp
Copy link
Author

mukuljp commented Sep 18, 2015

yes that worked , but in the documentation I found it was wrong at first . anyway its showing correctly now in https://www.muicss.com/docs/v1/css-js/tabs
your work is good , its very easy to use , thank you @amorey

@amorey
Copy link
Member

amorey commented Sep 18, 2015

Great! I'm happy to hear it's working!

@amorey amorey closed this as completed Sep 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants