Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / layout / component / field / Trigger.js
1 /**
2  * @private
3  * @class Ext.layout.component.field.Trigger
4  * @extends Ext.layout.component.field.Field
5  * Layout class for {@link Ext.form.field.Trigger} fields. Adjusts the input field size to accommodate
6  * the trigger button(s).
7  * @private
8  */
9
10 Ext.define('Ext.layout.component.field.Trigger', {
11
12     /* Begin Definitions */
13
14     alias: ['layout.triggerfield'],
15
16     extend: 'Ext.layout.component.field.Field',
17
18     /* End Definitions */
19
20     type: 'triggerfield',
21
22     sizeBodyContents: function(width, height) {
23         var me = this,
24             owner = me.owner,
25             inputEl = owner.inputEl,
26             triggerWrap = owner.triggerWrap,
27             triggerWidth = owner.getTriggerWidth();
28
29         // If we or our ancestor is hidden, we can get a triggerWidth calculation
30         // of 0.  We don't want to resize in this case.
31         if (owner.hideTrigger || owner.readOnly || triggerWidth > 0) {
32             // Decrease the field's width by the width of the triggers. Both the field and the triggerWrap
33             // are floated left in CSS so they'll stack up side by side.
34             me.setElementSize(inputEl, Ext.isNumber(width) ? width - triggerWidth : width);
35     
36             // Explicitly set the triggerWrap's width, to prevent wrapping
37             triggerWrap.setWidth(triggerWidth);
38         }
39     }
40 });