Sha256: 71e09bf1c4069fa01e8ebafb332197a0b47897c3622365a28f8f739e240f8303

Contents?: true

Size: 901 Bytes

Versions: 11

Compression:

Stored size: 901 Bytes

Contents

/**
 * Applicability:
 * Rule applies to any element that has
 * a) a semantic role that is `widget` that supports name from content
 * b) has visible text content
 * c) has accessible name (eg: `aria-label`)
 */
const { aria, text } = axe.commons;

const role = aria.getRole(node);
if (!role) {
	return false;
}

const isWidgetType = aria.lookupTable.rolesOfType.widget.includes(role);
if (!isWidgetType) {
	return false;
}

const rolesWithNameFromContents = aria.getRolesWithNameFromContents();
if (!rolesWithNameFromContents.includes(role)) {
	return false;
}

/**
 * if no `aria-label` or `aria-labelledby` attribute - ignore `node`
 */
if (
	!text.sanitize(aria.arialabelText(virtualNode)) &&
	!text.sanitize(aria.arialabelledbyText(node))
) {
	return false;
}

/**
 * if no `contentText` - ignore `node`
 */
if (!text.sanitize(text.visibleVirtual(virtualNode))) {
	return false;
}

return true;

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
govuk_publishing_components-21.27.1 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.27.0 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.26.2 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.26.1 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.26.0 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.25.0 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.24.0 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.23.1 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.23.0 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.22.2 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js
govuk_publishing_components-21.22.1 node_modules/axe-core/lib/rules/label-content-name-mismatch-matches.js