Sha256: e780e36083e4b6e4e3ab80091546a5de0a178e51006209c9044c8b13fdfcd81b

Contents?: true

Size: 1.33 KB

Versions: 375

Compression:

Stored size: 1.33 KB

Contents

/* global aria, matches */
/**
 * @description validate if a given role is an allowed ARIA role for the supplied node
 * @method isAriaRoleAllowedOnElement
 * @param {HTMLElement} node the node to verify
 * @param {String} role aria role to check
 * @return {Boolean} retruns true/false
 */
aria.isAriaRoleAllowedOnElement = function isAriaRoleAllowedOnElement(
	node,
	role
) {
	const nodeName = node.nodeName.toUpperCase();
	const lookupTable = axe.commons.aria.lookupTable;

	// if given node can have no role - return false
	if (matches(node, lookupTable.elementsAllowedNoRole)) {
		return false;
	}
	// if given node allows any role - return true
	if (matches(node, lookupTable.elementsAllowedAnyRole)) {
		return true;
	}

	// get role value (if exists) from lookupTable.role
	const roleValue = lookupTable.role[role];

	// if given role does not exist in lookupTable - return false
	if (!roleValue || !roleValue.allowedElements) {
		return false;
	}

	// validate attributes and conditions (if any) from allowedElement to given node
	let out = matches(node, roleValue.allowedElements);

	// if given node type has complex condition to evaluate a given aria-role, execute the same
	if (Object.keys(lookupTable.evaluateRoleForElement).includes(nodeName)) {
		return lookupTable.evaluateRoleForElement[nodeName]({ node, role, out });
	}
	return out;
};

Version data entries

375 entries across 375 versions & 1 rubygems

Version Path
govuk_publishing_components-25.3.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-25.2.3 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-25.2.2 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-25.2.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-25.2.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-25.1.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-25.0.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.21.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.21.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.20.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.19.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.18.5 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.18.4 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.18.3 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.18.2 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.18.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.18.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.17.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.16.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-24.16.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js