Retained tab state using location hash (#161)

This commit is contained in:
Kieran
2024-04-03 11:05:49 -07:00
committed by GitHub
parent 79c61bca4f
commit 3b1c1692fb
4 changed files with 27 additions and 3 deletions
+20
View File
@@ -0,0 +1,20 @@
window.setTabIndex = (index) => {
window.location.hash = `tab-${index}`
return index
}
// The conditionals and currIndex stuff ensures that
// the tab index is always set to 0 if the hash is empty
// AND other hash values are ignored
window.getTabIndex = (currIndex) => {
if (window.location.hash === '' || window.location.hash === '#') {
return 0
}
if (window.location.hash.startsWith('#tab-')) {
return parseInt(window.location.hash.replace('#tab-', ''))
}
return currIndex
}