-
Notifications
You must be signed in to change notification settings - Fork 67
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
feat: introduce as prop for Hyperlink #3082
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for paragon-openedx ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3082 +/- ##
==========================================
- Coverage 93.19% 93.17% -0.03%
==========================================
Files 249 249
Lines 4348 4349 +1
Branches 1034 1001 -33
==========================================
Hits 4052 4052
- Misses 290 294 +4
+ Partials 6 3 -3 ☔ View full report in Codecov by Sentry. |
7af05c8
to
fa72a7d
Compare
import { Launch } from '../../icons'; | ||
import Icon from '../Icon'; | ||
|
||
export const HYPER_LINK_EXTERNAL_LINK_ALT_TEXT = 'in a new tab'; | ||
export const HYPER_LINK_EXTERNAL_LINK_TITLE = 'Opens in a new tab'; | ||
|
||
interface Props extends Omit<React.ComponentPropsWithRef<'a'>, 'href' | 'target'> { | ||
interface HyperlinkProps extends BsPrefixProps, Omit<React.ComponentPropsWithRef<'a'>, 'href' | 'target'> { | ||
/** specifies the URL */ | ||
destination: string; |
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.
When using Hyperlink
with Link
from React Router (or GatsbyLink
on the Paragon docs site example), the destination
prop will not suffice as it gets passed to an href
prop, leading to the link getting treated as an external URL (triggering full-page refresh).
Both Link
and GatsbyLink
utilize the standard hyperlink (i.e., a
) when href
prop is provided; to get it to work with internal routing, the to
prop must be passed.
Because we use prop spreading of all attributes passed to the Hyperlink
component, consumers can pass to
prop but would continue to need to pass destination
as it's a required prop.
We will need to determine how consumers can pass to
without needing to also pass an identical value to destination
(i.e., href
), e.g.:
<Hyperlink
as={GatsbyLink}
to="/components/button"
// `destination` is still a required prop even though the `to` takes precedence.
destination="/components/button"
>
Button
</Hyperlink>
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.
@bradenmacdonald Curious if you might have any thoughts on how to mitigate this concern around to
vs. href
vs. destination
?
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.
Yeah, I was wondering about this.
I think one nice option is to change the Paragon hyperlink
to accept to
instead of destination
and just treat destination
as a deprecated alias for to
?
Otherwise to avoid the need to introspect as
and determine what prop to pass based on some conditions, you could change the logic that currently converts destination
to href
and instead convert destination
to both href
and to
, and unconditionally pass both props to the inner as
component. Though I think this may display a DOM warning in the console that a
doesn't accept a to
attribute. So maybe some conditional logic is actually needed.
fa72a7d
to
9ead6aa
Compare
Description
Introduces
as
prop and types forHyperlink
to make it compatible with React Router'sLink
.Note: May need to be updated after #3080 is reviewed/merged.
Deploy Preview
https://deploy-preview-3082--paragon-openedx.netlify.app/components/hyperlink
Merge Checklist
example
app?Post-merge Checklist