Skip to content

Commit e9f9bd7

Browse files
musaleMnickii
andauthored
Update the aria-label value for the expand/collapse button on the navigation menu (#1684)
* Catch and rewrite expand/collapse button behaviour * Set the aria-label before attaching an event * Add logic for completely closed menu button * Changed the logic to set the aria-label for the button Co-authored-by: Nickii Miaro <[email protected]>
1 parent 4936d97 commit e9f9bd7

File tree

1 file changed

+78
-38
lines changed

1 file changed

+78
-38
lines changed

.storybook/manager-head.html

Lines changed: 78 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<link rel="shortcut icon" type="image/png" href="/favicon.png" />
33
<link rel="manifest" href="manifest.json" />
44
<script>
5-
navigator.serviceWorker.register("sw.js")
5+
navigator.serviceWorker.register("sw.js");
66
</script>
77

88
<footer class="storybook-footer">
@@ -18,11 +18,11 @@
1818

1919
var config = {
2020
autoCapture: {
21-
lineage: true
21+
lineage: true,
2222
},
2323
coreData: {
24-
appId: 'JS:GraphToolkit'
25-
}
24+
appId: "JS:GraphToolkit",
25+
},
2626
};
2727
awa.init(config);
2828

@@ -36,60 +36,58 @@
3636
const textStyle = 'margin-left: 0.25rem; font-size: 0.75rem;';
3737
const linkContentStyle = 'display: flex;';
3838

39-
const sidebarHeader = document.getElementsByClassName('sidebar-header');
39+
const sidebarHeader = document.getElementsByClassName("sidebar-header");
4040
if (sidebarHeader.length === 0) {
4141
// sidebar container has not loaded in the page yet, retry in 500ms
4242
setTimeout(addUsefulLinks, 500);
4343
return false;
4444
}
4545

4646
// This is a fix for an accessibility issue: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/1085
47-
sidebarHeader[0].innerHTML = '<h1 tabindex="0" class="css-1su1ft1">' + '<a href="https://aka.ms/mgt" target="_blank" class="css-ixbm00">' +
48-
'Microsoft Graph Toolkit Playground</a>' +
49-
'</h1>';
47+
sidebarHeader[0].innerHTML = '<h1 tabindex="0" class="css-1su1ft1">' + '<a href="https://aka.ms/mgt" target="_blank" class="css-ixbm00">' + "Microsoft Graph Toolkit Playground</a>" + "</h1>";
5048

5149
const sidebarNode = sidebarHeader[0].parentNode;
5250

5351
// Github
5452
const ghSvgPath = "M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12";
5553
const githubSvgElem = createSvg(ghSvgPath);
5654

57-
const githubText = document.createElement('span');
55+
const githubText = document.createElement("span");
5856
githubText.style = textStyle;
59-
githubText.innerText = 'GitHub';
57+
githubText.innerText = "GitHub";
6058

61-
const repoLinkContent = document.createElement('span');
59+
const repoLinkContent = document.createElement("span");
6260
repoLinkContent.style = linkContentStyle;
6361
repoLinkContent.append(githubSvgElem, githubText);
6462

65-
const repoLink = document.createElement('a');
66-
repoLink.href = 'https://aka.ms/mgt';
67-
repoLink.target = '_blank';
63+
const repoLink = document.createElement("a");
64+
repoLink.href = "https://aka.ms/mgt";
65+
repoLink.target = "_blank";
6866
repoLink.style = linkStyle;
6967
repoLink.appendChild(repoLinkContent);
7068

7169
// npm
7270
const npmSvgPath = "M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z";
7371
const npmSvgElem = createSvg(npmSvgPath);
7472

75-
const npmText = document.createElement('span');
73+
const npmText = document.createElement("span");
7674
npmText.style = textStyle;
77-
npmText.innerText = 'npm';
75+
npmText.innerText = "npm";
7876

79-
const npmLinkContent = document.createElement('span');
77+
const npmLinkContent = document.createElement("span");
8078
npmLinkContent.style = linkContentStyle;
8179
npmLinkContent.append(npmSvgElem, npmText);
8280

83-
const npmLink = document.createElement('a');
84-
npmLink.href = 'https://www.npmjs.com/package/@microsoft/mgt';
85-
npmLink.target = '_blank';
86-
npmLink.style = linkStyle + ' margin-left: 0.5rem;';
81+
const npmLink = document.createElement("a");
82+
npmLink.href = "https://www.npmjs.com/package/@microsoft/mgt";
83+
npmLink.target = "_blank";
84+
npmLink.style = linkStyle + " margin-left: 0.5rem;";
8785
npmLink.appendChild(npmLinkContent);
8886

8987
// links container
90-
const usefulLinksContainer = document.createElement('div');
91-
usefulLinksContainer.id = 'useful-links';
92-
usefulLinksContainer.style = 'display: flex; margin: 1rem 0rem; font-size: 0.875rem;';
88+
const usefulLinksContainer = document.createElement("div");
89+
usefulLinksContainer.id = "useful-links";
90+
usefulLinksContainer.style = "display: flex; margin: 1rem 0rem; font-size: 0.875rem;";
9391

9492
usefulLinksContainer.append(repoLink, npmLink);
9593

