This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Remove span from VLink #1841
Merged
Merged
Remove span from VLink #1841
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
<!-- eslint-disable vue/no-restricted-syntax --> | ||
<template> | ||
<NuxtLink | ||
v-if="linkComponent === 'NuxtLink'" | ||
v-bind="$attrs" | ||
v-if="isNuxtLink" | ||
:class="{ 'inline-flex flex-row items-center gap-2': showExternalIcon }" | ||
:to="linkTo" | ||
v-on="$listeners" | ||
@click.native="$emit('click', $event)" | ||
> | ||
<slot /><VIcon | ||
v-if="showExternalIcon && !isInternal" | ||
:icon-path="externalLinkIcon" | ||
class="inline-block" | ||
:size="4" | ||
rtl-flip | ||
/> | ||
<slot /> | ||
</NuxtLink> | ||
<a | ||
v-else-if="linkComponent === 'a'" | ||
v-bind="$attrs" | ||
v-else | ||
:href="href" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
:role="href ? undefined : 'link'" | ||
:aria-disabled="!href" | ||
:class="{ 'inline-flex flex-row items-center gap-2': showExternalIcon }" | ||
v-on="$listeners" | ||
> | ||
|
@@ -33,26 +27,13 @@ | |
rtl-flip | ||
/> | ||
</a> | ||
<span | ||
v-else | ||
v-bind="$attrs" | ||
:class="{ 'inline-flex flex-row items-center gap-2': showExternalIcon }" | ||
> | ||
<slot /><VIcon | ||
v-if="showExternalIcon && !isInternal" | ||
:icon-path="externalLinkIcon" | ||
class="inline-block" | ||
:size="4" | ||
rtl-flip | ||
/> | ||
Comment on lines
-41
to
-47
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. Is the removal of 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. Only the Icon inside the span I'd removed, and NuxtLink still have it. |
||
</span> | ||
</template> | ||
|
||
<script lang="ts"> | ||
/** | ||
* This is a wrapper component for all links. If a link is dynamically generated and doesn't have | ||
* an `href` prop (as the links for detail pages when the image detail hasn't loaded yet), | ||
* it is rendered as a `span`. | ||
* This is a wrapper component for all links. If `href` prop is undefined, | ||
* the link will be rendered as a disabled: an `<a>` element without `href` | ||
* attribute and with `role="link"` and `aria-disabled="true"` attributes. | ||
* Links with `href` starting with `/` are treated as internal links. | ||
* | ||
* Internal links use `NuxtLink` component with `to` attribute set to `localePath(href)` | ||
|
@@ -67,7 +48,6 @@ import externalLinkIcon from '~/assets/icons/external-link.svg' | |
export default defineComponent({ | ||
name: 'VLink', | ||
components: { VIcon }, | ||
inheritAttrs: false, | ||
props: { | ||
href: { | ||
type: String, | ||
|
@@ -96,9 +76,7 @@ export default defineComponent({ | |
const isInternal = computed( | ||
() => hasHref.value && props.href?.startsWith('/') | ||
) | ||
const linkComponent = computed(() => | ||
hasHref.value ? (isInternal.value ? 'NuxtLink' : 'a') : 'span' | ||
) | ||
const isNuxtLink = computed(() => hasHref.value && isInternal.value) | ||
|
||
let linkTo = computed(() => | ||
checkHref(props) && isInternal.value | ||
|
@@ -108,7 +86,7 @@ export default defineComponent({ | |
|
||
return { | ||
linkTo, | ||
linkComponent, | ||
isNuxtLink, | ||
isInternal, | ||
externalLinkIcon, | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 realized just now that a NuxtLink is only used for the internal links, so it cannot use the
externalLinkIcon
.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.
Interesting. How do we define an "external" link? When we've removed the iframe, will w.org links be "external"? If all links that don't use
NuxtLink
are external then we can remove the conditionalshowExternalIcon && !isInternal
fromVIcon
. If it's only things that are not either (a) Openverse frontend links or (b) w.org links, then we could detect it and automatically add the icon without having to rely on the prop.Probably an additional tightening up here and clarification around the iframe project and the idea of "externality". We typically concern ourselves with this (I think) due to differing privacy expectations on other websites. Given Openverse and WordPress.org follow the same privacy policies and are all controlled by WPF, we probably don't need the external icon for w.org links either. But again, something to clarify and probably something for another issue and to rope the w.org infrastructure folks in on.