-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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: routerized links #4628
base: canary
Are you sure you want to change the base?
fix: routerized links #4628
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ export function useLink(originalProps: UseLinkProps) { | |
as, | ||
children, | ||
anchorIcon, | ||
href, | ||
isExternal = false, | ||
showAnchorIcon = false, | ||
autoFocus = false, | ||
|
@@ -73,6 +74,7 @@ export function useLink(originalProps: UseLinkProps) { | |
const {linkProps} = useAriaLink( | ||
{ | ||
...otherProps, | ||
href, | ||
onPress, | ||
onPressStart, | ||
onPressEnd, | ||
|
@@ -110,6 +112,8 @@ export function useLink(originalProps: UseLinkProps) { | |
"data-focus": dataAttr(isFocused), | ||
"data-disabled": dataAttr(originalProps.isDisabled), | ||
"data-focus-visible": dataAttr(isFocusVisible), | ||
// The `href` prop may be routerized by useAriaLink, so we may merge over top of it | ||
href, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sure that the href on the is set properly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
p.s. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case you are not using a routerized link you still need the original href I thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still needs to be extracted from otherProps though so mergeProps doesn't overwrite the linkProps href with the otherProps href. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the key for me is that useLinkProps can change href |
||
...mergeProps(focusProps, linkProps, otherProps), | ||
}; | ||
}, [classNames, isFocused, isFocusVisible, focusProps, linkProps, otherProps]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,10 +118,10 @@ export function useAriaLink(props: AriaLinkOptions, ref: RefObject<FocusableElem | |
// If props are applied to a router Link component, it may have already prevented default. | ||
!e.isDefaultPrevented() && | ||
shouldClientNavigate(e.currentTarget, e) && | ||
props.href | ||
routerLinkProps.href | ||
) { | ||
e.preventDefault(); | ||
router.open(e.currentTarget, e, props.href, props.routerOptions); | ||
router.open(e.currentTarget, e, routerLinkProps.href, props.routerOptions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sure that we use the useHref'ed href for the navigation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by doing so, one couldn't do any absolute paths, e.g. says I'm at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not? useHref from RR should produce /foo/1 in that case. I updated https://stackblitz.com/edit/wfdcu9f2 with that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RRLink can navigate to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/adobe/react-spectrum/blob/016590a4afc585eea18d5a12853c9d1e2d82a19c/packages/%40react-aria/utils/src/openLink.tsx#L174 for reference - unless the useLinkProps href is used, why call it it at all? Also, if the href is something like "https://www.heroui.com/" i believe the router.open call won't be made on it, a regular link will happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you give more details? All this patch really does is ensure the href produced by useLinkProps from react-aria is actually used in Hero (at least that was my intention) |
||
} | ||
}, | ||
}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
href
originally is inotherProps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know; see below.