feat: change tab when URL hash matches one of the tabs

Added an event listener to watch for hash change after the page is loaded.
If the hash matches a tabber tab, it will emit a tab click to switch the tab.

Closes: #150
This commit is contained in:
alistair3149 2024-07-03 13:26:10 -04:00
parent d453adde07
commit 421c42b6f0
No known key found for this signature in database

View file

@ -680,9 +680,16 @@ async function load( tabberEls ) {
await tabberBuilder.init( urlHash );
} ) );
// Delay animation execution so it doesn't not animate the tab gets into position on load
setTimeout( () => {
// Delay animation execution so it doesn't not animate the tab gets into position on load
TabberAction.toggleAnimation( true );
window.addEventListener( 'hashchange', () => {
const newHash = window.location.hash.slice( 1 );
const tab = document.getElementById( `tab-${ CSS.escape( newHash ) }` );
if ( tab ) {
tab.click();
}
} );
}, 250 );
}