-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(a11y): add distinct name definitions for copy code buttons in sto…
…rybook overview (#2622) uses custom react component to add aria-labels to the copy buttons in the page
- Loading branch information
Showing
3 changed files
with
39 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <></>; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters