Skip to content

Commit

Permalink
fix(a11y): Add meaningful alt text to custom logo (#1352)
Browse files Browse the repository at this point in the history
* fix(custom_logo): Adds missing alt attribute to custom-logo element

* fix(custom_logo): Internationalize alternative image text

* fix(a11y): Adress PR comments

* fix(a11y): Adress PR comments
  • Loading branch information
tille authored Apr 15, 2021
1 parent a80ab58 commit 4e11fbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ print_loading=Preparing to print...
print_ready=Ready to print.
# Accessible text for right navigation arrow that navigates user to previous file in collection
previous_file=Previous file
# Alternative text for logo-image
logo=Logo
# Accessible text for right navigation arrow that navigates user to next file in collection
next_file=Next file
# Text shown while preview is loading
Expand Down
7 changes: 5 additions & 2 deletions src/lib/PreviewUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,12 @@ class PreviewUI {
headerContainerEl.classList.remove(CLASS_HIDDEN);

const headerEl = headerContainerEl.firstElementChild;
const defaultLogoEl = headerEl.querySelector(SELECTOR_BOX_PREVIEW_LOGO_DEFAULT);
const customLogoEl = headerEl.querySelector(SELECTOR_BOX_PREVIEW_LOGO_CUSTOM);

headerEl.className = `${CLASS_BOX_PREVIEW_HEADER} ${CLASS_BOX_PREVIEW_BASE_HEADER}`;
this.previewContainer.classList.add(CLASS_BOX_PREVIEW_HAS_HEADER);
defaultLogoEl.setAttribute('aria-label', __('logo'));

// Setup theme, default is 'light'
if (headerTheme === 'dark') {
Expand All @@ -382,10 +386,9 @@ class PreviewUI {

// Set custom logo
if (logoUrl) {
const defaultLogoEl = headerEl.querySelector(SELECTOR_BOX_PREVIEW_LOGO_DEFAULT);
defaultLogoEl.classList.add(CLASS_HIDDEN);
customLogoEl.setAttribute('alt', __('logo'));

const customLogoEl = headerEl.querySelector(SELECTOR_BOX_PREVIEW_LOGO_CUSTOM);
customLogoEl.src = logoUrl;
customLogoEl.classList.remove(CLASS_HIDDEN);
}
Expand Down

0 comments on commit 4e11fbe

Please sign in to comment.