2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-24 14:04:06 +03:00

fix(react): rendering of react for screenreaders (#220)

* Fix rendering of react for screenreaders

* Fix rendering of react for screenreaders (#1)

Co-authored-by: WAI YAU <waister@ip-192-168-1-52.eu-west-1.compute.internal>

* Tweak

* Change code to be the source instead of the result

---------

Co-authored-by: WAI YAU <waister@ip-192-168-1-52.eu-west-1.compute.internal>
Co-authored-by: richardmtsr <richard.moss@thestudentroom.com>
This commit is contained in:
Wai Lam Yau
2024-03-27 00:46:59 +00:00
committed by GitHub
parent 383d436b63
commit e875c7832d
+14 -2
View File
@@ -22,16 +22,28 @@ function tagToReactElement(node, index) {
}
function renderToReactNodes(nodes) {
let content = '';
const els = [].concat(nodes).reduce((arr, node, index) => {
if (isTagNode(node)) {
if (content !== '') {
arr.push(content);
content = '';
}
arr.push(tagToReactElement(node, index));
} else if (isStringNode(node)) {
arr.push(node);
if (content === '') {
content = node;
} else {
content += node;
}
}
if (index === nodes.length - 1 && content !== '') {
arr.push(content);
}
return arr;
}, []);
return els;
}