Skip to content

Commit

Permalink
fix(nav): clickable range of link (#493)
Browse files Browse the repository at this point in the history
* fix(nav): clickable range of link

* fix: event propagation
  • Loading branch information
shhdgit authored Jul 2, 2024
1 parent d7f2fef commit 8874439
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
7 changes: 6 additions & 1 deletion src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import { Link as I18nLink } from "gatsby-plugin-react-i18next";
import Typography from "@mui/material/Typography";

export default function LinkComponent(props: {
to: string;
to?: string;
style?: { [key: string]: any };
isI18n?: boolean;
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
[key: string]: any;
}) {
if (!props.to) {
return props.children;
}

const { to, style, isI18n, ...rest } = props;
const isExternal = props.to.startsWith("http");
if (isExternal) {
Expand Down
45 changes: 21 additions & 24 deletions src/components/Navigation/LeftNavTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,7 @@ export default function ControlledTreeView(props: {
paddingBottom: "0.25rem",
}}
>
{item.link ? (
<LinkComponent
to={item.link}
style={{ width: "100%", color: "inherit" }}
>
{generateItemLabel(item.content)}
</LinkComponent>
) : (
generateItemLabel(item.content)
)}
{generateItemLabel(item.content)}
{hasChildren ? (
<ChevronRightIcon
className="MuiTreeItem-ChevronRightIcon"
Expand All @@ -197,21 +188,27 @@ export default function ControlledTreeView(props: {
);
};
return (
<StyledTreeItem
key={item.id}
nodeId={item.id}
label={<LabelEle />}
// onClick={() => {
// console.log(item.id);
// }}
ContentProps={{
style: { width: "inherit" },
}}
<LinkComponent
to={item.link}
style={{ width: "100%", color: "inherit" }}
onClick={(e) => e.stopPropagation()}
>
{hasChildren
? renderTreeItems(item.children as DocLeftNavItem[], deepth + 1)
: null}
</StyledTreeItem>
<StyledTreeItem
key={item.id}
nodeId={item.id}
label={<LabelEle />}
// onClick={() => {
// console.log(item.id);
// }}
ContentProps={{
style: { width: "inherit" },
}}
>
{hasChildren
? renderTreeItems(item.children as DocLeftNavItem[], deepth + 1)
: null}
</StyledTreeItem>
</LinkComponent>
);
});
};
Expand Down

0 comments on commit 8874439

Please sign in to comment.