From e485be966e15dc2a6b6d4d7c34024779281dcbc7 Mon Sep 17 00:00:00 2001 From: Nicholas Ruffing Date: Sun, 21 Jan 2024 13:52:43 -0500 Subject: [PATCH 1/7] feat(theme-default): image alt option and set aria hidden on title if same as image alt (close #20) --- .../src/client/components/NavbarBrand.vue | 11 ++++++++++- themes/theme-default/src/shared/options.ts | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/themes/theme-default/src/client/components/NavbarBrand.vue b/themes/theme-default/src/client/components/NavbarBrand.vue index c28ef229bb..b77a171cab 100644 --- a/themes/theme-default/src/client/components/NavbarBrand.vue +++ b/themes/theme-default/src/client/components/NavbarBrand.vue @@ -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, }) if (themeLocale.value.logoDark === undefined) { return img @@ -48,6 +56,7 @@ const NavbarBrandLogo: FunctionalComponent = () => { v-if="navbarBrandTitle" class="site-name" :class="{ 'can-hide': navbarBrandLogo }" + :aria-hidden="navBarLogoAltMatchesTitle" > {{ navbarBrandTitle }} diff --git a/themes/theme-default/src/shared/options.ts b/themes/theme-default/src/shared/options.ts index 49c2c7d73c..dfd1434a68 100644 --- a/themes/theme-default/src/shared/options.ts +++ b/themes/theme-default/src/shared/options.ts @@ -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 * From a68600f4378a37d5173b5e0799afe9817f55c029 Mon Sep 17 00:00:00 2001 From: Nicholas Ruffing Date: Sun, 21 Jan 2024 14:24:14 -0500 Subject: [PATCH 2/7] feat(theme-default): add labels to differ nav landmarks (close #21) --- themes/theme-default/src/client/components/NavbarItems.vue | 6 +++++- themes/theme-default/src/client/components/PageNav.vue | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/themes/theme-default/src/client/components/NavbarItems.vue b/themes/theme-default/src/client/components/NavbarItems.vue index 5965ee5f85..221664201b 100644 --- a/themes/theme-default/src/client/components/NavbarItems.vue +++ b/themes/theme-default/src/client/components/NavbarItems.vue @@ -176,7 +176,11 @@ useUpdateDeviceStatus(