1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    5
    Vote Rating
    0
    arbarrett is on a distinguished road

      0  

    Exclamation Vertical toolbar not resizing when changing button text

    Vertical toolbar not resizing when changing button text


    Using the code below, I can click on Button 1 and it shortens the text on each button on the vertical toolbar. This correctly makes the toolbar thinner the first time it is clicked. When clicked a second time it expands the text again. This also works. However after clicking again (and thereafter) to shorten the text, it doesn't make the buttons or toolbar thinner. I would be grateful for any assistance on how to get it to work. Thanks.

    index.html:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    
    <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>My App</title>
            <link rel="stylesheet" type="text/css" href="/tools/extjs4/resources/css/ext-all-gray.css" />
            <script type="text/javascript" src="/tools/extjs4/bootstrap.js"></script>
            <script type="text/javascript" src="js/app.js"></script>
    </head>
    
    
    <body>
    </body>
    
    
    </html>
    js/app.js:
    Code:
    Ext.require([
            'Ext.container.*',
            'Ext.panel.*',
            'Ext.toolbar.*',
            'Ext.button.*'
    ]);
    
    
    Ext.onReady(function() {
            Ext.create('Ext.container.Viewport', {
                    layout: 'border',
                    items: [{
                            region: 'center',
                            xtype: 'panel',
                            dockedItems: [{
                                    xtype: 'toolbar',
                                    dock: 'left',
                                    defaults: {
                                            textAlign: 'left'
                                    },
                                    items: [{
                                            text: 'Button 1',
                                            handler: function() {
                                                    if (this.getText() == 'B 1') {
                                                            this.setText('Button 1');
                                                            Ext.getCmp('b2').setText('Button 2');
                                                    } else {
                                                            this.setText('B 1');
                                                            Ext.getCmp('b2').setText('B 2');
                                                    }
                                                    this.ownerCt.ownerCt.forceComponentLayout();
                                            }
                                    },
                                    {
                                            id: 'b2',
                                            text: 'Button 2'
                                    }]
                            }]
                    }]
            });
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,548
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I can reproduce this on 4.0.7 but 4.1.0 beta 1 is acting as expected with resizing the width after numerous clicks on the first button.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    5
    Vote Rating
    0
    arbarrett is on a distinguished road

      0  

    Smile yes fixed thanks, though some other issues

    yes fixed thanks, though some other issues


    Thanks Mitchell. I have now downloaded 4.1.0 beta 1 and it has fixed the issue.


    Some related issues to note though are:
    • separators in the toolbar prevent the toolbar from resizing. I have tried calling doComponentLayout and forceComponentLayout on the separator which didn't help. Currently I am calling setWidth to achieve the result which is not ideal, as I want the width to be automatic.
    • setting a toolbar button's text to empty string results in the button icon losing its vertical centering. I have overcome this with css.
    • bootstrap.js seems to be missing from 4.1.0 beta 1, so I copied over the 4.0.7 version and it worked.
    • button textAlign now seems to be ignored in 4.1.0 beta 1, but was working in 4.0.7. I have overcome this using css, but thought I would mention it.
    btw, what I am really using this code for is to allow labels to be placed to the right of icons on a vertical toolbar, which can then be hidden to create extra room. I preferred this to just tooltips for 2 reasons: 1) tooltips are not very practical for touch screens, 2) it is faster and easier to scan the eye over all toolbar items at once to read what the icons do (for new, infrequent or forgetful users).

Thread Participants: 1

Tags for this Thread