aria-api

access ARIA information from JavaScript
git clone https://git.ce9e.org/aria-api.git

commit
5a577ef93e15a8b15d78bfb7ce3e18d7cefa8560
parent
162b8c5ec8e94b18b923efa6d181df4e2eebe1ba
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-01-12 18:27
refactor: getRole returns undefined if explicit role is not in candidates

Diffstat

M lib/attrs.js 10 +++++++---

1 files changed, 7 insertions, 3 deletions


diff --git a/lib/attrs.js b/lib/attrs.js

@@ -3,7 +3,12 @@ var constants = require('./constants.js');
    3     3 // candidates can be passed for performance optimization
    4     4 var getRole = function(el, candidates) {
    5     5 	if (el.hasAttribute('role')) {
    6    -1 		return el.getAttribute('role');
   -1     6 		var role = el.getAttribute('role');
   -1     7 		if (!candidates || candidates.includes(role)) {
   -1     8 			return role;
   -1     9 		} else {
   -1    10 			return;
   -1    11 		}
    7    12 	}
    8    13 	for (var role in constants.roles) {
    9    14 		var selector = (constants.roles[role].selectors || []).join(',');
@@ -17,8 +22,7 @@ var hasRole = function(el, roles) {
   17    22 	var candidates = [].concat.apply([], roles.map(role => {
   18    23 		return (constants.roles[role] || {}).subRoles || [role];
   19    24 	}));
   20    -1 	var actual = getRole(el, candidates);
   21    -1 	return candidates.includes(actual);
   -1    25 	return !!getRole(el, candidates);
   22    26 };
   23    27 
   24    28 var getAttribute = function(el, key) {