Comments (6)
That’s a great idea. Thank you @evandiamond! I’ll look into how to add this over the next days.
from a11y-accordion-tabs.
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.
I'd love to see this too.
from a11y-accordion-tabs.
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.
Any updates on this feature? Would be love to see it as other elements working great.
from a11y-accordion-tabs.
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)
- Is JS needed ? HOT 1
- Any benefit to this compared to pure HTML/CSS solutions? HOT 1
- Uncaught ReferenceError: _ is not defined HOT 2
- tabs to no effect
- Can you support using data attributes? HOT 1
- Any particular reason Accordion is misspelled as accordeon? HOT 1
- Support for multiple a11y tabs in the same page, parent tabs loaded when child tabs are clicked HOT 4
- Tabs start expanded with accordion start collapsed? HOT 2
- Stop playing videos when changing a tab
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from a11y-accordion-tabs.