react-sidenav icon indicating copy to clipboard operation
react-sidenav copied to clipboard

Unfold top level nav based on path

Open tudro opened this issue 7 years ago • 4 comments

Hi, is it possible to show the sub nav item based on the path? If i got to URL/x, the 'x' nav item is highlighted, but if i go to URL/x/y then i can't see the 'y' sub nav item, because 'x' is not unfolded. Thank you

tudro avatar May 10 '18 12:05 tudro

@tudro this is a confirmed bug. will get this fixed

wmira avatar May 10 '18 15:05 wmira

Thank you. I must have skipped it when i looked through the issues.

tudro avatar May 10 '18 15:05 tudro

Any news on this?

lucasconstantino avatar May 22 '19 00:05 lucasconstantino

Here goes a patch-package for that.

diff --git a/node_modules/react-sidenav/NavGroup.js b/node_modules/react-sidenav/NavGroup.js
index 40b9620..9e6530f 100644
--- a/node_modules/react-sidenav/NavGroup.js
+++ b/node_modules/react-sidenav/NavGroup.js
@@ -95,9 +95,18 @@ var ToggleIndicator = function (props) {
     return (React.createElement("div", { style: __assign({}, ToggleIndicatorStyle, { transform: transform }) },
         React.createElement(ChildrenIndicatorIcon, null)));
 };
+
+var useChildSelected = () => {
+    var selectedPath = React.useContext(_1.SideNavContext).selectedPath;
+    var pathId = React.useContext(_1.NavContext).pathId;
+
+    return selectedPath !== pathId && selectedPath.indexOf(pathId) === 0
+}
+
 exports.NavGroup = function (props) {
     var children = props.children, onClick = props.onClick, others = __rest(props, ["children", "onClick"]);
-    var _a = React.useState(NavGroupState.collapsed), state = _a[0], setState = _a[1];
+    var childSelected = useChildSelected()
+    var _a = React.useState(childSelected ? NavGroupState.expanded : NavGroupState.collapsed), state = _a[0], setState = _a[1];
     var rootRef = React.useRef(null);
     var onHandleClick = function (e) {
         if (e) {

lucasconstantino avatar May 22 '19 00:05 lucasconstantino