Skip to content

Commit 439d0fc

Browse files
musaleMnickii
andauthored
fix: update the css query and events used to rename copy button aria-labels (#3271)
* Update the css query and events used to rename copy button aria-labels * Add the additional header text to the button aria-labels * Remove logs and update notes * Use a descriptive function name * Update package version * Update function names Co-authored-by: Nickii Miaro <[email protected]> --------- Co-authored-by: Nickii Miaro <[email protected]>
1 parent 1f3deb8 commit 439d0fc

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

.storybook/components/ElementNamer.jsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { use } from '@esm-bundle/chai';
12
import React, { useEffect } from 'react';
23

34
export const TableNamer = ({ names }) => {
@@ -17,21 +18,32 @@ export const TableNamer = ({ names }) => {
1718
};
1819

1920
export const CopyButtonNamer = ({ names }) => {
20-
useEffect(() => {
21-
const onWindowLoadHander = () => {
22-
const buttons = document.getElementsByClassName('css-3ltsna');
21+
const windowScrollHandler = () => {
22+
const buttons = document.getElementsByClassName('css-1fdphfk');
23+
if (buttons) {
2324
if (buttons.length !== names.length) {
2425
console.error(
2526
'🦒: CopyButtonNamer: number of buttons does not match number of names',
2627
`Found ${buttons?.length ?? 0} buttons and was provided ${names?.length ?? 0} names`
2728
);
29+
return;
2830
}
31+
2932
for (let i = 0; i < buttons.length; i++) {
3033
buttons[i].setAttribute('aria-label', names[i]);
3134
}
32-
};
33-
window.addEventListener('load', onWindowLoadHander);
34-
return () => window.removeEventListener('load', onWindowLoadHander);
35+
// avoid triggering the scroll event again if you keep scrolling.
36+
window.removeEventListener('scroll', windowScrollHandler);
37+
}
38+
};
39+
40+
useEffect(() => {
41+
// NOTE: a good event here is load or DOMContentLoaded BUT for unknown
42+
// reasons, they don't trigger on the page. The scroll event is a hack
43+
// based on the fact that to reach the area the code needs an update,
44+
// you have to scroll - using a mouse or tabbing.
45+
window.addEventListener('scroll', windowScrollHandler);
46+
return () => window.removeEventListener('scroll', windowScrollHandler);
3547
}, [names]);
3648
return <></>;
3749
};

packages/mgt-element/src/utils/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// THIS FILE IS AUTO GENERATED
99
// ANY CHANGES WILL BE LOST DURING BUILD
1010

11-
export const PACKAGE_VERSION = '4.2.3';
11+
export const PACKAGE_VERSION = '4.2.4';

stories/overview.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ The Microsoft Graph Toolkit is supported in the following browsers.
104104
- Check out the Microsoft Graph Toolkit on [GitHub](https://aka.ms/mgt).
105105

106106
<TableNamer names={['Microsoft Graph Toolkit Components', 'Microsoft Graph Toolkit Providers', 'Supported browsers']}/>
107-
<CopyButtonNamer names={['Copy mgt-loader script tag', 'Copy npm install command']}/>
107+
<CopyButtonNamer names={['Copy mgt-loader script tag from a cdn', 'Copy npm install command via npm']}/>

0 commit comments

Comments
 (0)