mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Automatically expand menu section containing the active link
This commit is contained in:
parent
77dbf5c3f1
commit
feda63d6a7
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -205,22 +205,22 @@ class SideNav {
|
|||||||
* @param action Expand or Collapse
|
* @param action Expand or Collapse
|
||||||
*/
|
*/
|
||||||
private activateLink(link: HTMLDivElement, action: 'expand' | 'collapse'): void {
|
private activateLink(link: HTMLDivElement, action: 'expand' | 'collapse'): void {
|
||||||
// Find the closest .collapse element, which should contain `link`.
|
// Find the closest .dropdown-menu element, which should contain `link`.
|
||||||
const collapse = link.closest('.collapse') as Nullable<HTMLDivElement>;
|
const dropdownMenu = link.closest('.dropdown-menu') as Nullable<HTMLDivElement>;
|
||||||
if (isElement(collapse)) {
|
if (isElement(dropdownMenu)) {
|
||||||
// Find the closest `.nav-link`, which should be adjacent to the `.collapse` element.
|
// Find the closest `.nav-link`, which should be adjacent to the `.dropdown-menu` element.
|
||||||
const groupLink = collapse.parentElement?.querySelector('.nav-link');
|
const groupLink = dropdownMenu.parentElement?.querySelector('.nav-link');
|
||||||
if (isElement(groupLink)) {
|
if (isElement(groupLink)) {
|
||||||
groupLink.classList.add('active');
|
groupLink.classList.add('active');
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'expand':
|
case 'expand':
|
||||||
groupLink.setAttribute('aria-expanded', 'true');
|
groupLink.setAttribute('aria-expanded', 'true');
|
||||||
collapse.classList.add('show');
|
dropdownMenu.classList.add('show');
|
||||||
link.classList.add('active');
|
link.classList.add('active');
|
||||||
break;
|
break;
|
||||||
case 'collapse':
|
case 'collapse':
|
||||||
groupLink.setAttribute('aria-expanded', 'false');
|
groupLink.setAttribute('aria-expanded', 'false');
|
||||||
collapse.classList.remove('show');
|
dropdownMenu.classList.remove('show');
|
||||||
link.classList.remove('active');
|
link.classList.remove('active');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user