From 4fa77306119200091a3e86bf18c7ae702517f8dd Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Tue, 8 Sep 2020 13:11:01 +0200 Subject: [PATCH] Improve dom nesting --- src/components/SideBar/MenuItem.tsx | 49 ++++++++++++++++++----------- src/components/SideBar/SideBar.tsx | 1 + src/components/SideBar/utils.ts | 13 +++++--- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/components/SideBar/MenuItem.tsx b/src/components/SideBar/MenuItem.tsx index 6ae19b402..51bb6023f 100644 --- a/src/components/SideBar/MenuItem.tsx +++ b/src/components/SideBar/MenuItem.tsx @@ -43,6 +43,18 @@ const useStyles = makeStyles( opacity: 1, transition: theme.transitions.duration.shortest + "ms" }, + menuItemBtn: { + "&:focus": { + color: theme.palette.primary.main, + outline: 0 + }, + background: "none", + border: "none", + color: "inherit", + display: "inline-flex", + margin: 0, + padding: 0 + }, paper: { borderRadius: 16, cursor: "default", @@ -58,8 +70,6 @@ const useStyles = makeStyles( color: theme.palette.primary.main, outline: 0 }, - background: "none", - border: "none", borderBottomRightRadius: 100, borderTopRightRadius: 100, color: fade(theme.palette.text.primary, 0.6), @@ -89,7 +99,8 @@ const useStyles = makeStyles( } }, "&:hover, &:focus": { - color: theme.palette.primary.main + color: theme.palette.primary.main, + outline: 0 }, background: "none", border: "none", @@ -109,7 +120,7 @@ const MenuItem: React.FC = ({ }) => { const classes = useStyles({}); const [open, setOpen] = React.useState(false); - const anchor = React.useRef(null); + const anchor = React.useRef(null); const handleClick = (event: React.MouseEvent, menuItem: IMenuItem) => { if (menuItem.children) { @@ -121,7 +132,7 @@ const MenuItem: React.FC = ({ }; return ( - {menuItem.children && ( = ({ )} - + ); }; diff --git a/src/components/SideBar/SideBar.tsx b/src/components/SideBar/SideBar.tsx index 0f521b9ff..3edd12db8 100644 --- a/src/components/SideBar/SideBar.tsx +++ b/src/components/SideBar/SideBar.tsx @@ -93,6 +93,7 @@ const SideBar: React.FC = ({ isMenuShrunk={isShrunk} menuItem={menuItem} onClick={onMenuItemClick} + key={menuItem.ariaLabel} /> ); })} diff --git a/src/components/SideBar/utils.ts b/src/components/SideBar/utils.ts index 5f9856778..06827a7ac 100644 --- a/src/components/SideBar/utils.ts +++ b/src/components/SideBar/utils.ts @@ -11,11 +11,14 @@ export function isMenuActive(location: string, menuItem: IMenuItem) { ); } - return location.split("?")[0] === orderDraftListUrl().split("?")[0] && - menuItem.url.split("?")[0] === orderListUrl().split("?")[0] + const activeUrl = location.split("?")[0]; + const menuItemUrl = menuItem.url.split("?")[0]; + + return activeUrl === orderDraftListUrl().split("?")[0] && + menuItemUrl === orderListUrl().split("?")[0] ? false - : !!matchPath(location.split("?")[0], { - exact: menuItem.url.split("?")[0] === "/", - path: menuItem.url.split("?")[0] + : !!matchPath(activeUrl, { + exact: menuItemUrl === "/", + path: menuItemUrl }); }