View Full Version : [FIXED-740][3.x] Button loses anchoring after setText

Stefan B
17 Mar 2010, 2:56 AM
Ext.Button's doAutoWidth method does not account for anchoring.
When it's called after changing the text on a button, anchoring gets lost in favour of automatic adjusting the width to the text length:

Ext.onReady(function() {

var p = new Ext.Panel({
width: 500,
layout: "anchor",
items: [{
xtype: "button",
text: "Original text",
anchor: "0"
renderTo: Ext.getBody()

(function() {
p.items.first().setText("Changed text");


Notice the button width changing with the new text after 2 seconds.

This behaviour is browser independent.

The override I use is simple but assumes that an anchor on a button always refers to its width, so a solid fix should parse the anchor first:

Ext.Button.prototype.doAutoWidth = Ext.Button.prototype.doAutoWidth.createInterceptor(function() {
if (this.anchor) return false;

17 Mar 2010, 3:07 AM
You're quite correct. It's not just anchor either, the same behaviour is demonstrated using a hbox/fit layout.

31 Mar 2010, 12:46 AM
It's difficult to come up with a generic solution for it to automatically detect, so I've changed the behaviour so if autoWidth === false, the button won't autoSize.

More details in rev 6417.