Sha256: 61b108d1b12f3e25943a6fa76588b18dc17de1b955b77a79afc6957cc27e0472

Contents?: true

Size: 1.09 KB

Versions: 375

Compression:

Stored size: 1.09 KB

Contents

/* global aria */

/**
 * Check if an element is named from contents
 *
 * @param {Node|VirtualNode} element
 * @param {Object} options
 * @property {Bool} strict Whether or not to follow the spects strictly
 * @return {Bool}
 */
aria.namedFromContents = function namedFromContents(node, { strict } = {}) {
	node = node.actualNode || node;
	if (node.nodeType !== 1) {
		return false;
	}

	const role = aria.getRole(node);
	const roleDef = aria.lookupTable.role[role];

	if (
		(roleDef && roleDef.nameFrom.includes('contents')) ||
		// TODO: This is a workaround for axe-core's over-assertive implicitRole computation
		// once we fix that, this extra noImplicit check can be removed.
		node.nodeName.toUpperCase() === 'TABLE'
	) {
		return true;
	}

	/**
	 * Note: Strictly speaking if the role is null, presentation, or none, the element
	 * isn't named from contents. Axe-core often needs to know if an element
	 * has content anyway, so we're allowing it here.
	 * Use { strict: true } to disable this behavior.
	 */
	if (strict) {
		return false;
	}
	return !roleDef || ['presentation', 'none'].includes(role);
};

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