mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
fix nav items not accessible with Tab
This commit is contained in:
@@ -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),
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user