Skip to content

Commit 60d0299

Browse files
committed
checks if url is substring of path for root items
1 parent 69dbf01 commit 60d0299

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

menu_generator/menu.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,20 @@ def _get_url(self, item_dict):
7878

7979
def _is_selected(self, item_dict):
8080
"""
81-
Given a menu item dictionary, it returns true if `url` is on path.
81+
Given a menu item dictionary, it returns true if `url` is on path,
82+
unless the item is marked as a root, in which case returns true if `url` is part of path.
8283
"""
8384
url = self._get_url(item_dict)
84-
return url == self.path
85+
if self._is_root(item_dict):
86+
return url in self.path
87+
else:
88+
return url == self.path
89+
90+
def _is_root(self, item_dict):
91+
"""
92+
Given a menu item dictionary, it returns true if item is marked as a `root`.
93+
"""
94+
return item_dict.get('root', False)
8595

8696
def _process_breadcrums(self, menu_list):
8797
"""

0 commit comments

Comments
 (0)