Sha256: 97143ca30e3cc75b80bcc7107045730e7cb26f99245d254da161cfbcebca0a85

Contents?: true

Size: 1.12 KB

Versions: 271

Compression:

Stored size: 1.12 KB

Contents

const id = axe.utils.escapeSelector(node.getAttribute('id'));
let parent = node.parentNode;
let root = axe.commons.dom.getRootNode(node);
root = root.documentElement || root;
let labels = Array.from(root.querySelectorAll(`label[for="${id}"]`));

if (labels.length) {
	// filter out CSS hidden labels because they're fine
	labels = labels.filter(label => axe.commons.dom.isVisible(label));
}

while (parent) {
	if (
		parent.nodeName.toUpperCase() === 'LABEL' &&
		labels.indexOf(parent) === -1
	) {
		labels.push(parent);
	}
	parent = parent.parentNode;
}

this.relatedNodes(labels);

// more than 1 CSS visible label
if (labels.length > 1) {
	const ATVisibleLabels = labels.filter(label =>
		axe.commons.dom.isVisible(label, true)
	);
	// more than 1 AT visible label will fail IOS/Safari/VO even with aria-labelledby
	if (ATVisibleLabels.length > 1) {
		return undefined;
	}
	// make sure the ONE AT visible label is in the list of idRefs of aria-labelledby
	const labelledby = axe.commons.dom.idrefs(node, 'aria-labelledby');
	return !labelledby.includes(ATVisibleLabels[0]) ? undefined : false;
}

// only 1 CSS visible label
return false;

Version data entries

271 entries across 271 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-30.4.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-30.3.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-30.2.1 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-30.2.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-30.1.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-30.0.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.15.3 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.15.2 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.15.1 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.15.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.14.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.13.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.12.1 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.12.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.11.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.10.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.9.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.8.0 node_modules/axe-core/lib/checks/label/multiple-label.js
govuk_publishing_components-29.7.0 node_modules/axe-core/lib/checks/label/multiple-label.js