Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Side menu stays open after selecting a menu item on mobile #1195

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ui/snippets/header/Burger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ const Burger = () => {
/>
) : <Box boxSize={ 9 }/> }
</Flex>
{ networkMenu.isOpen ? <NetworkMenuContentMobile tabs={ networkMenu.availableTabs } items={ networkMenu.data }/> : <NavigationMobile/> }
{ networkMenu.isOpen ?
<NetworkMenuContentMobile tabs={ networkMenu.availableTabs } items={ networkMenu.data }/> :
<NavigationMobile onNavLinkClick={ onClose }/>
}
</DrawerBody>
</DrawerContent>
</Drawer>
Expand Down
4 changes: 3 additions & 1 deletion ui/snippets/navigation/NavLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ type Props = {
isCollapsed?: boolean;
px?: string | number;
className?: string;
onClick?: () => void;
}

const NavLink = ({ item, isCollapsed, px, className }: Props) => {
const NavLink = ({ item, isCollapsed, px, className, onClick }: Props) => {
const isMobile = useIsMobile();
const colors = useColors();

Expand All @@ -41,6 +42,7 @@ const NavLink = ({ item, isCollapsed, px, className }: Props) => {
px={ px || { base: 3, lg: isExpanded ? 3 : '15px', xl: isCollapsed ? '15px' : 3 } }
aria-label={ `${ item.text } link` }
whiteSpace="nowrap"
onClick={ onClick }
>
<Tooltip
label={ item.text }
Expand Down
14 changes: 9 additions & 5 deletions ui/snippets/navigation/NavigationMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import NavLink from 'ui/snippets/navigation/NavLink';

import NavLinkGroupMobile from './NavLinkGroupMobile';

const NavigationMobile = () => {
interface Props {
onNavLinkClick?: () => void;
}

const NavigationMobile = ({ onNavLinkClick }: Props) => {
const { mainNavItems, accountNavItems } = useNavItems();

const [ openedGroupIndex, setOpenedGroupIndex ] = React.useState(-1);
Expand Down Expand Up @@ -59,7 +63,7 @@ const NavigationMobile = () => {
if (isGroupItem(item)) {
return <NavLinkGroupMobile key={ item.text } item={ item } onClick={ onGroupItemOpen(index) }/>;
} else {
return <NavLink key={ item.text } item={ item }/>;
return <NavLink key={ item.text } item={ item } onClick={ onNavLinkClick }/>;
}
}) }
</VStack>
Expand All @@ -73,7 +77,7 @@ const NavigationMobile = () => {
borderColor="divider"
>
<VStack as="ul" spacing="1" alignItems="flex-start">
{ accountNavItems.map((item) => <NavLink key={ item.text } item={ item }/>) }
{ accountNavItems.map((item) => <NavLink key={ item.text } item={ item } onClick={ onNavLinkClick }/>) }
</VStack>
</Box>
) }
Expand Down Expand Up @@ -109,10 +113,10 @@ const NavigationMobile = () => {
borderColor: 'divider',
}}
>
{ item.map(subItem => <NavLink key={ subItem.text } item={ subItem }/>) }
{ item.map(subItem => <NavLink key={ subItem.text } item={ subItem } onClick={ onNavLinkClick }/>) }
</Box>
) :
<NavLink key={ item.text } item={ item } mb={ 1 }/>,
<NavLink key={ item.text } item={ item } mb={ 1 } onClick={ onNavLinkClick }/>,
) }
</Box>
</Box>
Expand Down
16 changes: 13 additions & 3 deletions ui/snippets/profileMenu/ProfileMenuContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const feature = config.features.account;

type Props = {
data?: UserInfo;
onNavLinkClick?: () => void;
};

const ProfileMenuContent = ({ data }: Props) => {
const ProfileMenuContent = ({ data, onNavLinkClick }: Props) => {
const { accountNavItems, profileItem } = useNavItems();
const primaryTextColor = useColorModeValue('blackAlpha.800', 'whiteAlpha.800');

Expand Down Expand Up @@ -45,10 +46,19 @@ const ProfileMenuContent = ({ data }: Props) => {
{ data.email }
</Text>
) }
<NavLink item={ profileItem } isActive={ undefined } px="0px" isCollapsed={ false }/>
<NavLink item={ profileItem } isActive={ undefined } px="0px" isCollapsed={ false } onClick={ onNavLinkClick }/>
<Box as="nav" mt={ 2 } pt={ 2 } borderTopColor="divider" borderTopWidth="1px" { ...getDefaultTransitionProps() }>
<VStack as="ul" spacing="0" alignItems="flex-start" overflow="hidden">
{ accountNavItems.map((item) => <NavLink key={ item.text } item={ item } isActive={ undefined } isCollapsed={ false } px="0px"/>) }
{ accountNavItems.map((item) => (
<NavLink
key={ item.text }
item={ item }
isActive={ undefined }
isCollapsed={ false }
px="0px"
onClick={ onNavLinkClick }
/>
)) }
</VStack>
</Box>
<Box mt={ 2 } pt={ 3 } borderTopColor="divider" borderTopWidth="1px" { ...getDefaultTransitionProps() }>
Expand Down
2 changes: 1 addition & 1 deletion ui/snippets/profileMenu/ProfileMenuMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ProfileMenuMobile = () => {
<DrawerOverlay/>
<DrawerContent maxWidth="260px">
<DrawerBody p={ 6 }>
<ProfileMenuContent data={ data }/>
<ProfileMenuContent data={ data } onNavLinkClick={ onClose }/>
</DrawerBody>
</DrawerContent>
</Drawer>
Expand Down
Loading