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-17.4.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-17.3.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-17.2.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-17.1.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-17.1.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-17.0.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.29.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.28.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.27.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.27.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.26.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.25.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.24.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.23.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.22.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.21.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.20.1 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.20.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.19.0 node_modules/axe-core/lib/commons/aria/get-role.js
govuk_publishing_components-16.18.0 node_modules/axe-core/lib/commons/aria/get-role.js