Skip to content

Commit

Permalink
bug correction
Browse files Browse the repository at this point in the history
  • Loading branch information
snmln committed Dec 19, 2024
1 parent df72331 commit 72575ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const createDynamicNavMenuList = (
isOpen?: boolean[],
setIsOpen?: SetState<boolean[]>
): JSX.Element[] => {
const setDropDownState = () => {
if (isOpen !== undefined && setIsOpen !== undefined) {
return setIsOpen(() => isOpen.fill(false));
}
};
return navItems.map((item, index) => {
switch (item.type) {
case NavItemType.DROPDOWN:
Expand All @@ -23,7 +28,8 @@ export const createDynamicNavMenuList = (
isOpen,
setIsOpen,
index,
linkProperties
linkProperties,
setDropDownState
}}
/>
);
Expand All @@ -32,10 +38,15 @@ export const createDynamicNavMenuList = (
return <NavItemInternalLink {...{ item, linkProperties }} />;

case NavItemType.EXTERNAL_LINK:
return <NavItemExternalLink item={item} />;
return (
<NavItemExternalLink
item={item}
setDropDownState={setDropDownState}
/>
);

case NavItemType.ACTION:
return <NavItemCTA item={item} />;
return <NavItemCTA item={item} setDropDownState={setDropDownState} />;

default:
return <></>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ interface NavDropDownButtonProps {
setIsOpen: SetState<boolean[]>;
index: number;
linkProperties: LinkProperties;
setDropDownState: () => void;
}

export const NavDropDownButton = ({
item,
isOpen,
setIsOpen,
index,
linkProperties
linkProperties,
setDropDownState
}: NavDropDownButtonProps) => {
const onToggle = (index: number, setIsOpen: SetState<boolean[]>): void => {
setIsOpen((prevIsOpen) => {
Expand Down Expand Up @@ -47,6 +49,7 @@ export const NavDropDownButton = ({
items={submenuItems}
isOpen={isOpen[index]}
id={`${item.id}-dropdown`}
onClick={setDropDownState()}
/>
</React.Fragment>
);
Expand Down

0 comments on commit 72575ff

Please sign in to comment.