Skip to content

Commit 6395096

Browse files
musaleMnickii
andauthored
fix(a11y): set the title and aria-label for the screen sizing buttons (#3188)
* Set the title and aria-label for the screen sizing buttons * Use better comment statement --------- Co-authored-by: Nickii Miaro <[email protected]>
1 parent 91ea748 commit 6395096

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

.storybook/manager.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ const xmlns = 'http://www.w3.org/2000/svg';
156156
window.onload = () => {
157157
addUsefulLinks();
158158
};
159+
// Dirty hack. The screen sizing btn resets the title on clicking it. When you
160+
// set the correct title during the window loading event, after clicking the
161+
// button for a full screen or exit of a full screen, the set title is
162+
// overridden to the previous problematic value. This is a catch-all hack on the
163+
// window click event to just ensure any clicks on the btn resets to the correct title.
164+
window.onclick = () =>{
165+
resetScreenSizingBtnTitles()
166+
}
159167

160168
function addUsefulLinks() {
161169
const linkStyle = 'color: black; text-decoration: none; text-align: center; cursor: pointer; padding-right: 0.5rem;';
@@ -266,6 +274,7 @@ function addUsefulLinks() {
266274
}
267275

268276
setEventOnMenuClick();
277+
resetScreenSizingBtnTitles();
269278
}
270279

271280
function createSvg(svgPath) {
@@ -287,6 +296,23 @@ function createSvg(svgPath) {
287296
return svgElem;
288297
}
289298

299+
function resetScreenSizingBtnTitles () {
300+
const titles = {
301+
'Exit full screen [F]': 'Exit full screen',
302+
'Go full screen [F]': 'Go full screen'
303+
}
304+
305+
const screenSizingBtns = document.getElementsByClassName('css-6jc9zw');
306+
for (let i = 0; i < screenSizingBtns.length; i++) {
307+
const btn = screenSizingBtns[i];
308+
const title = btn.getAttribute('title');
309+
// zooming in/out btns share the same class, prefer their titles when they
310+
// are not found in the titles object above.
311+
btn.setAttribute('title', titles[title] ?? title);
312+
btn.setAttribute('aria-label', titles[title] ?? title);
313+
}
314+
}
315+
290316
const injectScripts = () => {
291317
const consentScript = document.createElement('script');
292318
consentScript.src = 'https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js';

0 commit comments

Comments
 (0)