Skip to content

Commit

Permalink
fix(VerticalNavigation): open slider where item is selected (#3389)
Browse files Browse the repository at this point in the history
* fix(VerticalNavigation): open the vertical navigation in the panel according to the selected item

* chore: change loadash import
  • Loading branch information
HQFOX committed Jun 1, 2023
1 parent 8183adf commit bdae374
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { StyledNav } from "./Navigation.styles";
import { HvVerticalNavigationSlider } from "..";
import { VerticalNavigationContext } from "../VerticalNavigationContext";
import { HvVerticalNavigationPopup } from "../NavigationPopup/NavigationPopup";
import { getParentItemById } from "../NavigationSlider/utils/NavigationSlider.utils";

export type NavigationData<T extends React.ElementType = "a"> =
ComponentProps<T> &
Expand Down Expand Up @@ -179,6 +180,7 @@ export const HvVerticalNavigationTree = ({
slider,

parentItem,
setParentItem,
withParentData,
navigateToChildHandler,

Expand Down Expand Up @@ -284,6 +286,17 @@ export const HvVerticalNavigationTree = ({
if (setParentData) setParentData(data);
}, [data]);

useEffect(() => {
if (
withParentData &&
selected &&
setParentItem &&
getParentItemById(withParentData, selected)
) {
setParentItem(getParentItemById(withParentData, selected));
}
}, [withParentData]);

// navigation slider
const navigateToTargetHandler = (event, selectedItem) => {
handleChange(event, selectedItem.id, selectedItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const HvVerticalNavigation = ({
setHeaderTitle,

parentItem,
setParentItem,
withParentData,
navigateToChildHandler,
navigateToParentHandler,
Expand All @@ -150,6 +151,7 @@ export const HvVerticalNavigation = ({
headerTitle,
setHeaderTitle,
parentItem,
setParentItem,
withParentData,
navigateToChildHandler,
navigateToParentHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface VerticalNavigationContextValue {
setHeaderTitle?: React.Dispatch<React.SetStateAction<string | undefined>>;

parentItem?;
setParentItem?: React.Dispatch<React.SetStateAction<any>>;
withParentData?;
navigateToChildHandler?: (event, item) => void;
navigateToParentHandler?: () => void;
Expand Down

0 comments on commit bdae374

Please sign in to comment.