Sha256: bf0fdd1039fa045d4c03f6d3a46add934fdb137624acecb8a59ad9391381c9d2

Contents?: true

Size: 1.71 KB

Versions: 104

Compression:

Stored size: 1.71 KB

Contents

function getSelector(role) {
	var impliedNative = axe.commons.aria.implicitNodes(role) || [];
	return impliedNative.concat('[role="' + role + '"]').join(',');
}

function getMissingContext(virtualNode, requiredContext, includeElement) {
	var index,
		length,
		role = virtualNode.actualNode.getAttribute('role'),
		missing = [];

	if (!requiredContext) {
		requiredContext = axe.commons.aria.requiredContext(role);
	}

	if (!requiredContext) {
		return null;
	}

	for (index = 0, length = requiredContext.length; index < length; index++) {
		if (
			includeElement &&
			axe.utils.matchesSelector(
				virtualNode.actualNode,
				getSelector(requiredContext[index])
			)
		) {
			return null;
		}
		if (
			axe.commons.dom.findUpVirtual(
				virtualNode,
				getSelector(requiredContext[index])
			)
		) {
			//if one matches, it passes
			return null;
		} else {
			missing.push(requiredContext[index]);
		}
	}

	return missing;
}

function getAriaOwners(element) {
	var owners = [],
		o = null;

	while (element) {
		if (element.getAttribute('id')) {
			const id = axe.utils.escapeSelector(element.getAttribute('id'));
			let doc = axe.commons.dom.getRootNode(element);
			o = doc.querySelector(`[aria-owns~=${id}]`);
			if (o) {
				owners.push(o);
			}
		}
		element = element.parentElement;
	}

	return owners.length ? owners : null;
}

var missingParents = getMissingContext(virtualNode);

if (!missingParents) {
	return true;
}

var owners = getAriaOwners(node);

if (owners) {
	for (var i = 0, l = owners.length; i < l; i++) {
		missingParents = getMissingContext(
			axe.utils.getNodeFromTree(axe._tree[0], owners[i]),
			missingParents,
			true
		);
		if (!missingParents) {
			return true;
		}
	}
}

this.data(missingParents);
return false;

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
govuk_publishing_components-21.16.3 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.16.2 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.16.1 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.16.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.15.2 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.15.1 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.15.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.14.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.13.5 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.13.4 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.13.3 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.13.2 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.13.1 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.13.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.12.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.11.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.10.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.9.0 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.8.1 node_modules/axe-core/lib/checks/aria/required-parent.js
govuk_publishing_components-21.8.0 node_modules/axe-core/lib/checks/aria/required-parent.js