Sha256: aa59719660a3c3fa20e08b536f7ff7d37dcb09fa9e89b48ea3642299f965aa11

Contents?: true

Size: 1.26 KB

Versions: 236

Compression:

Stored size: 1.26 KB

Contents

const cells = [];
const reviewCells = [];
const badCells = [];

for (let rowIndex = 0; rowIndex < node.rows.length; rowIndex++) {
	const row = node.rows[rowIndex];

	for (let cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
		cells.push(row.cells[cellIndex]);
	}
}

const ids = cells.reduce((ids, cell) => {
	if (cell.getAttribute('id')) {
		ids.push(cell.getAttribute('id'));
	}
	return ids;
}, []);

cells.forEach(cell => {
	let isSelf = false;
	let notOfTable = false;

	if (!cell.hasAttribute('headers')) {
		return;
	}

	const headersAttr = cell.getAttribute('headers').trim();
	if (!headersAttr) {
		return reviewCells.push(cell);
	}

	// Get a list all the values of the headers attribute
	const headers = axe.utils.tokenList(headersAttr);

	if (headers.length !== 0) {
		// Check if the cell's id is in this list
		if (cell.getAttribute('id')) {
			isSelf = headers.indexOf(cell.getAttribute('id').trim()) !== -1;
		}

		// Check if the headers are of cells inside the table
		notOfTable = headers.some(header => !ids.includes(header));

		if (isSelf || notOfTable) {
			badCells.push(cell);
		}
	}
});

if (badCells.length > 0) {
	this.relatedNodes(badCells);
	return false;
}

if (reviewCells.length) {
	this.relatedNodes(reviewCells);
	return undefined;
}

return true;

Version data entries

236 entries across 236 versions & 1 rubygems

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