MenuItem's render function always passes href
#9988
rothsandro
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
The Menu documentation for menu item with links mention that the
renderfunction can be used to conditionally render a (router) link by checking'href' in props".However, the
domPropsalways containshrefit's justundefinedfor regular menu items. We also have to check ifhrefis not undefined. But this additional checks results in a TS error when returning<div {...domProps} />becausedomPropscould be anchor props, so we have to type-cast it.Repro: https://stackblitz.com/edit/87xhexc4?file=src%2FExample.tsx
I assume this comes from
useLinkProps():react-spectrum/packages/react-aria/src/utils/openLink.tsx
Lines 175 to 185 in 86c8a3b
Is it expected that
hrefis always set? If yes, should the docs be updated to check forundefinedas well and TS users have to type-cast when spreading the props?Regards,
Sandro
Beta Was this translation helpful? Give feedback.
All reactions