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-30.4.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/commons/aria/is-aria-role-allowed-on-element.js