Skip to content
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(theme-default): image alt option and set aria hidden on title if same as image alt (close #20) #23

Merged
merged 11 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion themes/theme-default/src/client/components/NavbarBrand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ const navbarBrandLogo = computed(() => {
}
return themeLocale.value.logo
})
const navbarBrandLogoAlt = computed(
() => themeLocale.value.logoAlt ?? navbarBrandTitle.value,
)
const navBarLogoAltMatchesTitle = computed(
() =>
navbarBrandTitle.value.toLocaleUpperCase().trim() ===
navbarBrandLogoAlt.value.toLocaleUpperCase().trim(),
)
const NavbarBrandLogo: FunctionalComponent = () => {
if (!navbarBrandLogo.value) return null
const img = h('img', {
class: 'logo',
src: withBase(navbarBrandLogo.value),
alt: navbarBrandTitle.value,
alt: navbarBrandLogoAlt.value,
Mister-Hope marked this conversation as resolved.
Show resolved Hide resolved
})
if (themeLocale.value.logoDark === undefined) {
return img
Expand All @@ -48,6 +56,7 @@ const NavbarBrandLogo: FunctionalComponent = () => {
v-if="navbarBrandTitle"
class="site-name"
:class="{ 'can-hide': navbarBrandLogo }"
:aria-hidden="navBarLogoAltMatchesTitle"
Mister-Hope marked this conversation as resolved.
Show resolved Hide resolved
>
{{ navbarBrandTitle }}
</span>
Expand Down
6 changes: 5 additions & 1 deletion themes/theme-default/src/client/components/NavbarItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ useUpdateDeviceStatus(
</script>

<template>
<nav v-if="navbarLinks.length" class="navbar-items">
<nav
v-if="navbarLinks.length"
class="navbar-items"
aria-label="site navigation"
nruffing marked this conversation as resolved.
Show resolved Hide resolved
>
<div v-for="item in navbarLinks" :key="item.text" class="navbar-item">
<NavbarDropdown
v-if="item.children"
Expand Down
6 changes: 5 additions & 1 deletion themes/theme-default/src/client/components/PageNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ const nextNavLink = computed(() => {
</script>

<template>
<nav v-if="prevNavLink || nextNavLink" class="page-nav">
<nav
v-if="prevNavLink || nextNavLink"
class="page-nav"
aria-label="page navigation"
nruffing marked this conversation as resolved.
Show resolved Hide resolved
>
<p class="inner">
<span v-if="prevNavLink" class="prev">
<AutoLink :item="prevNavLink" />
Expand Down
8 changes: 8 additions & 0 deletions themes/theme-default/src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ export interface DefaultThemeLocaleData extends LocaleData {
*/
logoDark?: null | string

/**
* The alt text of navbar logo.
* Defaults to the site title if not specified.
* If the value is the same as the site title and the site title is displayed (i.e not mobile)
* the alt attribute will still be rendered but with an empty value to not be read twice by screen readers.
*/
logoAlt?: null | string

/**
* Navbar repository config
*
Expand Down