From 60e13caaba23a09af9183b4897ad96ca6942c161 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Wed, 15 Jan 2020 23:14:36 +0800 Subject: [PATCH 1/2] fix issue 2504 --- src/components/LoginNav/index.js | 2 +- src/components/TopNav/PrimaryNav.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/LoginNav/index.js b/src/components/LoginNav/index.js index a1e2696..6a1b0b1 100644 --- a/src/components/LoginNav/index.js +++ b/src/components/LoginNav/index.js @@ -77,7 +77,7 @@ const LoginNav = ({ } return ( -
+
{loggedIn ? renderLoginPanel() : (
, /* Level 1 menu item */ {level1.subMenu.filter(filterNotInMore).map((level2, i) => ( {moreMenu.map((menu, i) => ( Date: Tue, 21 Jan 2020 15:47:49 +0800 Subject: [PATCH 2/2] fix enter key issue --- src/components/LoginNav/index.js | 14 ++++++-- src/components/TopNav/PrimaryNav.js | 13 +++++++- src/components/UserInfo/index.js | 51 +++++++++++++++++++---------- 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/components/LoginNav/index.js b/src/components/LoginNav/index.js index 6a1b0b1..d1cc129 100644 --- a/src/components/LoginNav/index.js +++ b/src/components/LoginNav/index.js @@ -29,8 +29,17 @@ const LoginNav = ({ setOpenAccountMenu(false) document.body.style.position = '' } + const listener = event => { + if (event.code === 'Enter') { + event.target.click() + } + } + document.addEventListener('keydown', listener) window.addEventListener('orientationchange', onOrientationChange) - return () => window.removeEventListener('orientationchange', onOrientationChange) + return () => { + document.removeEventListener('keydown', listener) + window.removeEventListener('orientationchange', onOrientationChange) + } }, []) const handleClickNotifications = () => setOpenNotifications(x => !x) @@ -77,10 +86,11 @@ const LoginNav = ({ } return ( -
+
{loggedIn ? renderLoginPanel() : ( { const retUrl = encodeURIComponent(window.location.href) window.location = authURLs.location.replace('%S', retUrl).replace('member?', '#!/member?') diff --git a/src/components/TopNav/PrimaryNav.js b/src/components/TopNav/PrimaryNav.js index 10b81fb..fbe1f33 100644 --- a/src/components/TopNav/PrimaryNav.js +++ b/src/components/TopNav/PrimaryNav.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import PropTypes from 'prop-types' import cn from 'classnames' import ResizeDetector from 'react-resize-detector' @@ -39,6 +39,17 @@ const PrimaryNav = ({ const activeTrigger = { bottom: 50 // The main nav head bottom Y } + useEffect(() => { + const listener = event => { + if (event.code === 'Enter') { + event.target.click() + } + } + document.addEventListener('keydown', listener) + return () => { + document.removeEventListener('keydown', listener) + } + }, []) return (
diff --git a/src/components/UserInfo/index.js b/src/components/UserInfo/index.js index 6839bcb..7f04b7e 100644 --- a/src/components/UserInfo/index.js +++ b/src/components/UserInfo/index.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import PropTypes from 'prop-types' import cn from 'classnames' import IconAvatar from '../../assets/images/img-vic-tor-avatar.svg' @@ -7,25 +7,40 @@ import IconArrowSmallup from '../../assets/images/arrow-small-up.svg' import styles from './styles.module.scss' import _ from 'lodash' -const UserInfo = ({ profile, onClick, open, newNotifications }) => ( -
-
- { - (_.isEmpty(profile) || _.isEmpty(profile.photoURL)) ? () : (avatar) +const UserInfo = ({ profile, onClick, open, newNotifications }) => { + useEffect(() => { + const listener = event => { + if (event.code === 'Enter') { + event.target.click() } + } + document.addEventListener('keydown', listener) + return () => { + document.removeEventListener('keydown', listener) + } + }, []) + + return ( +
+
+ { + (_.isEmpty(profile) || _.isEmpty(profile.photoURL)) ? () : (avatar) + } +
+
+ {_.isEmpty(profile) ? '' : profile.handle} + + { open ? : } + +
-
- {_.isEmpty(profile) ? '' : profile.handle} - - { open ? : } - -
-
-) + ) +} UserInfo.propTypes = { profile: PropTypes.shape(),