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

[Bug]: SideNavMenuItem doesn't have an as prop although warning indicates it does #18021

Closed
2 tasks done
adamalston opened this issue Nov 7, 2024 · 0 comments · Fixed by #18056
Closed
2 tasks done
Assignees

Comments

@adamalston
Copy link
Contributor

Package

@carbon/react

Browser

No response

Package version

1.67.1

React version

No response

Description

SideNavMenuItem doesn't have an as prop, or at least it isn't typed. I want to use a react-router-dom Link as the element in the component.

Reproduction/example

N/A

Steps to reproduce

This code worked in Carbon v10:

<SideNavMenuItem
  key={name}
  element={externalPath ? 'a' : Link}
  href={externalPath}
  target={externalPath ? '_blank' : undefined}
  to={path}
  aria-current={sideMenuItemState[`${menuKey}${name}`]}
>
  {display ?? t(`nls.${section}.${name}`)}
</SideNavMenuItem>

In Carbon v11, I get this warning:

Warning: The `element` prop for `Link` has been deprecated. Please use `as` instead. This will be removed in the next major release. Error Component Stack

This change addresses the warning:

<SideNavMenuItem
  key={name}
  as={externalPath ? 'a' : Link}
  href={externalPath}
  target={externalPath ? '_blank' : undefined}
  to={path}
  aria-current={sideMenuItemState[`${menuKey}${name}`]}
>
  {display ?? t(`nls.${section}.${name}`)}
</SideNavMenuItem>

However, that change results in a TypeScript error that says:

Type '{ children: string; key: string; as: string | (<S = unknown>(props: LinkProps<S> & RefAttributes<HTMLAnchorElement>) => ReactElement<any, string | JSXElementConstructor<...>> | null); href: string | undefined; target: string | undefined; to: string; "aria-current": "page" | undefined; }' is not assignable to type 'IntrinsicAttributes & SideNavMenuItemProps & RefAttributes<HTMLElement>'.
  Property 'as' does not exist on type 'IntrinsicAttributes & SideNavMenuItemProps & RefAttributes<HTMLElement>'.

error

Suggested Severity

Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.

Application/PAL

DataPower

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants