fix(theme-classic): expose empty string alt text in navbar logos (#7659)

* fix: Expose empty string alt text in brand logos via nullish coalescing

* fix: Update boolean logic for fallbacks

* fix: Dogfood fix on Docusaurus brand logo

* refactor: Un-inline alt logic, and reduce chance of duplication in fallback
This commit is contained in:
Ben Myers 2022-06-22 22:42:52 -05:00 committed by GitHub
parent fd87afd249
commit 3990404419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -27,12 +27,21 @@ export default function Logo(props: Props): JSX.Element {
light: useBaseUrl(logo.src),
dark: useBaseUrl(logo.srcDark || logo.src),
};
// If visible title is shown, fallback alt text should be
// an empty string to mark the logo as decorative.
const fallbackAlt = navbarTitle ? '' : title;
// Use logo alt text if provided (including empty string),
// and provide a sensible fallback otherwise.
const alt = logo.alt ?? fallbackAlt;
const themedImage = (
<ThemedImage
sources={sources}
height={logo.height}
width={logo.width}
alt={logo.alt || navbarTitle || title}
alt={alt}
/>
);

View File

@ -399,7 +399,7 @@ const config = {
hideOnScroll: true,
title: 'Docusaurus',
logo: {
alt: 'Docusaurus Logo',
alt: '',
src: 'img/docusaurus.svg',
srcDark: 'img/docusaurus_keytar.svg',
width: 32,