Skip to content

update script to highlight the reference tab if active #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions material-overrides/assets/stylesheets/wormhole.css
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,23 @@
}

/* --- To better handle page reloads and minimize flickering */
:not(.js-loading) .md-nav {
:not(.js-loading) .md-nav,
:not(.js-loading) .md-tabs__list {
opacity: 1;
}

.js-loading nav.md-nav {
.js-loading nav.md-nav,
.js-loading .md-tabs__list {
display: none !important;
}

.nav__item--section:not(.expanded) > nav.md-nav {
display: none;
}

.md-header--shadow {
min-height: 107px;
}
/* --- */

.nav__item--section
Expand Down
25 changes: 25 additions & 0 deletions material-overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,34 @@
});
}

getTopNavigationState = () => {
const path = window.location.pathname;
// If on a reference page, highlight the reference top level nav item
if (path.includes('products/reference')) {
const tabs = document.querySelectorAll('.md-tabs__item');

tabs.forEach(tab => {
// Remove the active class from the active tab
if (tab.classList.contains('md-tabs__item--active')) {
tab.classList.remove('md-tabs__item--active');
}

// Add the active class to the tab that contains 'Reference'
if (tab.children[0].innerText.includes('Reference')) {
tab.classList.add('md-tabs__item--active');
}
});
}
}

document.addEventListener('DOMContentLoaded', () => {
// Handle left navigation state
document.querySelectorAll('.nav__item--section').forEach(setupSection);
applyInitialState();

// Handle top navigation state
getTopNavigationState();

document.documentElement.classList.remove('js-loading');
});

Expand Down