@scania/tegel
Version:
Tegel Design System
16 lines (15 loc) • 549 B
JavaScript
/**
* Loop through the children and add the 'listitem' role if needed.
* @param {Node} targetNode The node being updated.
* */
const updateListChildrenRoles = (targetNode) => {
targetNode.childNodes.forEach((node) => {
if (node.nodeType === Node.ELEMENT_NODE) {
const element = node;
if (element.tagName.toLowerCase() !== 'li' && element.getAttribute('role') !== 'listitem') {
element.setAttribute('role', 'listitem');
}
}
});
};
export default updateListChildrenRoles;