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

Close the drawer on mobile when clicking on a item of the menu #764

Merged
merged 1 commit into from
Feb 14, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/ui/NavMenu/NavMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { memo, useState } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { useDispatch, useSelector } from 'react-redux'
import {
Menu,
Collapse,
Expand All @@ -15,6 +16,8 @@ import _castArray from 'lodash/castArray'
import Icons from 'icons'
import { getPath, getTarget } from 'state/query/utils'

import { toggleNavigationDrawer } from 'state/ui/actions'
import { getIsNavigationDrawerOpen } from 'state/ui/selectors'
import menuTypes from './NavMenu.constants'
import { getSections, getMenuItemChevron } from './NavMenu.helpers'

Expand All @@ -35,6 +38,8 @@ const NavMenu = ({
const [isMyHistoryOpen, setIsMyHistoryOpen] = useState(true)
const [isMarketHistoryOpen, setIsMarketHistoryOpen] = useState(false)
const [isMerchantHistoryOpen, setIsMerchantHistoryOpen] = useState(false)
const dispatch = useDispatch()
const isNavigationDrawerOpen = useSelector(getIsNavigationDrawerOpen)

const handleItemClick = (e, nextTarget) => {
e.preventDefault()
Expand All @@ -45,6 +50,9 @@ const NavMenu = ({
search: window.location.search,
})
window.scrollTo(0, 0) // scroll to the top of the page on section change
if (isNavigationDrawerOpen) {
dispatch(toggleNavigationDrawer())
}
}

const getMenuItems = (menuType, target) => (
Expand Down