Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Argentini 19 posts 123 karma points
    Jun 12, 2019 @ 23:44
    Michael Argentini
    0

    Default open tab?

    Could you either default the topmost tab to being open, or allow for setting a default open tab"?

  • Simon Campbell 20 posts 326 karma points
    Jun 24, 2019 @ 07:38
    Simon Campbell
    0

    Hi Michael,

    Yes it should be possible to default the top tab to open, I will take a look.

  • Marc Love 298 posts 750 karma points
    Jun 25, 2019 @ 09:21
    Marc Love
    1

    If you replace the controller with this code the first tab will be open by default:

    angular.module('umbraco.services').config([
    '$httpProvider',
    function ($httpProvider) {
        $httpProvider.interceptors.push(function ($q, $location) {
            return {
                'response': function (response) {
                    if (response.config.url.includes('/umbraco/backoffice/UmbracoApi/Content/GetById')
                        || response.config.url.includes('umbraco/backoffice/UmbracoApi/Content/GetEmpty')) {
                        if (response.status === 200) {
                            window.setTimeout(function () {
                                var tabs = document.getElementsByClassName("umb-group-panel__header");
                                for (var i = 0; i < tabs.length; i++) {
                                    if (tabs[i].onclick == null) {
                                        tabs[i].onclick = function () {
                                            this.classList.toggle("open");
                                            this.nextElementSibling.classList.toggle("open");
                                        }
                                    }
                                }
                                tabs[0].classList.toggle("open");
                                tabs[0].nextElementSibling.classList.toggle("open");
                            }, 500)
                        }
                    }
                    return response;
                }
            };
        });
    }
    

    ]);

  • Michael Argentini 19 posts 123 karma points
    Jun 26, 2019 @ 15:06
    Michael Argentini
    0

    I tweaked the answer provided by Marc. Toggling the open status would sometimes make the first panel open then close again. This variation simply adds the open class.

    angular.module('umbraco.services').config([
        '$httpProvider',
        function ($httpProvider) {
            $httpProvider.interceptors.push(function ($q, $location) {
                return {
                    'response': function (response) {
                        if (response.config.url.includes('/umbraco/backoffice/UmbracoApi/Content/GetById')
                            || response.config.url.includes('umbraco/backoffice/UmbracoApi/Content/GetEmpty')) {
                            if (response.status === 200) {
                                window.setTimeout(function () {
                                    var tabs = document.getElementsByClassName("umb-group-panel__header");
                                    for (var i = 0; i < tabs.length; i++) {
                                        if (tabs[i].onclick == null) {
                                            tabs[i].onclick = function () {
                                                this.classList.toggle("open");
                                                this.nextElementSibling.classList.toggle("open");
                                            }
                                        }
                                    }
                                    tabs[0].classList.add("open");
                                    tabs[0].nextElementSibling.classList.add("open");
                                }, 500)
                            }
                        }
                        return response;
                    }
                };
            });
        }
    ]);
    
  • Simon Campbell 20 posts 326 karma points
    Jun 27, 2019 @ 15:12
    Simon Campbell
    100

    I've uploaded a new version which now defaults the first tab to open.

    Please can you mark this as answered / closed?

  • Michael Argentini 19 posts 123 karma points
    Jun 29, 2019 @ 23:34
    Michael Argentini
    0

    I discovered that the component sometimes throws an angular exception in the console regarding classList not being available. This only happens when editing document types. So I added a couple checks to prevent it from firing in that scenario.

    Inside the window.setTimeout, use this block instead:

    var tabs = document.getElementsByClassName("umb-group-panel__header");
    if (tabs) {
        for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].onclick == null) {
                tabs[i].onclick = function () {
                    this.classList.toggle("open");
                    this.nextElementSibling.classList.toggle("open");
                }
            }
        }
        if (tabs[0]) {
            tabs[0].classList.add("open");
            tabs[0].nextElementSibling.classList.add("open");
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft