Skip to content

Commit

Permalink
feat(theme): add custom label for social links (#2466)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
AgustinBanchio and brc-dd committed Jun 7, 2023
1 parent 7a2bde3 commit c995b9f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion docs/reference/default-theme-config.md
Expand Up @@ -214,7 +214,9 @@ export default {
icon: {
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>'
},
link: '...'
link: '...',
// You can include a custom label for accessibility too (optional but recommended):
ariaLabel: 'cool link'
}
]
}
Expand All @@ -225,6 +227,7 @@ export default {
interface SocialLink {
icon: SocialLinkIcon
link: string
ariaLabel?: string
}

type SocialLinkIcon =
Expand Down
3 changes: 2 additions & 1 deletion src/client/theme-default/components/VPSocialLink.vue
Expand Up @@ -6,6 +6,7 @@ import { icons } from '../support/socialIcons'
const props = defineProps<{
icon: DefaultTheme.SocialLinkIcon
link: string
ariaLabel?: string
}>()
const svg = computed(() => {
Expand All @@ -18,7 +19,7 @@ const svg = computed(() => {
<a
class="VPSocialLink"
:href="link"
:aria-label="typeof icon === 'string' ? icon : ''"
:aria-label="ariaLabel ?? (typeof icon === 'string' ? icon : '')"
target="_blank"
rel="noopener"
v-html="svg"
Expand Down
3 changes: 2 additions & 1 deletion src/client/theme-default/components/VPSocialLinks.vue
Expand Up @@ -10,10 +10,11 @@ defineProps<{
<template>
<div class="VPSocialLinks">
<VPSocialLink
v-for="{ link, icon } in links"
v-for="{ link, icon, ariaLabel } in links"
:key="link"
:icon="icon"
:link="link"
:ariaLabel="ariaLabel"
/>
</div>
</template>
Expand Down
1 change: 1 addition & 0 deletions types/default-theme.d.ts
Expand Up @@ -251,6 +251,7 @@ export namespace DefaultTheme {
export interface SocialLink {
icon: SocialLinkIcon
link: string
ariaLabel?: string
}

export type SocialLinkIcon =
Expand Down

0 comments on commit c995b9f

Please sign in to comment.