Sha256: 2e25f064e9e197ebd8b5d6db9d60bce1c4be5946d16654a290fc1a414fb63f4c

Contents?: true

Size: 1.6 KB

Versions: 35

Compression:

Stored size: 1.6 KB

Contents

const tableUtils = axe.commons.table;
const cells = tableUtils.getAllCells(node);
const checkResult = this;

// Get a list of all headers reffed to in this rule
let reffedHeaders = [];
cells.forEach(function(cell) {
	const headers = cell.getAttribute('headers');
	if (headers) {
		reffedHeaders = reffedHeaders.concat(headers.split(/\s+/));
	}

	const ariaLabel = cell.getAttribute('aria-labelledby');
	if (ariaLabel) {
		reffedHeaders = reffedHeaders.concat(ariaLabel.split(/\s+/));
	}
});

// Get all the headers
const headers = cells.filter(function(cell) {
	if (axe.commons.text.sanitize(cell.textContent) === '') {
		return false;
	}
	return (
		cell.nodeName.toUpperCase() === 'TH' ||
		['rowheader', 'columnheader'].indexOf(cell.getAttribute('role')) !== -1
	);
});

const tableGrid = tableUtils.toGrid(node);

let out = true;
headers.forEach(header => {
	if (
		header.getAttribute('id') &&
		reffedHeaders.includes(header.getAttribute('id'))
	) {
		return;
	}

	const pos = tableUtils.getCellPosition(header, tableGrid);

	// ensure column header has at least 1 non-header cell
	let hasCell = false;
	if (tableUtils.isColumnHeader(header)) {
		hasCell = tableUtils
			.traverse('down', pos, tableGrid)
			.find(cell => !tableUtils.isColumnHeader(cell));
	}

	// ensure row header has at least 1 non-header cell
	if (!hasCell && tableUtils.isRowHeader(header)) {
		hasCell = tableUtils
			.traverse('right', pos, tableGrid)
			.find(cell => !tableUtils.isRowHeader(cell));
	}

	// report the node as having failed
	if (!hasCell) {
		checkResult.relatedNodes(header);
	}

	out = out && hasCell;
});

return out ? true : undefined;

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
govuk_publishing_components-21.37.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.36.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.36.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.35.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.34.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.34.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.33.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.32.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.31.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.30.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.29.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.29.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.28.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.28.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.27.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.27.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.26.2 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.26.1 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.26.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js
govuk_publishing_components-21.25.0 node_modules/axe-core/lib/checks/tables/th-has-data-cells.js