Skip to content

Commit

Permalink
fix: UserMenu component bugs (#493)
Browse files Browse the repository at this point in the history
* fix: noscroll on mobile for UserMenu

* fix: handle properly menu and usermenu

* fix: prettier
  • Loading branch information
lauti7 authored Jan 15, 2024
1 parent 9011ea5 commit 4a36f84
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/components/Navbar2/Navbar2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export const Navbar2 = React.memo((props: Navbar2Props) => {
[onClickNavbarItem]
)

const handleUserMenuOpen = (
event: React.MouseEvent<HTMLElement, MouseEvent>,
trackingId: string
) => {
if (userMenuProps.onClickOpen) {
userMenuProps.onClickOpen(event, trackingId)
}
handleMobileToggle(event, false)
}

return (
<div
className={classNames(
Expand Down Expand Up @@ -109,9 +119,14 @@ export const Navbar2 = React.memo((props: Navbar2Props) => {
<div className="dui-navbar2-account">
<UserMenu
{...userMenuProps}
onClickOpen={
isTabletAndBelow
? handleUserMenuOpen
: userMenuProps.onClickOpen
}
isSignedIn={isSignedIn}
i18n={i18nUserMenu}
></UserMenu>
/>
</div>
</div>
</Container>
Expand Down
19 changes: 19 additions & 0 deletions src/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { config } from '../../config'
import { Row } from '../Row/Row'

import './UserMenu.css'
import { useTabletAndBelowMediaQuery } from '../Media'

export const UserMenu = React.memo((props: UserMenuProps) => {
const {
Expand All @@ -27,6 +28,8 @@ export const UserMenu = React.memo((props: UserMenuProps) => {
...signInProps
} = props

const isTabletAndBelow = useTabletAndBelowMediaQuery()

const [isOpen, setIsOpen] = useState(false)
const [trackingId, setTrackingId] = useState<string | null>(null)
const handleToggle = useCallback(
Expand All @@ -39,6 +42,15 @@ export const UserMenu = React.memo((props: UserMenuProps) => {
if (!prev && onClickOpen) {
onClickOpen(event, trackId)
}

if (isTabletAndBelow) {
if (!prev) {
window.addEventListener('scroll', noScroll)
} else {
window.removeEventListener('scroll', noScroll)
}
}

return !prev
})
},
Expand All @@ -47,6 +59,9 @@ export const UserMenu = React.memo((props: UserMenuProps) => {

const handleClose = useCallback(() => {
setIsOpen(false)
if (isTabletAndBelow) {
window.removeEventListener('scroll', noScroll)
}
}, [setIsOpen])

const handleClickJumpIn = useCallback(
Expand Down Expand Up @@ -150,3 +165,7 @@ export const UserMenu = React.memo((props: UserMenuProps) => {
</Column>
)
})

function noScroll() {
window.scrollTo(0, 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Notifications from '../../Notifications/Notifications'
import ArrowIcon from '../../Icons/ArrowIcon'
import { config } from '../../../config'
import { UserMenuEventId } from '../UserMenu.types'
import { useTabletAndBelowMediaQuery } from '../../Media'

import '../UserMenu.css'
import './UserMenuSignedIn.css'
Expand All @@ -37,6 +38,8 @@ export const UserMenuSignedIn = (props: UserMenuSignedInProps) => {
onClickWallet
} = props

const isTabletAndBelow = useTabletAndBelowMediaQuery()

const handleClickActivity = useCallback(
(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
onClickUserMenuItem &&
Expand Down Expand Up @@ -196,7 +199,7 @@ export const UserMenuSignedIn = (props: UserMenuSignedInProps) => {
<div
className={classNames('menu-wrapper', isOpen && 'open')}
onMouseLeave={handleClickClose}
onScroll={handleClickClose}
onScroll={!isTabletAndBelow ? handleClickClose : undefined}
>
<div
className={classNames(
Expand Down

1 comment on commit 4a36f84

@vercel
Copy link

@vercel vercel bot commented on 4a36f84 Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

decentraland-ui – ./

decentraland-ui-decentraland1.vercel.app
decentraland-ui-git-master-decentraland1.vercel.app

Please sign in to comment.