How do I dynamically show and hide an entire TabContainer using DOJO?

Brian Schroth picture Brian Schroth · Aug 11, 2009 · Viewed 49.4k times · Source

DOJO seems to have some quirks here. I specifically need to have the TabContainer hidden when the page loads, but then become visible after the user clicks a button. The first thing I tried is setting style.display = "none" to start, and then setting style.display = "block" on the click event. Unfortunately, this only partially works- the page will render an invisible box in the right location/dimensions, but not render the actual contents. The box's contents only get rendered when triggered by something else (for example, going to a different FF tab or suspending/resuming firebug will make the box render).

If the style.display property is set to be visible on page load, everything works fine. You can toggle the display property and it shows or hides the tabcontainer properly. But if it's set to "none" on page load, it screws up.

I tried a workaround of setting the style.display property to "" in the HTML but then immediately setting it to "none" in the Javascript, but it still fails- the change occurs too soon and it needs to happen after the tabcontainer renders (which can take a second or two).

Some stripped sample code:

HTML:
<div id="tabContainer" dojoType="dijit.layout.TabContainer" style="width:500px; height:100px;display:none;">
</div>

and then the Javascript to show the tab on a user click:

function initTabs()  
{  
var tabContainer = dojo.byId('tabContainer');  
tabContainer.style.display = 'block';  
}  

How can I dynamically show/hide a TabContainer without having it start in the shown state?

Answer

Lukasz R. picture Lukasz R. · Sep 2, 2009

There is solution for this. If you want to show TabContainer calll:

dijit.byId("tabContainer").domNode.style.display = 'block';
dijit.byId("tabContainer").resize();

and use 'none' if you want to hide TabContainer.

This works for me, but that is truth, it is not obvious :)