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