Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(a11y): fix same name definitions for copy code buttons in storybook overview #2622

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .storybook/components/ElementNamer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { useEffect } from 'react';

export const TableNamer = ({ names }) => {
useEffect(() => {
const tables = document.querySelectorAll('table:not([aria-hidden="true"])');
if (tables.length !== names.length) {
console.error(
'🦒: TableNamer: number of tables does not match number of names',
`Found ${tables?.length ?? 0} and was provided ${names?.length ?? 0}`
);
}
for (let i = 0; i < tables.length; i++) {
tables[i].setAttribute('title', names[i]);
}
}, [names]);
return <></>;
};

export const CopyButtonNamer = ({ names }) => {
useEffect(() => {
const onWindowLoadHander = () => {
const buttons = document.getElementsByClassName('css-3ltsna');
if (buttons.length !== names.length) {
console.error(
'🦒: CopyButtonNamer: number of buttons does not match number of names',
`Found ${buttons?.length ?? 0} buttons and was provided ${names?.length ?? 0} names`
);
}
for (let i = 0; i < buttons.length; i++) {
buttons[i].setAttribute('aria-label', names[i]);
}
};
window.addEventListener('load', onWindowLoadHander);
return () => window.removeEventListener('load', onWindowLoadHander);
}, [names]);
return <></>;
};
17 changes: 0 additions & 17 deletions .storybook/components/TableNamer.jsx

This file was deleted.

3 changes: 2 additions & 1 deletion stories/overview.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, Source } from '@storybook/addon-docs';
import { PACKAGE_VERSION } from '@microsoft/mgt';
import { versionInfo } from '../.storybook/versionInfo';
import { TableNamer } from '../.storybook/components/TableNamer';
import { TableNamer, CopyButtonNamer } from '../.storybook/components/ElementNamer';

<Meta title="Overview" />

Expand Down Expand Up @@ -105,3 +105,4 @@ The Microsoft Graph Toolkit is supported in the following browsers.
- Check out the Microsoft Graph Toolkit on [GitHub](https://aka.ms/mgt).

<TableNamer names={['Microsoft Graph Toolkit Components', 'Components in preview', 'Microsoft Graph Toolkit Providers', 'Supported browsers']}/>
<CopyButtonNamer names={['Copy mgt-loader script tag', 'Copy npm install command']}/>
gavinbarron marked this conversation as resolved.
Show resolved Hide resolved
Loading