Skip to content

Commit

Permalink
chore: forwardRef from SideNavigationLink component
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryanporwal committed Aug 22, 2024
1 parent 2339e4c commit c5aeb71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SideNavigationItem = <L = SideNavigationLinkDefaultElement,>(
const { nonInteractive: _, ...textProps } = props;
content = <SideNavigationText {...textProps} />;
} else if (!("children" in props)) {
content = <SideNavigationLink<L> {...props} />;
content = <SideNavigationLink {...props} />;
} else {
({ children: content, ...liProps } = props);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { forwardRef } from "react";
import classNames from "classnames";
import type { HTMLProps } from "react";

Expand All @@ -17,23 +17,21 @@ export type Props<L = LinkDefaultElement> = Omit<
*/
component?: SideNavigationBaseProps<L>["component"];
};

const SideNavigationLink = <L = LinkDefaultElement,>({
component,
...props
}: Props<L>) => {
let className: string | null = null;
if ("className" in props && typeof props.className === "string") {
className = props.className;
delete props.className;
const SideNavigationLink = forwardRef<HTMLAnchorElement, Props>(
({ component, ref, ...props }: Props) => {
let className: string | null = null;
if ("className" in props && typeof props.className === "string") {
className = props.className;
delete props.className;
}
return (
<SideNavigationBase
className={classNames("p-side-navigation__link", className)}
component={component ?? "a"}
{...props}
/>
);
}
return (
<SideNavigationBase
className={classNames("p-side-navigation__link", className)}
component={component ?? "a"}
{...props}
/>
);
};
);

export default SideNavigationLink;

0 comments on commit c5aeb71

Please sign in to comment.