Skip to content

Commit

Permalink
fix(theme-classic): expose empty string alt text in navbar logos (#7659)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BenDMyers committed Jun 23, 2022
1 parent fd87afd commit 3990404
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/docusaurus-theme-classic/src/theme/Logo/index.tsx
Expand Up @@ -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}
/>
);

Expand Down
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Expand Up @@ -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,
Expand Down

0 comments on commit 3990404

Please sign in to comment.