fix nav items not accessible with Tab

This commit is contained in:
Sidney Alcantara
2022-07-20 14:51:17 +10:00
parent a96b23f38d
commit b641af8c8f

View File

@@ -1,29 +1,45 @@
import { Link, useLocation } from "react-router-dom";
import { MenuItem, MenuItemProps } from "@mui/material";
import { spreadSx } from "@src/utils/ui";
export default function NavItem(props: MenuItemProps<typeof Link>) {
const linkProps = { target: "_blank", rel: "noopener noreferrer" };
export default function NavItem(
props: MenuItemProps<typeof Link | "a" | "button">
) {
const { pathname } = useLocation();
return (
<MenuItem
component={Link}
selected={pathname === props.to}
role="none"
tabIndex={0}
component={"to" in props ? Link : "href" in props ? "a" : "button"}
selected={"to" in props ? pathname === props.to : false}
{...props}
sx={{
"& .MuiListItemText-primary": {
typography: "button",
{...("href" in props ? linkProps : {})}
sx={[
{
overflow: "hidden",
textAlign: "left",
color: "text.secondary",
},
"& .MuiListItemIcon-root": { opacity: 0.87 },
"&:hover, &.Mui-selected": {
"& .MuiListItemText-primary": { color: "text.primary" },
"& .MuiSvgIcon-root": { color: "text.primary" },
},
"& .MuiListItemText-primary": {
typography: "button",
overflow: "hidden",
},
"& .MuiSvgIcon-root": {
color: "inherit",
opacity: 0.87,
display: "block",
},
...props.sx,
"&&::before": { left: "auto", right: 0 },
}}
"&:hover, &.Mui-selected": {
"& .MuiListItemText-primary": { color: "text.primary" },
"& .MuiSvgIcon-root": { color: "text.primary" },
},
},
...spreadSx(props.sx),
]}
/>
);
}