As it turns out, a TabContainer
is really just a fancier
version of a StackContainer
âthe
primary difference is that a TabContainer
comes with a snazzy set of tabs
that can be used to control which page is displayed at any given time.
In fact, the TabContainer
inherits
from StackContainer
and provides
only a few additional features that pertain to the list of tabs
itself. Example 14-6
illustrates basic usage of the TabContainer
.
Example 14-6. Creating a TabContainer in markup
<div dojoType="dijit.layout.TabContainer" style="width:225px; height:100px; margin:5px; border:solid 1px;"> <div dojoType="dijit.layout.ContentPane" title="one"> One fish... </div> <div dojoType="dijit.layout.ContentPane" title="two"> Two fish... </div> <div dojoType="dijit.layout.ContentPane" title="red" closable= "true">Red fish... <script type="dojo/method" event="onClose" args="evt"> console.log("Closing", this.title); return true; //must return true for close to occur! </script> </div> <div dojoType="dijit.layout.ContentPane" title="blue"> Blue fish... </div> </div>
Take special note that the tab controls take care of themselves;
you simply provide a title
attribute to each child of the TabContainer
, and the rest is handled with
internal automation that you don't have get be directly involved with
(and that's the best kind). Additionally, notice that you may provide
a closeable tab via the closable
attribute, and an optional onClose
extension point may perform a custom action when a close does occur.
Be careful, though, because if true
is not returned from onClose
, the
tab will not close.
Table 14-7 lists the features that
pertain to TabContainer
.
Table 14-7. TabContainer API
Name | Type | Comment |
---|---|---|
| String | Mixed into |
| Boolean | Mixed into |
| Function | An extension point
mixed into |
| String | Specifies where the
list of tab buttons should appear. Possible values include
|
|
| This functionality is
inherited from |
Tip
The buttons you see on a tab container are honest to goodness
dijit.form.Button
buttons; do
with them as you will.
Just like with StackContainer
, you may lazy load content in
a TabContainer
via a ContentPane
, as long as preload
is set to be false
.
And now, Example 14-7 shows how to use programmatic creation.
Example 14-7. Programmatically creating a TabContainer
var container = new dijit.layout.TabContainer({ tabPosition: "left-h", style : "width:200px;height:200px;" }, "foo"); var leftChild = new dijit.layout.ContentPane({title : "tab1"}); leftChild.domNode.innerHTML="tab 1"; var rightChild = new dijit.layout.ContentPane({title : "tab2", closable: true}); rightChild.domNode.innerHTML="tab 2"; container.addChild(leftChild); container.addChild(rightChild); container.startup( );
Get Dojo: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.