Skip to content
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

fix(leftnavtree): highlight nav item for tabbed pages #1506

Merged
merged 1 commit into from
Sep 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// branch node with more than 1 leaf nodes
if (item.pages && item.pages.length > 1) {
item.isBranch = true;
item.pages.forEach((SubNavItem, i) => assignNodeType(SubNavItem));

Check warning on line 29 in packages/gatsby-theme-carbon/src/components/LeftNav/LeftNavTree.js

View workflow job for this annotation

GitHub Actions / validate-and-build

'i' is defined but never used. Allowed unused args must match /res|next|^err|^_/u
}
// if it is branch node with only one leaf node, convert it to a leaf node
else if (item.pages && item.pages.length) {
Expand Down Expand Up @@ -79,10 +79,25 @@
[activePath]
);

const isTabActive = useCallback(
(node) => {
const pathname = removeHashAndQuery(activePath);
const isActive =
`${node.path?.split('/')[1]}/${node.path?.split('/')[2]}` ===
`${pathname.split('/')[1]}/${pathname.split('/')[2]}`;

return isActive;
},
[activePath]
);

useEffect(() => {
const activeNode = dfs(itemNodes, isTreeNodeActive);
let activeNode = dfs(itemNodes, isTreeNodeActive);
if (!activeNode) {
activeNode = dfs(itemNodes, isTabActive);
}
setTreeActiveItem(activeNode);
}, [isTreeNodeActive, itemNodes]);

Check warning on line 100 in packages/gatsby-theme-carbon/src/components/LeftNav/LeftNavTree.js

View workflow job for this annotation

GitHub Actions / validate-and-build

React Hook useEffect has a missing dependency: 'isTabActive'. Either include it or remove the dependency array

const isTreeNodeExpanded = (node) =>
!!dfs([node], (evalNode) =>
Expand Down Expand Up @@ -153,6 +168,6 @@
),
};

const areEqual = (prevProps, nextProps) => true;

Check warning on line 171 in packages/gatsby-theme-carbon/src/components/LeftNav/LeftNavTree.js

View workflow job for this annotation

GitHub Actions / validate-and-build

'prevProps' is defined but never used. Allowed unused args must match /res|next|^err|^_/u

export default memo(LeftNavTree, areEqual);
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10595,7 +10595,7 @@ __metadata:
dependencies:
"@carbon/icons-react": "npm:^11.43.0"
gatsby: "npm:^5.13.6"
gatsby-theme-carbon: "npm:^4.0.6"
gatsby-theme-carbon: "npm:^4.0.7"
react: "npm:^18.3.1"
react-dom: "npm:^18.3.1"
languageName: unknown
Expand Down Expand Up @@ -11905,7 +11905,7 @@ __metadata:
languageName: unknown
linkType: soft

"gatsby-theme-carbon@npm:^4.0.6, gatsby-theme-carbon@workspace:packages/gatsby-theme-carbon":
"gatsby-theme-carbon@npm:^4.0.7, gatsby-theme-carbon@workspace:packages/gatsby-theme-carbon":
version: 0.0.0-use.local
resolution: "gatsby-theme-carbon@workspace:packages/gatsby-theme-carbon"
dependencies:
Expand Down
Loading