diff --git a/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.test.tsx b/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.test.tsx index 8990982b..6b9f753e 100644 --- a/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.test.tsx +++ b/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.test.tsx @@ -32,11 +32,11 @@ it("displays a dark icon", () => { }); it("can use a custom link component", () => { - const Link = ({ ...props }: ButtonHTMLAttributes) => ( - ); const label = "Test content"; - render(); + render(); expect(screen.getByRole("button", { name: label })).toHaveClass( "p-side-navigation__link", ); diff --git a/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.tsx b/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.tsx index 15493174..dcac36a1 100644 --- a/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.tsx +++ b/src/components/SideNavigation/SideNavigationLink/SideNavigationLink.tsx @@ -16,22 +16,30 @@ export type Props = Omit< * @default a */ component?: SideNavigationBaseProps["component"]; + /** + * A ref to pass to the link element. + */ + forwardRef?: React.Ref | null; +}; + +const SideNavigationLink = ({ + component, + forwardRef, + ...props +}: Props) => { + let className: string | null = null; + if ("className" in props && typeof props.className === "string") { + className = props.className; + delete props.className; + } + return ( + + ); }; -const SideNavigationLink = forwardRef( - ({ component, ...props }: Props) => { - let className: string | null = null; - if ("className" in props && typeof props.className === "string") { - className = props.className; - delete props.className; - } - return ( - - ); - }, -); export default SideNavigationLink;