Skip to content

Commit

Permalink
feat: [A11y] Add a button to skip to web widget
Browse files Browse the repository at this point in the history
  • Loading branch information
smansouri committed Nov 15, 2023
1 parent e9221a8 commit 4fc0d1e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ window.addEventListener("DOMContentLoaded", () => {
}
});

// Hide Skip to Web Widget button if Web Widget is not present
const skipToWidgetButton = document.body.querySelector(".skip-to-web-widget");

let webWidgetLoadingCounter = 20;
let handleSkipToWidgetButtonIntervalId;

Check failure on line 37 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
const handleSkipToWidgetButtonIntervalDuration = 500;

Check failure on line 38 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`

skipToWidgetButton.style.display = "none";

Check failure on line 40 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`

const handleSkipToWidgetButton = () => {

Check failure on line 42 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
if ("zE" in window && window.zE("webWidget:get", "display") !== "hidden") {

Check failure on line 43 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
skipToWidgetButton.addEventListener("click", () =>

Check failure on line 44 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
window.zE(

Check failure on line 45 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Replace `······` with `········`
window.zE.widget === "classic" ? "webWidget" : "messenger",

Check failure on line 46 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
"open"

Check failure on line 47 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
)

Check failure on line 48 in src/navigation.js

View workflow job for this annotation

GitHub Actions / Lint JS files

Insert `··`
);
skipToWidgetButton.style.display = "inline-block";
clearInterval(handleSkipToWidgetButtonIntervalId);
}
if (webWidgetLoadingCounter-- <= 0) {
clearInterval(handleSkipToWidgetButtonIntervalId);
}
}

handleSkipToWidgetButtonIntervalId = setInterval(handleSkipToWidgetButton, handleSkipToWidgetButtonIntervalDuration);

// Toggles expanded aria to collapsible elements
const collapsible = document.querySelectorAll(
".collapsible-nav, .collapsible-sidebar"
Expand Down
29 changes: 29 additions & 0 deletions styles/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,32 @@ $header-height: 71px;
#zd-modal-container ~ .skip-navigation {
display: none;
}

.skip-to-web-widget {
align-items: center;
background-color: black;
color: white;
display: flex;
font-size: 14px;
justify-content: center;
left: -919px;
margin: 20px;
padding: 20px;
overflow: hidden;
position: absolute;
top: auto;
z-index: -999;
}

.skip-to-web-widget:focus, .skip-to-web-widget:active {
left: auto;
overflow: auto;
text-align: center;
text-decoration: none;
top: auto;
z-index: 999;
}
[dir=rtl] .skip-to-web-widget {
left: initial;
right: -919px;
}
1 change: 1 addition & 0 deletions templates/header.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<a class="skip-navigation" tabindex="1" href="#main-content">{{t 'skip_navigation' }}</a>
<a class="skip-to-web-widget" tabindex="2" href="#launcher" >{{t 'skip_to_chat'}}</a>

<header class="header">
<div class="logo">
Expand Down

0 comments on commit 4fc0d1e

Please sign in to comment.