3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
18 * @extends Ext.button.Button
20 * <p>Represents a single Tab in a {@link Ext.tab.Panel TabPanel}. A Tab is simply a slightly customized {@link Ext.button.Button Button},
21 * styled to look like a tab. Tabs are optionally closable, and can also be disabled. Typically you will not
22 * need to create Tabs manually as the framework does so automatically when you use a {@link Ext.tab.Panel TabPanel}</p>
24 Ext.define('Ext.tab.Tab', {
25 extend: 'Ext.button.Button',
29 'Ext.layout.component.Tab',
33 componentLayout: 'tab',
37 baseCls: Ext.baseCSSPrefix + 'tab',
40 * @cfg {String} activeCls
41 * The CSS class to be applied to a Tab when it is active.
42 * Providing your own CSS for this class enables you to customize the active state.
47 * @cfg {String} disabledCls
48 * The CSS class to be applied to a Tab when it is disabled.
52 * @cfg {String} closableCls
53 * The CSS class which is added to the tab when it is closable
55 closableCls: 'closable',
58 * @cfg {Boolean} closable True to make the Tab start closable (the close icon will be visible).
63 * @cfg {String} closeText
64 * The accessible text label for the close button link; only used when {@link #closable} = true.
66 closeText: 'Close Tab',
69 * @property {Boolean} active
70 * Read-only property indicating that this tab is currently active. This is NOT a public configuration.
77 * True if the tab is currently closable
84 initComponent: function() {
90 * Fired when the tab is activated.
91 * @param {Ext.tab.Tab} this
97 * Fired when the tab is deactivated.
98 * @param {Ext.tab.Tab} this
104 * Fires if the user clicks on the Tab's close button, but before the {@link #close} event is fired. Return
105 * false from any listener to stop the close event being fired
106 * @param {Ext.tab.Tab} tab The Tab object
112 * Fires to indicate that the tab is to be closed, usually because the user has clicked the close button.
113 * @param {Ext.tab.Tab} tab The Tab object
118 me.callParent(arguments);
128 onRender: function() {
130 tabBar = me.up('tabbar'),
131 tabPanel = me.up('tabpanel');
133 me.addClsWithUI(me.position);
135 // Set all the state classNames, as they need to include the UI
136 // me.disabledCls = me.getClsWithUIs('disabled');
140 // Propagate minTabWidth and maxTabWidth settings from the owning TabBar then TabPanel
142 me.minWidth = (tabBar) ? tabBar.minTabWidth : me.minWidth;
143 if (!me.minWidth && tabPanel) {
144 me.minWidth = tabPanel.minTabWidth;
146 if (me.minWidth && me.iconCls) {
151 me.maxWidth = (tabBar) ? tabBar.maxTabWidth : me.maxWidth;
152 if (!me.maxWidth && tabPanel) {
153 me.maxWidth = tabPanel.maxTabWidth;
157 me.callParent(arguments);
163 me.syncClosableElements();
165 me.keyNav = Ext.create('Ext.util.KeyNav', me.el, {
166 enter: me.onEnterKey,
173 enable : function(silent) {
176 me.callParent(arguments);
178 me.removeClsWithUI(me.position + '-disabled');
184 disable : function(silent) {
187 me.callParent(arguments);
189 me.addClsWithUI(me.position + '-disabled');
197 onDestroy: function() {
201 me.closeEl.un('click', Ext.EventManager.preventDefault);
205 Ext.destroy(me.keyNav);
208 me.callParent(arguments);
212 * Sets the tab as either closable or not
213 * @param {Boolean} closable Pass false to make the tab not closable. Otherwise the tab will be made closable (eg a
214 * close button will appear on the tab)
216 setClosable: function(closable) {
219 // Closable must be true if no args
220 closable = (!arguments.length || !!closable);
222 if (me.closable != closable) {
223 me.closable = closable;
225 // set property on the user-facing item ('card'):
227 me.card.closable = closable;
233 me.syncClosableElements();
235 // Tab will change width to accommodate close icon
236 me.doComponentLayout();
238 me.ownerCt.doLayout();
245 * This method ensures that the closeBtn element exists or not based on 'closable'.
248 syncClosableElements: function () {
253 me.closeEl = me.el.createChild({
255 cls: me.baseCls + '-close-btn',
257 // html: me.closeText, // removed for EXTJSIV-1719, by rob@sencha.com
259 }).on('click', Ext.EventManager.preventDefault); // mon ???
262 var closeEl = me.closeEl;
264 closeEl.un('click', Ext.EventManager.preventDefault);
272 * This method ensures that the UI classes are added or removed based on 'closable'.
275 syncClosableUI: function () {
276 var me = this, classes = [me.closableCls, me.closableCls + '-' + me.position];
279 me.addClsWithUI(classes);
281 me.removeClsWithUI(classes);
286 * Sets this tab's attached card. Usually this is handled automatically by the {@link Ext.tab.Panel} that this Tab
287 * belongs to and would not need to be done by the developer
288 * @param {Ext.Component} card The card to set
290 setCard: function(card) {
294 me.setText(me.title || card.title);
295 me.setIconCls(me.iconCls || card.iconCls);
300 * Listener attached to click events on the Tab's close button
302 onCloseClick: function() {
305 if (me.fireEvent('beforeclose', me) !== false) {
307 if (me.tabBar.closeTab(me) === false) {
308 // beforeclose on the panel vetoed the event, stop here
312 // if there's no tabbar, fire the close event
313 me.fireEvent('close', me);
319 * Fires the close event on the tab.
322 fireClose: function(){
323 this.fireEvent('close', this);
329 onEnterKey: function(e) {
333 me.tabBar.onClick(e, me.el);
340 onDeleteKey: function(e) {
349 activate : function(supressEvent) {
353 me.addClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
355 if (supressEvent !== true) {
356 me.fireEvent('activate', me);
361 deactivate : function(supressEvent) {
365 me.removeClsWithUI([me.activeCls, me.position + '-' + me.activeCls]);
367 if (supressEvent !== true) {
368 me.fireEvent('deactivate', me);