Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

hiding text nodes #30

Open
pkra opened this issue Dec 13, 2018 · 1 comment
Open

hiding text nodes #30

pkra opened this issue Dec 13, 2018 · 1 comment
Labels
question/discussion Further information is requested

Comments

@pkra
Copy link
Member

pkra commented Dec 13, 2018

We used to hide text nodes manually (wrap them in a span with aria-hidden). Joanie had suggested to keep this in mind when running into double voicing (e.g. I saw that when testing role=group).

@pkra pkra added the question/discussion Further information is requested label Dec 13, 2018
@pkra
Copy link
Member Author

pkra commented Dec 13, 2018

Since our code structure changed, we can't be sure we touch every node, so we need to do this separately now (instead of during the rewriteNodeRec).

This does the trick. (Sadly, *:not(*:has(*)) is not a valid selector.)

+ const hideTextLeafs = (node) => {
+  const leafs =  Array.from(node.querySelectorAll('*')).filter ( node => !node.querySelector('*'));
+  leafs.forEach( leaf => {
+    if (leaf.innerHTML.trim() === '') return;
+    leaf.innerHTML = '<span aria-hidden="true">' + leaf.innerHTML + '</span>';
+  })
+ }


 export function rewriteNode(node, tree) {
+  if (node.tagName === 'SPAN') hideTextLeafs(node);
   rewriteNodeRec(node, tree.root);
 }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question/discussion Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant