Skip to content

Commit

Permalink
fix: Update SideNavigationLink component's prop type
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryanporwal committed Sep 19, 2024
1 parent 26cf50d commit 47d1030
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ it("can use a custom link component", () => {

it("gets the ref and checks if it can be used to get the element's position", () => {
const ref = React.createRef<HTMLAnchorElement>();
render(<SideNavigationLink label="Test content" forwardRef={ref} />);
render(
<SideNavigationLink
label="Test content"
onClick={jest.fn()}
forwardRef={ref}
/>,
);
expect(ref.current?.getBoundingClientRect()).toBeDefined();
});
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import React from "react";
import classNames from "classnames";
import type { HTMLProps, ReactNode } from "react";
import type { HTMLProps } from "react";

import type { SideNavigationBaseProps } from "../SideNavigationBase";
import SideNavigationBase from "../SideNavigationBase";
import { PropsWithSpread } from "types";

export type LinkDefaultElement = HTMLProps<HTMLAnchorElement>;

export type Props<L = LinkDefaultElement, E = HTMLAnchorElement> = Partial<
export type Props<
L = LinkDefaultElement,
E = HTMLAnchorElement,
> = PropsWithSpread<
{
/**
* The component or element to use for the link element e.g. `a` or `NavLink`.
* @default a
*/
component?: SideNavigationBaseProps<L>["component"];
/**
* A ref to pass to the link element.
*/
forwardRef?: React.Ref<E> | null;
},
Omit<SideNavigationBaseProps<L>, "component">
> & {
/**
* The navigation item's label.
*/
label: ReactNode;
/**
* The component or element to use for the link element e.g. `a` or `NavLink`.
* @default a
*/
component?: SideNavigationBaseProps<L>["component"];
/**
* A ref to pass to the link element.
*/
forwardRef?: React.Ref<E> | null;
};
>;

const SideNavigationLink = <L = LinkDefaultElement, E = HTMLAnchorElement>({
component,
Expand Down

0 comments on commit 47d1030

Please sign in to comment.