cferdinandi / tabby

Lightweight, accessible vanilla JS toggle tabs.
MIT License
602 stars 73 forks source link

Make Tabby Work with Anchor Links from Outside #121

Closed marcobardenheuer closed 3 years ago

marcobardenheuer commented 3 years ago

What about giving tabby extended anchor link support?

Example Use Case:

Allow tabs to be opened from anchor links which are not part of tabby. See forked Codepen here: Clicking the link <a href=#neville class=hero-link>More on Neville</a> should open the corresponding tab.

cferdinandi commented 3 years ago

Hi there, the toggle() method is perfect for this kind of use-case. Adding this to your code should do it.

// If there's a relevant hash, show the tab
if (window.location.hash) {
    tabs.toggle('#' + window.location.hash);
}
cferdinandi commented 3 years ago

Relevant link in the docs: https://github.com/cferdinandi/tabby#toggle