Skip to content

Commit 6dafa61

Browse files
fix: storybook footer accessibility (#2369)
moves the footer into the side bar and makes links in the footer focusable --------- Co-authored-by: Sébastien Levert <[email protected]>
1 parent 1ce13ae commit 6dafa61

File tree

1 file changed

+20
-96
lines changed

1 file changed

+20
-96
lines changed

.storybook/manager-head.html

Lines changed: 20 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<footer class="storybook-footer">
99
Microsoft Graph Toolkit (v<span id="mgt-version"></span>) Playground was founded by Microsoft as a community guided,
1010
open source project.
11-
<a tabindex="-1" href="https://privacy.microsoft.com/en-us/privacystatement">Privacy & cookies</a>
12-
<a tabindex="-1" href="https://www.microsoft.com/en-us/legal/intellectualproperty/copyright/default">Term of use</a>
11+
<a href="https://privacy.microsoft.com/en-us/privacystatement">Privacy & cookies</a>
12+
<a href="https://www.microsoft.com/en-us/legal/intellectualproperty/copyright/default">Terms of use</a>
1313
</footer>
1414

1515
<script src="https://consentdeliveryfd.azurefd.net/mscc/lib/v2/wcp-consent.js"></script>
@@ -30,7 +30,6 @@
3030

3131
window.onload = () => {
3232
addUsefulLinks();
33-
setUpBottomBar();
3433
}
3534

3635
function addUsefulLinks() {
@@ -157,79 +156,6 @@
157156
return svgElem;
158157
}
159158
const windowWidth = window.innerWidth;
160-
// Whenever the browser zoom is added or reduced, as long as it's
161-
// over 100%, then get the footer height and set that as the value
162-
// of the bottom offset of the bar.
163-
const updateOnZoom = () => {
164-
const pr = window.devicePixelRatio;
165-
// Add an event listener to get any zoom changes based on
166-
// on the resolution.
167-
matchMedia(`(resolution: ${pr}dppx)`).addEventListener("change", updateOnZoom, {
168-
once: true,
169-
});
170-
171-
if ((pr * 100).toFixed(0) > 110) {
172-
return setUpBottomBar();
173-
}
174-
return;
175-
};
176-
177-
// Whenever the browser is resized, also get the footer height and set the
178-
// bottom bar value offset to it.
179-
const updateOnWindowResize = () => {
180-
if (windowWidth.innerWidth != windowWidth) {
181-
setUpBottomBar();
182-
}
183-
window.addEventListener("resize", updateOnWindowResize, {
184-
once: true,
185-
});
186-
return;
187-
};
188-
189-
const updateOnOrientationChange = () => {
190-
const orientation = window.matchMedia("(orientation: landscape)");
191-
updateBottomBar();
192-
// This is just to detect whether there has been an orientation change
193-
// By default we expect to be in landscape so just in case it's something
194-
// else, we still do the updates.
195-
orientation.addEventListener("change", updateOnOrientationChange, {
196-
once: true,
197-
});
198-
};
199-
200-
const setUpBottomBar = () => {
201-
const pr = (window.devicePixelRatio * 100).toFixed(0);
202-
// This is a special case. When zooming in, in the first instance the content
203-
// has to make the side bar disappear, the content takes a while to load. This
204-
// makes the bottom bar unavailable hence it's hidden when the content loads.
205-
// This delay should allow that to happen so that we are able to do get the
206-
// bottom bar when we query it after 3 seconds.
207-
if (pr > 190 && pr < 310) {
208-
sleep(3000)
209-
.then(() => {
210-
updateBottomBar();
211-
})
212-
.catch(() => { });
213-
}
214-
return updateBottomBar();
215-
};
216-
217-
function updateBottomBar() {
218-
const footer = document.getElementsByClassName("storybook-footer")[0];
219-
const bottomBar = document.getElementsByClassName("css-1td7bem");
220-
if (bottomBar && bottomBar.length > 0) {
221-
bottomBar[0].style.bottom = `${footer.clientHeight}px`;
222-
}
223-
return;
224-
}
225-
226-
function sleep(ms) {
227-
return new Promise((resolve) => setTimeout(resolve, ms));
228-
}
229-
230-
updateOnZoom();
231-
updateOnWindowResize();
232-
updateOnOrientationChange();
233159
</script>
234160

235161
<style>
@@ -311,26 +237,6 @@
311237
</style>
312238

313239
<style>
314-
315-
/* don't show the footer on mobile */
316-
@media (max-width: 599px) {
317-
.storybook-footer {
318-
display: none !important;
319-
}
320-
}
321-
322-
/* this keeps the storybook body area above footer */
323-
@media (max-width: 768px) {
324-
#root>div:first-of-type {
325-
height: calc(100% - 50px);
326-
}
327-
}
328-
329-
@media (min-width: 769px) {
330-
#root>div:first-of-type {
331-
height: calc(100% - 40px);
332-
}
333-
}
334240
.sidebar-header button {
335241
display: none !important;
336242
}
@@ -402,3 +308,21 @@
402308
display: none !important;
403309
}
404310
</style>
311+
<script>
312+
let attempts = 0;
313+
// Uses setInterval to wait for the sidebar to be rendered into the page
314+
// interval is cleared on success or after 100 tries (10 seconds)
315+
const retry = setInterval(() => {
316+
attempts++;
317+
if (attempts > 100) {
318+
clearInterval(retry);
319+
return;
320+
}
321+
const footer = document.querySelector('footer');
322+
const sidebar = document.querySelector('nav.sidebar-container');
323+
if (!sidebar) return;
324+
sidebar.parentElement.appendChild(footer);
325+
sidebar.style.height = `calc(100% - ${footer.clientHeight}px)`;
326+
clearInterval(retry);
327+
}, 100)
328+
</script>

0 commit comments

Comments
 (0)