Fix active submenu items
Signed-off-by: hiba-aldalaty <hibaaldalaty@gmail.com>
This commit is contained in:
@@ -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}>
|
||||
|
||||
Reference in New Issue
Block a user