@@ -98,7 +96,7 @@
9896
const searchBox = document.querySelector(".search-field");
9997
if (searchBox) {
10098
searchBox.setAttribute("name", "Find Components");
101-
searchBox.setAttribute("aria-expanded", "false")
99+
searchBox.setAttribute("aria-expanded", "false");
102100

103101
const searchInput = searchBox.querySelector("input");
104102
if (searchInput) {
@@ -150,6 +148,38 @@
150148
}
151149
}
152150

151+
function setEventOnMenuClick() {
152+
const expandCollapseMenu = document.getElementsByClassName("css-ulso1l");
153+
if (expandCollapseMenu) {
154+
for (let i = 0; i < expandCollapseMenu.length; i++) {
155+
const menu = expandCollapseMenu[i];
156+
menu.addEventListener("click", setArialLabelForExpandCollapseBtn, { useCapture: true });
157+
}
158+
}
159+
}
160+
function setArialLabelForExpandCollapseBtn() {
161+
const expandCollapseBtns = document.getElementsByClassName("css-rl1ij0");
162+
if (expandCollapseBtns) {
163+
for (let i = 0; i < expandCollapseBtns.length; i++) {
164+
const button = expandCollapseBtns[i];
165+
setButtonAriaLabel(button);
166+
button.addEventListener("click", btnUpDown, { useCapture: true });
167+
}
168+
}
169+
}
170+
171+
function btnUpDown(event) {
172+
const element = event.target; // button when using tabs to navigate, svg when using mouse.
173+
setButtonAriaLabel(element);
174+
}
175+
176+
function setButtonAriaLabel(element) {
177+
const dataExpandedState = element.getAttribute("data-expanded");
178+
const ariaValue = dataExpandedState === "true" ? "expand" : "collapse";
179+
element.setAttribute("aria-label", ariaValue);
180+
}
181+
182+
setEventOnMenuClick();
153183
setListItemsAc11y();
154184
}
155185

@@ -178,47 +208,55 @@
178208
const pr = window.devicePixelRatio;
179209
// Add an event listener to get any zoom changes based on
180210
// on the resolution.
181-
matchMedia(`(resolution: ${pr}dppx)`).addEventListener("change", updateOnZoom, { once: true });
211+
matchMedia(`(resolution: ${pr}dppx)`).addEventListener("change", updateOnZoom, {
212+
once: true,
213+
});
182214

183215
if ((pr * 100).toFixed(0) > 110) {
184216
return setUpBottomBar();
185217
}
186218
return;
187-
}
219+
};
188220

189221
// Whenever the browser is resized, also get the footer height and set the
190222
// bottom bar value offset to it.
191223
const updateOnWindowResize = () => {
192224
if (windowWidth.innerWidth != windowWidth) {
193225
setUpBottomBar();
194226
}
195-
window.addEventListener("resize", updateOnWindowResize, { once: true });
227+
window.addEventListener("resize", updateOnWindowResize, {
228+
once: true,
229+
});
196230
return;
197-
}
231+
};
198232

199233
const updateOnOrientationChange = () => {
200234
const orientation = window.matchMedia("(orientation: landscape)");
201235
updateBottomBar();
202236
// This is just to detect whether there has been an orientation change
203237
// By default we expect to be in landscape so just in case it's something
204238
// else, we still do the updates.
205-
orientation.addEventListener("change", updateOnOrientationChange, { once: true });
206-
}
239+
orientation.addEventListener("change", updateOnOrientationChange, {
240+
once: true,
241+
});
242+
};
207243

208244
const setUpBottomBar = () => {
209-
const pr = (window.devicePixelRatio * 100).toFixed(0)
245+
const pr = (window.devicePixelRatio * 100).toFixed(0);
210246
// This is a special case. When zooming in, in the first instance the content
211247
// has to make the side bar disappear, the content takes a while to load. This
212248
// makes the bottom bar unavailable hence it's hidden when the content loads.
213249
// This delay should allow that to happen so that we are able to do get the
214250
// bottom bar when we query it after 3 seconds.
215251
if (pr > 190 && pr < 310) {
216-
sleep(3000).then(() => {
217-
updateBottomBar();
218-
}).catch(() => { })
252+
sleep(3000)
253+
.then(() => {
254+
updateBottomBar();
255+
})
256+
.catch(() => { });
219257
}
220258
return updateBottomBar();
221-
}
259+
};
222260

223261
function updateBottomBar() {
224262
const footer = document.getElementsByClassName("storybook-footer")[0];
@@ -230,7 +268,7 @@
230268
}
231269

232270
function sleep(ms) {
233-
return new Promise(resolve => setTimeout(resolve, ms));
271+
return new Promise((resolve) => setTimeout(resolve, ms));
234272
}
235273

236274
updateOnZoom();
@@ -246,6 +284,7 @@
246284
}
247285

248286
@media (forced-colors: active) and (prefers-color-scheme: dark) {
287+
249288
#root,
250289
svg,
251290
svg>path,
@@ -280,6 +319,7 @@
280319
}
281320

282321
@media (forced-colors: active) and (prefers-color-scheme: light) {
322+
283323
#root,
284324
svg,
285325
svg>path,
@@ -377,6 +417,6 @@
377417
}
378418

379419
.css-1en6m26 {
380-
color: #616159 !important
420+
color: #616159 !important;
381421
}
382422
</style>

0 commit comments

Comments
 (0)