Skip to content

Commit

Permalink
[docs] refactor: Improve sidebar item handling in handleMenuClick
Browse files Browse the repository at this point in the history
In the handleMenuClick function, the logic has been updated to handle different types of sidebar items more effectively. The function now distinguishes between dropdown items, header links, and regular sidebar items. Dropdown items and header links with href="#" are prevented from closing the sidebar. Additionally, header links that are not part of the sidebar now scroll to the top instead of collapsing the sidebar.
  • Loading branch information
Visual1mpact committed Oct 10, 2023
1 parent b23dd35 commit 892ef63
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/docsify-sidebar-collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
var newActiveNode = findTagParent(e.target, "LI", 2);
if (!newActiveNode) return;

// Check if the clicked item is a dropdown item
var isDropdownItem = !e.target.href || e.target.href === "#";
var isHeader = e.target.tagName === "A";

if (isDropdownItem || (isHeader && e.target.getAttribute("href") === "#")) {
// Prevent closing the sidebar for dropdown items
e.stopPropagation();
}

if (newActiveNode.classList.contains("open")) {
newActiveNode.classList.remove("open"); // docsify 默认行为会操作 collapse,我们异步之后修补

Expand Down

0 comments on commit 892ef63

Please sign in to comment.