Fix active submenu items

Signed-off-by: hiba-aldalaty <hibaaldalaty@gmail.com>
This commit is contained in:
hiba-aldalaty
2021-12-06 11:33:00 +00:00
parent 884c451191
commit 2c17e5b073
2 changed files with 12 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/core-components': patch
---
Bug fix - items in sidebar submenu are only active when full path is active (including search parameters)
@@ -116,14 +116,13 @@ export type SidebarSubmenuItemProps = {
export const SidebarSubmenuItem = (props: SidebarSubmenuItemProps) => {
const { title, to, icon: Icon, dropdownItems } = props;
const classes = useStyles();
const { pathname: locationPathname } = useLocation();
const { pathname: toPathname } = useResolvedPath(to);
const { pathname: locationPathname, search: locationSearch } = useLocation();
const { pathname: toPathname, search: toSearch } = useResolvedPath(to ?? '');
const { setIsHoveredOn } = useContext(SidebarItemWithSubmenuContext);
const closeSubmenu = () => {
setIsHoveredOn(false);
};
let isActive = locationPathname === toPathname;
let isActive = locationPathname === toPathname && toSearch === locationSearch;
const [showDropDown, setShowDropDown] = useState(false);
const handleClickDropdown = () => {
@@ -132,7 +131,10 @@ export const SidebarSubmenuItem = (props: SidebarSubmenuItemProps) => {
if (dropdownItems !== undefined) {
dropdownItems.some(item => {
const resolvedPath = resolvePath(item.to);
isActive = locationPathname === resolvedPath.pathname;
isActive =
locationPathname === resolvedPath.pathname &&
locationSearch === toSearch;
return isActive;
});
return (
<div className={classes.itemContainer}>