1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-tab.Panel-method-constructor'><span id='Ext-tab.Panel'>/**
2 </span></span> * @author Ed Spencer, Tommy Maintz, Brian Moeskau
4 * @extends Ext.panel.Panel
6 A basic tab container. TabPanels can be used exactly like a standard {@link Ext.panel.Panel} for layout purposes, but also
7 have special support for containing child Components (`{@link Ext.container.Container#items items}`) that are managed
8 using a {@link Ext.layout.container.Card CardLayout layout manager}, and displayed as separate tabs.
12 By default, a tab's close tool _destroys_ the child tab Component and all its descendants. This makes the child tab
13 Component, and all its descendants __unusable__. To enable re-use of a tab, configure the TabPanel with `{@link #autoDestroy autoDestroy: false}`.
15 __TabPanel's layout:__
17 TabPanels use a Dock layout to position the {@link Ext.tab.Bar TabBar} at the top of the widget. Panels added to the TabPanel will have their
18 header hidden by default because the Tab will automatically take the Panel's configured title and icon.
20 TabPanels use their {@link Ext.panel.Panel#header header} or {@link Ext.panel.Panel#footer footer} element (depending on the {@link #tabPosition}
21 configuration) to accommodate the tab selector buttons. This means that a TabPanel will not display any configured title, and will not display any
22 configured header {@link Ext.panel.Panel#tools tools}.
24 To display a header, embed the TabPanel in a {@link Ext.panel.Panel Panel} which uses `{@link Ext.container.Container#layout layout:'fit'}`.
28 Here is a basic TabPanel rendered to the body. This also shows the useful configuration {@link #activeTab}, which allows you to set the active tab on render.
29 If you do not set an {@link #activeTab}, no tabs will be active by default.
30 {@img Ext.tab.Panel/Ext.tab.Panel1.png TabPanel component}
33 Ext.create('Ext.tab.Panel', {
48 renderTo : Ext.getBody()
51 It is easy to control the visibility of items in the tab bar. Specify hidden: true to have the
52 tab button hidden initially. Items can be subsequently hidden and show by accessing the
53 tab property on the child item.
57 var tabs = Ext.create('Ext.tab.Panel', {
60 renderTo: document.body,
77 setTimeout(function(){
78 tabs.child('#home').tab.hide();
79 var users = tabs.child('#users');
81 tabs.setActiveTab(users);
84 You can remove the background of the TabBar by setting the {@link #plain} property to `false`.
88 Ext.create('Ext.tab.Panel', {
104 renderTo : Ext.getBody()
107 Another useful configuration of TabPanel is {@link #tabPosition}. This allows you to change the position where the tabs are displayed. The available
108 options for this are `'top'` (default) and `'bottom'`.
109 {@img Ext.tab.Panel/Ext.tab.Panel2.png TabPanel component}
112 Ext.create('Ext.tab.Panel', {
117 tabPosition: 'bottom',
121 html : 'A simple tab'
128 renderTo : Ext.getBody()
131 The {@link #setActiveTab} is a very useful method in TabPanel which will allow you to change the current active tab. You can either give it an index or
132 an instance of a tab.
136 var tabs = Ext.create('Ext.tab.Panel', {
141 html : 'A simple tab'
148 renderTo : Ext.getBody()
151 var tab = Ext.getCmp('my-tab');
153 Ext.create('Ext.button.Button', {
154 renderTo: Ext.getBody(),
155 text : 'Select the first tab',
157 handler : function() {
158 tabs.setActiveTab(tab);
162 Ext.create('Ext.button.Button', {
163 text : 'Select the second tab',
165 handler : function() {
166 tabs.setActiveTab(1);
168 renderTo : Ext.getBody()
171 The {@link #getActiveTab} is a another useful method in TabPanel which will return the current active tab.
175 var tabs = Ext.create('Ext.tab.Panel', {
179 html : 'A simple tab'
186 renderTo : Ext.getBody()
189 Ext.create('Ext.button.Button', {
190 text : 'Get active tab',
192 handler : function() {
193 var tab = tabs.getActiveTab();
194 alert('Current tab: ' + tab.title);
196 renderTo : Ext.getBody()
199 Adding a new tab is very simple with a TabPanel. You simple call the {@link #add} method with an config object for a panel.
203 var tabs = Ext.Create('Ext.tab.Panel', {
207 html : 'A simple tab'
214 renderTo : Ext.getBody()
217 Ext.create('Ext.button.Button', {
220 handler : function() {
222 title: 'Tab ' + (tabs.items.length + 1), //we use the tabs.items property to get the length of current items/tabs
226 tabs.setActiveTab(tab);
228 renderTo : Ext.getBody()
231 Additionally, removing a tab is very also simple with a TabPanel. You simple call the {@link #remove} method with an config object for a panel.
235 var tabs = Ext.Create('Ext.tab.Panel', {
239 html : 'A simple tab'
242 id : 'remove-this-tab',
247 renderTo : Ext.getBody()
250 Ext.Create('Ext.button.Button', {
253 handler : function() {
254 var tab = Ext.getCmp('remove-this-tab');
257 renderTo : Ext.getBody()
262 * @param {Object} config The configuration options
266 Ext.define('Ext.tab.Panel', {
267 extend: 'Ext.panel.Panel',
268 alias: 'widget.tabpanel',
269 alternateClassName: ['Ext.TabPanel'],
271 requires: ['Ext.layout.container.Card', 'Ext.tab.Bar'],
273 <span id='Ext-tab.Panel-cfg-tabPosition'> /**
274 </span> * @cfg {String} tabPosition The position where the tab strip should be rendered (defaults to <code>'top'</code>).
275 * In 4.0, The only other supported value is <code>'bottom'</code>.
279 <span id='Ext-tab.Panel-cfg-tabBar'> /**
280 </span> * @cfg {Object} tabBar Optional configuration object for the internal {@link Ext.tab.Bar}. If present, this is
281 * passed straight through to the TabBar's constructor
284 <span id='Ext-tab.Panel-cfg-layout'> /**
285 </span> * @cfg {Object} layout Optional configuration object for the internal {@link Ext.layout.container.Card card layout}.
286 * If present, this is passed straight through to the layout's constructor
289 <span id='Ext-tab.Panel-cfg-removePanelHeader'> /**
290 </span> * @cfg {Boolean} removePanelHeader True to instruct each Panel added to the TabContainer to not render its header
291 * element. This is to ensure that the title of the panel does not appear twice. Defaults to true.
293 removePanelHeader: true,
295 <span id='Ext-tab.Panel-cfg-Boolean'> /**
296 </span> * @cfg Boolean plain
297 * True to not show the full background on the TabBar
301 <span id='Ext-tab.Panel-cfg-itemCls'> /**
302 </span> * @cfg {String} itemCls The class added to each child item of this TabPanel. Defaults to 'x-tabpanel-child'.
304 itemCls: 'x-tabpanel-child',
306 <span id='Ext-tab.Panel-cfg-minTabWidth'> /**
307 </span> * @cfg {Number} minTabWidth The minimum width for a tab in the {@link #tabBar}. Defaults to <code>30</code>.
310 <span id='Ext-tab.Panel-cfg-deferredRender'> /**
311 </span> * @cfg {Boolean} deferredRender
312 * <p><tt>true</tt> by default to defer the rendering of child <tt>{@link Ext.container.Container#items items}</tt>
313 * to the browsers DOM until a tab is activated. <tt>false</tt> will render all contained
314 * <tt>{@link Ext.container.Container#items items}</tt> as soon as the {@link Ext.layout.container.Card layout}
315 * is rendered. If there is a significant amount of content or a lot of heavy controls being
316 * rendered into panels that are not displayed by default, setting this to <tt>true</tt> might
317 * improve performance.</p>
318 * <br><p>The <tt>deferredRender</tt> property is internally passed to the layout manager for
319 * TabPanels ({@link Ext.layout.container.Card}) as its {@link Ext.layout.container.Card#deferredRender}
320 * configuration value.</p>
321 * <br><p><b>Note</b>: leaving <tt>deferredRender</tt> as <tt>true</tt> means that the content
322 * within an unactivated tab will not be available</p>
324 deferredRender : true,
327 initComponent: function() {
329 dockedItems = me.dockedItems || [],
330 activeTab = me.activeTab || 0;
332 me.layout = Ext.create('Ext.layout.container.Card', Ext.apply({
334 deferredRender: me.deferredRender,
338 <span id='Ext-tab.Panel-property-tabBar'> /**
339 </span> * @property tabBar
341 * Internal reference to the docked TabBar
343 me.tabBar = Ext.create('Ext.tab.Bar', Ext.apply({}, me.tabBar, {
344 dock: me.tabPosition,
347 cardLayout: me.layout,
351 if (dockedItems && !Ext.isArray(dockedItems)) {
352 dockedItems = [dockedItems];
355 dockedItems.push(me.tabBar);
356 me.dockedItems = dockedItems;
359 <span id='Ext-tab.Panel-event-beforetabchange'> /**
360 </span> * @event beforetabchange
361 * Fires before a tab change (activated by {@link #setActiveTab}). Return false in any listener to cancel
363 * @param {Ext.tab.Panel} tabPanel The TabPanel
364 * @param {Ext.Component} newCard The card that is about to be activated
365 * @param {Ext.Component} oldCard The card that is currently active
369 <span id='Ext-tab.Panel-event-tabchange'> /**
370 </span> * @event tabchange
371 * Fires when a new tab has been activated (activated by {@link #setActiveTab}).
372 * @param {Ext.tab.Panel} tabPanel The TabPanel
373 * @param {Ext.Component} newCard The newly activated item
374 * @param {Ext.Component} oldCard The previously active item
378 me.callParent(arguments);
381 me.setActiveTab(activeTab);
382 //set the active tab after initial layout
383 me.on('afterlayout', me.afterInitialLayout, me, {single: true});
386 <span id='Ext-tab.Panel-method-afterInitialLayout'> /**
388 * We have to wait until after the initial layout to visually activate the activeTab (if set).
389 * The active tab has different margins than normal tabs, so if the initial layout happens with
390 * a tab active, its layout will be offset improperly due to the active margin style. Waiting
391 * until after the initial layout avoids this issue.
393 afterInitialLayout: function() {
395 card = me.getComponent(me.activeTab);
398 me.layout.setActiveItem(card);
402 <span id='Ext-tab.Panel-method-setActiveTab'> /**
403 </span> * Makes the given card active (makes it the visible card in the TabPanel's CardLayout and highlights the Tab)
404 * @param {Ext.Component} card The card to make active
406 setActiveTab: function(card) {
410 card = me.getComponent(card);
412 previous = me.getActiveTab();
414 if (previous && previous !== card && me.fireEvent('beforetabchange', me, card, previous) === false) {
418 me.tabBar.setActiveTab(card.tab);
421 me.layout.setActiveItem(card);
424 if (previous && previous !== card) {
425 me.fireEvent('tabchange', me, card, previous);
430 <span id='Ext-tab.Panel-method-getActiveTab'> /**
431 </span> * Returns the item that is currently active inside this TabPanel. Note that before the TabPanel first activates a
432 * child component this will return whatever was configured in the {@link #activeTab} config option
433 * @return {Ext.Component/Integer} The currently active item
435 getActiveTab: function() {
436 return this.activeTab;
439 <span id='Ext-tab.Panel-method-getTabBar'> /**
440 </span> * Returns the {@link Ext.tab.Bar} currently used in this TabPanel
441 * @return {Ext.TabBar} The TabBar
443 getTabBar: function() {
447 <span id='Ext-tab.Panel-method-onAdd'> /**
449 * Makes sure we have a Tab for each item added to the TabPanel
451 onAdd: function(item, index) {
454 item.tab = me.tabBar.insert(index, {
457 disabled: item.disabled,
458 closable: item.closable,
465 enable: me.onItemEnable,
466 disable: me.onItemDisable,
467 beforeshow: me.onItemBeforeShow,
468 iconchange: me.onItemIconChange,
469 titlechange: me.onItemTitleChange
473 if (me.removePanelHeader) {
474 item.preventHeader = true;
479 if (item.isPanel && me.border) {
480 item.setBorder(false);
484 // ensure that there is at least one active tab
485 if (this.rendered && me.items.getCount() === 1) {
490 <span id='Ext-tab.Panel-method-onItemEnable'> /**
492 * Enable corresponding tab when item is enabled.
494 onItemEnable: function(item){
498 <span id='Ext-tab.Panel-method-onItemDisable'> /**
500 * Disable corresponding tab when item is enabled.
502 onItemDisable: function(item){
506 <span id='Ext-tab.Panel-method-onItemBeforeShow'> /**
508 * Sets activeTab before item is shown.
510 onItemBeforeShow: function(item) {
511 if (item !== this.activeTab) {
512 this.setActiveTab(item);
517 <span id='Ext-tab.Panel-method-onItemIconChange'> /**
519 * Update the tab iconCls when panel iconCls has been set or changed.
521 onItemIconChange: function(item, newIconCls) {
522 item.tab.setIconCls(newIconCls);
523 this.getTabBar().doLayout();
526 <span id='Ext-tab.Panel-method-onItemTitleChange'> /**
528 * Update the tab title when panel title has been set or changed.
530 onItemTitleChange: function(item, newTitle) {
531 item.tab.setText(newTitle);
532 this.getTabBar().doLayout();
536 <span id='Ext-tab.Panel-method-doRemove'> /**
538 * If we're removing the currently active tab, activate the nearest one. The item is removed when we call super,
539 * so we can do preprocessing before then to find the card's index
541 doRemove: function(item, autoDestroy) {
544 <span id='Ext-tab.Panel-property-hasItemsLeft'> /**
545 </span> * At this point the item hasn't been removed from the items collection.
546 * As such, if we want to check if there are no more tabs left, we have to
547 * check for one, as opposed to 0.
549 hasItemsLeft = items.getCount() > 1;
551 if (me.destroying || !hasItemsLeft) {
553 } else if (item === me.activeTab) {
554 me.setActiveTab(item.next() || items.getAt(0));
556 me.callParent(arguments);
558 // Remove the two references
559 delete item.tab.card;
563 <span id='Ext-tab.Panel-method-onRemove'> /**
565 * Makes sure we remove the corresponding Tab when an item is removed
567 onRemove: function(item, autoDestroy) {
572 enable: me.onItemEnable,
573 disable: me.onItemDisable,
574 beforeshow: me.onItemBeforeShow
576 if (!me.destroying && item.tab.ownerCt == me.tabBar) {
577 me.tabBar.remove(item.tab);
581 </pre></pre></body></html>