Code Monkey home page Code Monkey logo

Comments (6)

matthiasott avatar matthiasott commented on June 5, 2024 1

That’s a great idea. Thank you @evandiamond! I’ll look into how to add this over the next days.

from a11y-accordion-tabs.

jacobaarnold avatar jacobaarnold commented on June 5, 2024 1

I ended up doing something quite similar using jQuery:

$(".js-tabs").each(function (index) {
    var targetTab = 0;
    
    if (window.location.hash) {
        var hash = window.location.hash.substring(1);
        $(this).find('.js-tabs-panel').each(function (i) {
            if ($(this).attr('id') == hash) {
                targetTab = i;
            }
        });
    }

    new AccordionTabs(this, {
        breakpoint: 640,
        tabsAllowed: true,
        selectedTab: targetTab,
        startCollapsed: false
    });
});

from a11y-accordion-tabs.

StephanieF avatar StephanieF commented on June 5, 2024

I'd love to see this too.

from a11y-accordion-tabs.

jacobaarnold avatar jacobaarnold commented on June 5, 2024

Same here! I was hoping I could programmatically click() on one of the .js-tab-trigger anchors, but it doesn't seem to work.

from a11y-accordion-tabs.

jane-tif avatar jane-tif commented on June 5, 2024

Any updates on this feature? Would be love to see it as other elements working great.

from a11y-accordion-tabs.

iamrobert avatar iamrobert commented on June 5, 2024

Here's a quick and dirty approach that I have got it working for tabs:

1. Add Hash to URL on click

At the bottom of:
AccordionTabs.prototype._clickEvent = function (e) {

        //ADD HASH TO URL
        if (!this.isAccordion) {
            var getHash = new URL(e.target);

            history.replaceState(null, '', getHash.hash);
        }

        if (this.isAccordion) {
            history.replaceState(null, '', '#' + closestTrigger.getAttribute('aria-controls'));
        }

2. Set the tab to load by setting the data.selectedTab

at the bottom of: function AccordionTabs(el, options) { before

       // get Hash From URL 
       var URLhash = new URL(document.URL).hash;
       URLhash = URLhash.replace('#', '');

       if (URLhash) {

           // get all tabSections
           var tabSections = document.querySelectorAll("section.tabs-panel");

           // initialize a counter variable
           var count = 0;

           // iterate through the elements to find the one with the specified URLhash
           for (var i = 0; i < tabSections.length; i++) {
               var tabSection = tabSections[i];

               if (tabSection.id === URLhash) {
                   // increment the counter if the ID matches

                   count = i;
               }

           }
           // log the final count
           this.options.selectedTab = count;
       }

3. Here's the complete JS script:
https://gist.github.com/iamrobert/ae7fd738151e909f351adce0393d05fc

from a11y-accordion-tabs.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.