Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update SideNavigationLink component's prop type #1133

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading