New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab Widget does not set class "ui-btn-active" for the initially opened tab #7407

Closed
thenewguy opened this Issue May 15, 2014 · 3 comments

Comments

Projects
None yet
3 participants
@thenewguy

thenewguy commented May 15, 2014

On page load the tab widget opens the first tab by default but it does not set the active class for this tab. See http://demos.jquerymobile.com/1.4.2/tabs/

You have to click the initially opened tab in order for it to highlight blue even though it is already opened

@thenewguy

This comment has been minimized.

Show comment
Hide comment
@thenewguy

thenewguy May 15, 2014

I posted this as a workaround but then I realized it isn't quite complete yet. The following sets the first tab as active, but when you click another tab both tabs are highlighted blue. It takes a third click to only have one selected tab.

(function($) {
    $(document).on('pagecontainerbeforeshow', function() {
        var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
        $('[data-role="tabs"] a:first', activePage).each(function(){
            $(this).click();
        });
    });
})(jQuery);

thenewguy commented May 15, 2014

I posted this as a workaround but then I realized it isn't quite complete yet. The following sets the first tab as active, but when you click another tab both tabs are highlighted blue. It takes a third click to only have one selected tab.

(function($) {
    $(document).on('pagecontainerbeforeshow', function() {
        var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
        $('[data-role="tabs"] a:first', activePage).each(function(){
            $(this).click();
        });
    });
})(jQuery);
@thenewguy

This comment has been minimized.

Show comment
Hide comment
@thenewguy

thenewguy May 15, 2014

This seems to do the trick for me now. I didn't account for tab links not being in the first ul or tabs with multiple anchors if that is a possibility.

// workaround for the default tab not being visually identified as active
// see: https://github.com/jquery/jquery-mobile/issues/7407 
(function($) {
    $(document).on('pagecontainerbeforeshow', function() {
        var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
        $('[data-role="tabs"] ul:first', activePage).each(function(){
            var ul = this;
            var as = $('a', ul);
            $(as).click(function(){
                $(as).removeClass('ui-btn-active');
                $(this).addClass('ui-btn-active');
            });
            $(as).first().click();
        });
    });
})(jQuery);

thenewguy commented May 15, 2014

This seems to do the trick for me now. I didn't account for tab links not being in the first ul or tabs with multiple anchors if that is a possibility.

// workaround for the default tab not being visually identified as active
// see: https://github.com/jquery/jquery-mobile/issues/7407 
(function($) {
    $(document).on('pagecontainerbeforeshow', function() {
        var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
        $('[data-role="tabs"] ul:first', activePage).each(function(){
            var ul = this;
            var as = $('a', ul);
            $(as).click(function(){
                $(as).removeClass('ui-btn-active');
                $(this).addClass('ui-btn-active');
            });
            $(as).first().click();
        });
    });
})(jQuery);
@psyclone241

This comment has been minimized.

Show comment
Hide comment
@psyclone241

psyclone241 Dec 21, 2014

Very nice workaround @thenewguy! A nice, simple fix to yet another odd issue in jqueryui mobile. Thank you, much appreciated!

psyclone241 commented Dec 21, 2014

Very nice workaround @thenewguy! A nice, simple fix to yet another odd issue in jqueryui mobile. Thank you, much appreciated!

@apsdehal apsdehal self-assigned this Jun 6, 2016

@apsdehal apsdehal added this to the 1.5.0 milestone Jun 6, 2016

apsdehal added a commit to apsdehal/jquery-mobile that referenced this issue Jun 28, 2016

@apsdehal apsdehal closed this Jun 30, 2016

arschmitz added a commit to arschmitz/jquery-mobile that referenced this issue Jul 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment