Sha256: 86a56c0e50cd392fcd6627cf831107bb8f6d796100d16a0f9dd650cf23547bfd

Contents?: true

Size: 1.19 KB

Versions: 375

Compression:

Stored size: 1.19 KB

Contents

/* global aria, axe */

/**
 * Return the accessible role of an element
 *
 * @method getRole
 * @memberof axe.commons.aria
 * @instance
 * @param {Element} node
 * @param {Object} options
 * @param {boolean} options.noImplicit  Do not return the implicit role
 * @param {boolean} options.fallback  Allow fallback roles
 * @param {boolean} options.abstracts  Allow role to be abstract
 * @param {boolean} options.dpub  Allow role to be any (valid) doc-* roles
 * @returns {string|null} Role or null
 */
aria.getRole = function getRole(
	node,
	{ noImplicit, fallback, abstracts, dpub } = {}
) {
	node = node.actualNode || node;
	if (node.nodeType !== 1) {
		return null;
	}
	const roleAttr = (node.getAttribute('role') || '').trim().toLowerCase();
	const roleList = fallback ? axe.utils.tokenList(roleAttr) : [roleAttr];

	// Get the first valid role:
	const validRoles = roleList.filter(role => {
		if (!dpub && role.substr(0, 4) === 'doc-') {
			return false;
		}
		return aria.isValidRole(role, { allowAbstract: abstracts });
	});

	const explicitRole = validRoles[0];

	// Get the implicit role, if permitted
	if (!explicitRole && !noImplicit) {
		return aria.implicitRole(node);
	}

	return explicitRole || null;
};

Version data entries

375 entries across 375 versions & 1 rubygems

Version Path
govuk_publishing_components-21.66.2 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.66.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.66.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.65.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.65.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.64.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.63.3 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.63.2 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.63.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.63.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.62.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.61.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.60.3 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.60.2 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.60.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.60.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.59.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.58.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.57.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-21.57.0 node_modules/axe-core/lib/commons/aria/get-role.js